@lwrjs/router 0.17.0-alpha.0 → 0.17.1-alpha.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.
@@ -1,2 +1,2 @@
1
- import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as r,registerDecorators as s,registerComponent as o,LightningElement as n}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";var u=[function(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;}"}];const p=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,v={key:0},g=[];function m(e,t,i,r){const{s:s,st:o}=e;return[s("",v,g,i),o(p,2)]}var f=t(m);function E(e){if(null==e)throw new TypeError("Provider must be defined.")}m.slots=[""],m.renderMode="light",m.stylesheets=[],m.stylesheetToken="lwc-7bis3qj4jjc",m.legacyStylesheetToken="lwr-routerContainer_routerContainer",u&&m.stylesheets.push.apply(m.stylesheets,u),i(m);class I{constructor(e){this.infoMap=new WeakMap,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){E(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){E(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){E(e),this.infoMap.delete(e)}subscribeContext(e,t){E(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){E(e),this.getInfo(e).consumers.delete(t)}}const b="LWR",N=1;function w(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function _(e,t){const i={...e,message:w(e.message,t)};return e.address&&(i.address=w(e.address,t)),e.stack&&(i.stack=w(e.stack,t)),i}function R(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${w(e.message,t)}`}(t,i))}const x={INVALID_MIXIN_CMP:{code:`${b}4001`,message:"{0} must be an Element type",level:N},MISSING_CONTEXT:{code:`${b}4002`,message:"Could not find context to perform navigation action.",level:N},INVALID_CONTEXT:{code:`${b}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:N},MULTIPLE_ROOTS:{code:`${b}4004`,message:"Router connection failed. There can only be one root router.",level:N},MULTIPLE_CHILDREN:{code:`${b}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:N},MISSING_ROUTE:{code:`${b}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:N,address:"{0}"},MISSING_URL:{code:`${b}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:N,address:"{0}"},PRENAV_FAILED:{code:`${b}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${b}4009`,message:'Route definition with id "{0}" is missing a "uri" property.',level:N,address:"{0}"},MISSING_ROUTE_CMP:{code:`${b}4016`,message:"Expected a route view component with a default export.",level:N},MISSING_DATA_CONTEXT:{code:`${b}4018`,message:"Could not find context to retrieve navigation data.",level:N},INVALID_ROUTE_QUERY:{code:`${b}4019`,message:"Invalid query param in route definition.",level:N},MISSING_PAGE_BINDING:{code:`${b}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:N,address:"{0}"},INVALID_PAGE_BINDING:{code:`${b}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:N,address:"{0}"},INVALID_URI_SYNTAX:{code:`${b}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:N,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${b}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:N,stack:"{2}"},VIEW_MISSING:{code:`${b}4024`,message:'Expected a view with name "{0}" in the viewset',level:N},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${b}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:N,stack:"{3}"},NO_ROUTE_MATCH:{code:`${b}4026`,message:"A routing match cannot be found for: {0}",level:N},INVALID_ROUTE_HANDLER:{code:`${b}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:N},DESTINATION_NOT_FOUND:{code:`${b}4028`,message:"Route handler returned 404: Not Found",level:N},DESTINATION_ERROR:{code:`${b}4029`,message:"Route handler returned error status {0}: {1}",level:N,stack:"{2}"},NO_INIT_URL:{code:`${b}4030`,message:'Cannot initialize a server router without a "url"',level:N}},C=new WeakMap;function T(e){var t;return(t=class{constructor(e){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=T(new I(void 0)),y=T(new I(void 0)),S=new I(void 0),O=class extends(T(S)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,o=s&&s.module||r;let n;if(o)try{const e=await o(),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;n=s.specifier?_(x.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):_(x.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else n=_(x.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(n)}}};function $(){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 A(e=""){return e=e||"",decodeURIComponent(e)}function M(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const L="undefined"!=typeof document,U=`universalcontainergetnavigationcontext${M()}`,D=r(y),k=L?r(O):void 0,F=r(P);function V(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 G(){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,o=!0)=>{(e=>{i.push(e)})(s),e&&o&&s.next(e),t&&r(t);const n=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(n)}}}}const W=`universalcontainernavigationevent${M()}`,j=`universalcontainerparentevent${M()}`;class H{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=$(),this.errorNavFilters=$(),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.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=G()}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},y.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(j,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:(e,t)=>this.generateUrl(e,t),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};C.set(i.id,i)}(this.contextId,e),V(this.contextId,this.target,F,P),V(void 0,this.target,D,y),V(void 0,this.target,k,O),this.router.subscribe((e=>{if(404===e.status)return void this.processError(_(x.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(_(x.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),L&&(this.target.addEventListener(W,this._handleNavigationEvent),this.target.addEventListener(j,this._handleParentEvent),this.target.addEventListener(U,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(W,this._handleNavigationEvent),this.target.removeEventListener(j,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((()=>{R(!this.child,x.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.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.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(W,{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}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){L&&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 B(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[A(i)]=A(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 X extends H{constructor(){super(...arguments),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(L&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&L&&this.catchBrowserUpdate(B(window.location.href))}disconnect(){super.disconnect(),L&&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)}}let q=!1;class z extends n{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=L?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};L&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new H(t,i,e):new X(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(),R(!q||!!r.parent,x.MULTIPLE_ROOTS),q=q||!r.parent,s.id=r.contextId},disconnect:()=>{q=q&&!!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,document.title=t);const i=this.querySelector("span.router-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})}}z.renderMode="light",s(z,{publicProps:{router:{config:0},historyDisabled:{config:0}}});const Y=o(z,{tmpl:f,sel:"lwr-router-container",apiVersion:63});export{Y as default};
1
+ import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as s,registerDecorators as r,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";var u=[function(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;}"}];const p=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,v={key:0},g=[],m={ref:"title"};function f(e,t,i,s){const{s:r,sp:n,st:o}=e;return[r("",v,g,i),o(p,2,[n(0,m,null)])]}var E=t(f);function I(e){if(null==e)throw new TypeError("Provider must be defined.")}f.slots=[""],f.renderMode="light",f.hasRefs=!0,f.stylesheets=[],f.stylesheetToken="lwc-7bis3qj4jjc",f.legacyStylesheetToken="lwr-routerContainer_routerContainer",u&&f.stylesheets.push.apply(f.stylesheets,u),i(f);class b{constructor(e){this.infoMap=new WeakMap,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){I(e);const i=t,s=this.getInfo(e);s.contextValue=t,s.consumers.forEach((e=>e.provide(i))),0===s.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){I(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){I(e),this.infoMap.delete(e)}subscribeContext(e,t){I(e);const{consumers:i,contextValue:s}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(s))}unsubscribeContext(e,t){I(e),this.getInfo(e).consumers.delete(t)}}const N="LWR",w=1;function _(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function R(e,t){const i={...e,message:_(e.message,t)};return e.address&&(i.address=_(e.address,t)),e.stack&&(i.stack=_(e.stack,t)),i}function x(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${_(e.message,t)}`}(t,i))}const C={INVALID_MIXIN_CMP:{code:`${N}4001`,message:"{0} must be an Element type",level:w},MISSING_CONTEXT:{code:`${N}4002`,message:"Could not find context to perform navigation action.",level:w},INVALID_CONTEXT:{code:`${N}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:w},MULTIPLE_ROOTS:{code:`${N}4004`,message:"Router connection failed. There can only be one root router.",level:w},MULTIPLE_CHILDREN:{code:`${N}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:w},MISSING_ROUTE:{code:`${N}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:w,address:"{0}"},MISSING_URL:{code:`${N}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:w,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:w,address:"{0}"},MISSING_ROUTE_CMP:{code:`${N}4016`,message:"Expected a route view component with a default export.",level:w},MISSING_DATA_CONTEXT:{code:`${N}4018`,message:"Could not find context to retrieve navigation data.",level:w},INVALID_ROUTE_QUERY:{code:`${N}4019`,message:"Invalid query param in route definition.",level:w},MISSING_PAGE_BINDING:{code:`${N}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:w,address:"{0}"},INVALID_PAGE_BINDING:{code:`${N}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:w,address:"{0}"},INVALID_URI_SYNTAX:{code:`${N}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:w,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${N}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:w,stack:"{2}"},VIEW_MISSING:{code:`${N}4024`,message:'Expected a view with name "{0}" in the viewset',level:w},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${N}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:w,stack:"{3}"},NO_ROUTE_MATCH:{code:`${N}4026`,message:"A routing match cannot be found for: {0}",level:w},INVALID_ROUTE_HANDLER:{code:`${N}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:w},DESTINATION_NOT_FOUND:{code:`${N}4028`,message:"Route handler returned 404: Not Found",level:w},DESTINATION_ERROR:{code:`${N}4029`,message:"Route handler returned error status {0}: {1}",level:w,stack:"{2}"},NO_INIT_URL:{code:`${N}4030`,message:'Cannot initialize a server router without a "url"',level:w}},T=new WeakMap;function P(e){var t;return(t=class{constructor(e){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 y=P(new b(void 0)),O=P(new b(void 0)),S=new b(void 0),$=class extends(P(S)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",s=t.viewset[i],r=s,n=r&&r.module||s;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=r.specifier?R(C.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[r.specifier,i,t.message,t.stack||""]):R(C.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else o=R(C.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(o)}}};function A(){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 M(e=""){return e=e||"",decodeURIComponent(e)}function L(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const U="undefined"!=typeof document,D=`universalcontainergetnavigationcontext${L()}`,k=s(O),F=U?s($):void 0,V=s(y);function G(e,t,i,s){i&&s&&(s.setContext(t,e),i(t,{consumerConnectedCallback:s.subscribeContext.bind(s,t),consumerDisconnectedCallback:s.unsubscribeContext.bind(s,t)}))}function W(){let e,t,i=[];const s=s=>{i.filter((e=>null!==e)).forEach((e=>e.error&&e.error(s))),e=void 0,t=s};return{next:s=>{i.filter((e=>null!==e)).forEach((e=>e.next&&e.next(s))),e=s,t=void 0},error:s,complete:()=>{i.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),i=[],e=void 0,t=void 0},subscribe:(r,n=!0)=>{(e=>{i.push(e)})(r),e&&n&&r.next(e),t&&s(t);const o=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(o)}}}}const j=`universalcontainernavigationevent${L()}`,H=`universalcontainerparentevent${L()}`;class B{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=A(),this.errorNavFilters=A(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:s}=t.detail;this.config.handleNavigation(s,i)?this.root&&!e?this.root.processError(R(C.MISSING_URL,[JSON.stringify(s)])):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=W()}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},O.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(H,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:(e,t)=>this.generateUrl(e,t),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};T.set(i.id,i)}(this.contextId,e),G(this.contextId,this.target,V,y),G(void 0,this.target,k,O),G(void 0,this.target,F,$),this.router.subscribe((e=>{if(404===e.status)return void this.processError(R(C.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(R(C.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)};$.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),U&&(this.target.addEventListener(j,this._handleNavigationEvent),this.target.addEventListener(H,this._handleParentEvent),this.target.addEventListener(D,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(j,this._handleNavigationEvent),this.target.removeEventListener(H,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((()=>{x(!this.child,C.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,s){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 r=this.router.parseUrl(e);return r&&this.router.navigate(r,i),!0}preProcess(e,t){const i=this.router.parseUrl(e),s=i&&this.router.matchRoute(i,t);if(!s)return Promise.reject(R(C.MISSING_ROUTE,[e]));this.pendingRoute={url:e,...s};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(R(C.PRENAV_FAILED,[e]))))}processError(e){l({id:d}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t,i){const s=this.filterNavigateOptions(i);let r=this.router.generateUrl(e,s);if(r){r=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(r)}this._sendEvent(j,{url:r,replace:t,address:e})}generateUrl(e,t){const i=this.filterNavigateOptions(t),s=this.router.generateUrl(e,i);if(!s)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${s}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){U&&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 X(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}`,s="/"===e.charAt(0)?"":"/";e=i+s+e}const t={},i=document.createElement("a");i.href=e;const s=i.search.substring(1);return s&&s.split("&").forEach((e=>{const[i,s=""]=e.split("=");t[M(i)]=M(s)})),{href:i.href,origin:`${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`,pathname:i.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),i=t.href.replace(/:\d+/,""),s=t.origin.replace(/:\d+/,"");return i.replace(s,"")}class q extends B{constructor(){super(...arguments),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(U&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&U&&this.catchBrowserUpdate(X(window.location.href))}disconnect(){super.disconnect(),U&&window.removeEventListener("popstate",this.onpopstate)}async process(e,t,i,s=!0){const r=await super.process(e,t,i,s);return r&&!this.historyDisabled&&s&&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)),r}catchBrowserUpdate(e){this.process(e,!1,{},!1)}}let z=!1;class Y extends o{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=U?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};U&&this.router&&(this.routerApi=function(e,t={},i){const s=t.historyDisabled?new B(t,i,e):new q(t,i,e),r={addPreNavigate:e=>(s.addPreNavigate(e),r),addPostNavigate:e=>(s.subscribe(e),r),addErrorNavigate:e=>(s.addErrorNavigate(e),r),connect:()=>{s.connect(),x(!z||!!s.parent,C.MULTIPLE_ROOTS),z=z||!s.parent,r.id=s.contextId},disconnect:()=>{z=z&&!!s.parent,s.disconnect()}};return r}(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,document.title=t);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})}}Y.renderMode="light",r(Y,{publicProps:{router:{config:0},historyDisabled:{config:0}}});const J=n(Y,{tmpl:E,sel:"lwr-router-container",apiVersion:63});export{J as default};
2
2
  //# sourceMappingURL=routerContainer.js.map
@@ -70,7 +70,7 @@ var Outlet = class extends import_lwc.LightningElement {
70
70
  }
71
71
  refocus() {
72
72
  if (!this.refocusOff) {
73
- const region = this.querySelector(`div[role='region'].outlet`);
73
+ const region = this.refs?.outlet;
74
74
  if (region)
75
75
  region.focus();
76
76
  }
@@ -66,7 +66,7 @@ var RouterContainer = class extends import_lwc.LightningElement {
66
66
  this.currentTitle = title;
67
67
  document.title = title;
68
68
  }
69
- const a11yTitle = this.querySelector("span.router-title");
69
+ const a11yTitle = this.refs?.title;
70
70
  if (a11yTitle)
71
71
  a11yTitle.innerHTML = this.currentTitle;
72
72
  }
@@ -47,7 +47,7 @@ export default class Outlet extends LightningElement {
47
47
  // If the feature is not turned off, put the browser focus onto the dynamic content.
48
48
  // This is done after a route change for accessibility.
49
49
  if (!this.refocusOff) {
50
- const region = this.querySelector(`div[role='region'].outlet`);
50
+ const region = this.refs?.outlet;
51
51
  if (region)
52
52
  region.focus();
53
53
  }
@@ -67,7 +67,7 @@ export default class RouterContainer extends LightningElement {
67
67
  }
68
68
  // Update the inner HTML of the aria-live region for screen readers
69
69
  // This DOM node must be touched for every route change
70
- const a11yTitle = this.querySelector('span.router-title');
70
+ const a11yTitle = this.refs?.title;
71
71
  if (a11yTitle)
72
72
  a11yTitle.innerHTML = this.currentTitle;
73
73
  }
@@ -1,10 +1,10 @@
1
1
  <template lwc:render-mode="light">
2
2
  <div role="alert">
3
- <template if:true={hasError}>
3
+ <template lwc:if={hasError}>
4
4
  <slot name="error"></slot>
5
5
  </template>
6
6
  </div>
7
- <div class="outlet" role="region" tabindex="-1">
8
- <lwr-dynamic lwc:dynamic={viewCtor} class="lwr-dynamic"></lwr-dynamic>
7
+ <div class="outlet" role="region" tabindex="-1" lwc:ref="outlet">
8
+ <lwc:component lwc:is={viewCtor} class="lwr-dynamic"></lwc:component>
9
9
  </div>
10
10
  </template>
@@ -53,7 +53,7 @@ export default class Outlet extends LightningElement {
53
53
  // If the feature is not turned off, put the browser focus onto the dynamic content.
54
54
  // This is done after a route change for accessibility.
55
55
  if (!this.refocusOff) {
56
- const region = this.querySelector(`div[role='region'].outlet`);
56
+ const region = this.refs?.outlet;
57
57
  if (region) region.focus();
58
58
  }
59
59
  }
@@ -3,5 +3,6 @@
3
3
  <isExposed>true</isExposed>
4
4
  <capabilities>
5
5
  <capability>lightning__ServerRenderableWithHydration</capability>
6
+ <capability>lightning__dynamicComponent</capability>
6
7
  </capabilities>
7
8
  </LightningComponentBundle>
@@ -1,4 +1,4 @@
1
1
  <template lwc:render-mode="light">
2
2
  <slot></slot>
3
- <span class="router-title" aria-live="polite" aria-atomic="true"></span>
3
+ <span class="router-title" aria-live="polite" aria-atomic="true" lwc:ref="title"></span>
4
4
  </template>
@@ -72,7 +72,7 @@ export default class RouterContainer extends LightningElement {
72
72
  }
73
73
  // Update the inner HTML of the aria-live region for screen readers
74
74
  // This DOM node must be touched for every route change
75
- const a11yTitle = this.querySelector('span.router-title');
75
+ const a11yTitle = this.refs?.title;
76
76
  if (a11yTitle) a11yTitle.innerHTML = this.currentTitle;
77
77
  }
78
78
 
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.17.0-alpha.0",
8
+ "version": "0.17.1-alpha.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.17.0-alpha.0",
57
- "@lwrjs/diagnostics": "0.17.0-alpha.0",
58
- "@lwrjs/shared-utils": "0.17.0-alpha.0",
56
+ "@lwrjs/client-modules": "0.17.1-alpha.0",
57
+ "@lwrjs/diagnostics": "0.17.1-alpha.0",
58
+ "@lwrjs/shared-utils": "0.17.1-alpha.0",
59
59
  "ajv": "6.12.6"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@lwc/jest-preset": "^16.1.0",
63
- "@lwrjs/fs-watch": "0.17.0-alpha.0",
63
+ "@lwrjs/fs-watch": "0.17.1-alpha.0",
64
64
  "@rollup/plugin-typescript": "^11.1.6",
65
65
  "jest": "^26.6.3",
66
66
  "memfs": "^4.13.0",
@@ -99,5 +99,5 @@
99
99
  "volta": {
100
100
  "extends": "../../../package.json"
101
101
  },
102
- "gitHead": "aa5c06120e4301352c2793f93d237603756f9db4"
102
+ "gitHead": "158ac917264ee5af17253f1674cde8e133811546"
103
103
  }