@lwrjs/router 0.8.6 → 0.8.8
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/routerContainer/routerContainer.cjs +4 -1
- package/build/modules/lwr/routerContainer/routerContainer.css +1 -1
- package/build/modules/lwr/routerContainer/routerContainer.d.ts +1 -0
- package/build/modules/lwr/routerContainer/routerContainer.html +2 -2
- package/build/modules/lwr/routerContainer/routerContainer.js +4 -3
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
import{registerTemplate as e,freezeTemplate as t,registerDecorators as r,createContextProvider as i,registerComponent as n,LightningElement as o}from"lwc";import{ROUTER_VIEW as s,ROUTER_NAV as a,ROUTER_ERROR as c}from"lwr/metrics";import{logOperationEnd as d,logOperationStart as l}from"lwr/profiler";var h=[function(e,t,r){return"span"+(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 u={key:0},p=[],v={classMap:{"router-title":!0},attrs:{"aria-live":"polite","aria-atomic":"true"},context:{lwc:{dom:"manual"}},key:1};function g(e,t,r,i){const{s:n,h:o}=e;return[n("",u,p,r),o("span",v)]}var m=e(g);function f(e){if(null==e)throw new TypeError("Provider must be defined.")}g.slots=[""],g.stylesheets=[],h&&g.stylesheets.push.apply(g.stylesheets,h),h&&(g.stylesheetToken="lwr-routerContainer_routerContainer"),t(g);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){f(e);const r=t,i=this.getInfo(e);i.contextValue=t,i.consumers.forEach((e=>e.provide(r))),0===i.consumers.size&&r?.onComplete&&r.onComplete()}getContext(e){f(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){f(e),this.infoMap.delete(e)}subscribeContext(e,t){f(e);const{consumers:r,contextValue:i}=this.getInfo(e);r.has(t)||(r.add(t),t.provide(i))}unsubscribeContext(e,t){f(e),this.getInfo(e).consumers.delete(t)}}function E(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function I(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?E(Object(r),!0).forEach((function(t){w(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):E(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function w(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r(b,{fields:["infoMap"]});const R=1;function N(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,r)=>t[r])):e}function _(e,t){const r=I(I({},e),{},{message:N(e.message,t)});return e.address&&(r.address=N(e.address,t)),e.stack&&(r.stack=N(e.stack,t)),r}function O(e,t,r){if(!e)throw new Error(function(e,t){return`${e.code}: ${N(e.message,t)}`}(t,r))}const y={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:R},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:R},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:R},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:R},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:R},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:R,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:R,address:"{0}"},PRENAV_FAILED:{code:"LWR4008",message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:"LWR4009",message:'A route definition must contain a "uri" property.',level:R},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:R},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:R},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:R},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:R},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:R},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:R},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:R,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:R},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:R,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:R},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:R},DESTINATION_NOT_FOUND:{code:"LWR4028",message:"Route handler returned 404: Not Found",level:R},DESTINATION_ERROR:{code:"LWR4029",message:"Route handler returned error status {0}: {1}",level:R,stack:"{2}"}},P=new WeakMap;function x(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,r){e.setContext(t,r)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,r){e.subscribeContext(t,r)}static unsubscribeContext(t,r){e.unsubscribeContext(t,r)}}).contextSchema={value:"required"},t}const L=x(new b(void 0)),C=x(new b(void 0)),T=new b(void 0),D=class extends(x(T)){async update(e,t){if(t){const r=e&&e.viewName?e.viewName:"default",i=t.viewset[r],n=i,o=n&&n.module||i;let s;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;s=n.specifier?_(y.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[n.specifier,r,t.message,t.stack||""]):_(y.VIEW_IMPORT_FAILED,[r,t.message,t.stack||""])}else s=_(y.VIEW_MISSING,[r]);t.onComplete&&t.onComplete(s)}}};function S(){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,r)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(r(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 U="undefined"!=typeof document,W=`universalcontainergetnavigationcontext${M()}`,j=U?i(C):void 0,k=U?i(D):void 0,F=U?i(L):void 0;function V(e,t,r,i){r&&i&&(i.setContext(t,e),r(t,{consumerConnectedCallback:i.subscribeContext.bind(i,t),consumerDisconnectedCallback:i.unsubscribeContext.bind(i,t)}))}function G(){let e,t,r=[];const i=i=>{r.filter((e=>null!==e)).forEach((e=>e.error&&e.error(i))),e=void 0,t=i};return{next:i=>{r.filter((e=>null!==e)).forEach((e=>e.next&&e.next(i))),e=i,t=void 0},error:i,complete:()=>{r.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),r=[],e=void 0,t=void 0},subscribe:(n,o=!0)=>{(e=>{r.push(e)})(n),e&&o&&n.next(e),t&&i(t);const s=r.length-1;return{unsubscribe:()=>(e=>{r=[...r.slice(0,e),...r.slice(e+1)]})(s)}}}}function $(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function H(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?$(Object(r),!0).forEach((function(t){B(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):$(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function B(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const X=`universalcontainernavigationevent${M()}`,q=`universalcontainerparentevent${M()}`;class z{constructor(e,t,r){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=S(),this.errorNavFilters=S(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:r,address:i}=t.detail;this.config.handleNavigation(i,r)?this.root&&!e?this.root.processError(_(y.MISSING_URL,[JSON.stringify(i)])):this.parent||this.process(e,r):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=r||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,r){if(r)this.processError(r);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;d({id:s,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||H(H({},e),{},{url:t}),this.committedRoute=H(H({},this.pendingRoute),e),C.setContext(this.target,e.route.pageReference),this.routeObservable.next(H(H({},this.committedRoute),{},{viewset:e.viewset})),d({id:a,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(q,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:e=>this.generateUrl(e),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const r={id:e,value:t,update:e=>{r.value=e}};P.set(r.id,r)}(this.contextId,e),V(this.contextId,this.target,F,L),V(void 0,this.target,j,C),V(void 0,this.target,k,D),this.router.subscribe((e=>{if(404===e.status)return void this.processError(_(y.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(_(y.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},r=this.router.generateUrl(t)||"";if(l({id:s,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,r)};D.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,r)}),!0),U&&(this.target.addEventListener(X,this._handleNavigationEvent),this.target.addEventListener(q,this._handleParentEvent),this.target.addEventListener(W,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(X,this._handleNavigationEvent),this.target.removeEventListener(q,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((()=>{O(!this.child,y.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){this.eventId=(new Date).getTime().toString(),l({id:a,specifier:this.eventId});try{this.parent||await this.preProcess(e)}catch(e){if(e.code)return this.processError(e),!1;throw e}const r=this.router.parseUrl(e);return r&&this.router.navigate(r),!0}preProcess(e){const t=this.router.parseUrl(e),r=t&&this.router.matchRoute(t);if(!r)return Promise.reject(_(y.MISSING_ROUTE,[e]));this.pendingRoute=H({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(_(y.PRENAV_FAILED,[e]))))}processError(e){l({id:c}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t){let r=this.router.generateUrl(e);if(r){r=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(r)}this._sendEvent(X,{url:r,replace:t,address:e})}generateUrl(e){const t=this.router.generateUrl(e);if(!t)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${t}`}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}}function Y(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",r=`${window.location.protocol}//${window.location.hostname}${t}`,i="/"===e.charAt(0)?"":"/";e=r+i+e}const t={},r=document.createElement("a");r.href=e;const i=r.search.substring(1);return i&&i.split("&").forEach((e=>{const[r,i=""]=e.split("=");t[A(r)]=A(i)})),{href:r.href,origin:`${r.protocol}//${r.hostname}${r.port?`:${r.port}`:""}`,pathname:r.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),r=t.href.replace(/:\d+/,""),i=t.origin.replace(/:\d+/,"");return r.replace(i,"")}r(z,{fields:["pendingRoute","committedRoute","contextId","connected","preNavFilters","errorNavFilters","_handleNavigationEvent","_handleParentEvent"]});class J extends z{constructor(...e){super(...e),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(U&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&U&&this.catchBrowserUpdate(Y(document.location.href))}disconnect(){super.disconnect(),U&&window.removeEventListener("popstate",this.onpopstate)}async process(e,t,r=!0){const i=await super.process(e);return i&&!this.historyDisabled&&r&&this.connected&&!this.parent&&(t?function(e,t){const r=t||{};window.history.replaceState(r,"",e)}(e):function(e,t){const r=t||{};window.history.pushState(r,"",e)}(e)),i}catchBrowserUpdate(e){this.process(e,!1,!1)}}r(J,{fields:["historyDisabled"]});let Q=!1;class K 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)};this.router&&(this.routerApi=function(e,t={},r){const i=t.historyDisabled?new z(t,r,e):new J(t,r,e),n={addPreNavigate:e=>(i.addPreNavigate(e),n),addPostNavigate:e=>(i.subscribe(e),n),addErrorNavigate:e=>(i.addErrorNavigate(e),n),connect:()=>{i.connect(),O(!Q||!!i.parent,y.MULTIPLE_ROOTS),Q=Q||!i.parent,n.id=i.contextId},disconnect:()=>{Q=Q&&!!i.parent,i.disconnect()}};return n}(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),this.template.querySelector("span.router-title").innerHTML=this.currentTitle}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const r=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(r),!r.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,r){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:r})}}r(K,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var Z=n(K,{tmpl:m});export default Z;
|
|
1
|
+
import{registerTemplate as e,parseFragment as t,freezeTemplate as r,registerDecorators as i,createContextProvider as n,registerComponent as o,LightningElement as s}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as l,logOperationStart as h}from"lwr/profiler";var u=[function(e,t,r){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=t`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,v={key:0},g=[];function f(e,t,r,i){const{s:n,st:o,f:s}=e;return s([n("",v,g,r),o(p(),2)])}var m=e(f);function b(e){if(null==e)throw new TypeError("Provider must be defined.")}f.slots=[""],f.stylesheets=[],f.renderMode="light",u&&f.stylesheets.push.apply(f.stylesheets,u),u&&(f.stylesheetToken="lwr-routerContainer_routerContainer"),r(f);class E{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){b(e);const r=t,i=this.getInfo(e);i.contextValue=t,i.consumers.forEach((e=>e.provide(r))),0===i.consumers.size&&r?.onComplete&&r.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:r,contextValue:i}=this.getInfo(e);r.has(t)||(r.add(t),t.provide(i))}unsubscribeContext(e,t){b(e),this.getInfo(e).consumers.delete(t)}}function I(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function w(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?I(Object(r),!0).forEach((function(t){R(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function R(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}i(E,{fields:["infoMap"]});const N=1;function _(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,r)=>t[r])):e}function O(e,t){const r=w(w({},e),{},{message:_(e.message,t)});return e.address&&(r.address=_(e.address,t)),e.stack&&(r.stack=_(e.stack,t)),r}function y(e,t,r){if(!e)throw new Error(function(e,t){return`${e.code}: ${_(e.message,t)}`}(t,r))}const P={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:N},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:N},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:N},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:N},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:N},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:N,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:N,address:"{0}"},PRENAV_FAILED:{code:"LWR4008",message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:"LWR4009",message:'A route definition must contain a "uri" property.',level:N},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:N},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:N},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:N},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:N},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:N},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:N},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:N,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:N},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:N,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:N},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:N},DESTINATION_NOT_FOUND:{code:"LWR4028",message:"Route handler returned 404: Not Found",level:N},DESTINATION_ERROR:{code:"LWR4029",message:"Route handler returned error status {0}: {1}",level:N,stack:"{2}"}},L=new WeakMap;function x(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,r){e.setContext(t,r)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,r){e.subscribeContext(t,r)}static unsubscribeContext(t,r){e.unsubscribeContext(t,r)}}).contextSchema={value:"required"},t}const C=x(new E(void 0)),T=x(new E(void 0)),D=new E(void 0),S=class extends(x(D)){async update(e,t){if(t){const r=e&&e.viewName?e.viewName:"default",i=t.viewset[r],n=i,o=n&&n.module||i;let s;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;s=n.specifier?O(P.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[n.specifier,r,t.message,t.stack||""]):O(P.VIEW_IMPORT_FAILED,[r,t.message,t.stack||""])}else s=O(P.VIEW_MISSING,[r]);t.onComplete&&t.onComplete(s)}}};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,r)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(r(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 U(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const W="undefined"!=typeof document,j=`universalcontainergetnavigationcontext${U()}`,k=W?n(T):void 0,F=W?n(S):void 0,V=W?n(C):void 0;function $(e,t,r,i){r&&i&&(i.setContext(t,e),r(t,{consumerConnectedCallback:i.subscribeContext.bind(i,t),consumerDisconnectedCallback:i.unsubscribeContext.bind(i,t)}))}function G(){let e,t,r=[];const i=i=>{r.filter((e=>null!==e)).forEach((e=>e.error&&e.error(i))),e=void 0,t=i};return{next:i=>{r.filter((e=>null!==e)).forEach((e=>e.next&&e.next(i))),e=i,t=void 0},error:i,complete:()=>{r.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),r=[],e=void 0,t=void 0},subscribe:(n,o=!0)=>{(e=>{r.push(e)})(n),e&&o&&n.next(e),t&&i(t);const s=r.length-1;return{unsubscribe:()=>(e=>{r=[...r.slice(0,e),...r.slice(e+1)]})(s)}}}}function H(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function B(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?H(Object(r),!0).forEach((function(t){X(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):H(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function X(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const q=`universalcontainernavigationevent${U()}`,z=`universalcontainerparentevent${U()}`;class Y{constructor(e,t,r){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:r,address:i}=t.detail;this.config.handleNavigation(i,r)?this.root&&!e?this.root.processError(O(P.MISSING_URL,[JSON.stringify(i)])):this.parent||this.process(e,r):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=r||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,r){if(r)this.processError(r);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;l({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||B(B({},e),{},{url:t}),this.committedRoute=B(B({},this.pendingRoute),e),T.setContext(this.target,e.route.pageReference),this.routeObservable.next(B(B({},this.committedRoute),{},{viewset:e.viewset})),l({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(z,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:e=>this.generateUrl(e),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const r={id:e,value:t,update:e=>{r.value=e}};L.set(r.id,r)}(this.contextId,e),$(this.contextId,this.target,V,C),$(void 0,this.target,k,T),$(void 0,this.target,F,S),this.router.subscribe((e=>{if(404===e.status)return void this.processError(O(P.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(O(P.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},r=this.router.generateUrl(t)||"";if(h({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,r)};S.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,r)}),!0),W&&(this.target.addEventListener(q,this._handleNavigationEvent),this.target.addEventListener(z,this._handleParentEvent),this.target.addEventListener(j,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(q,this._handleNavigationEvent),this.target.removeEventListener(z,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((()=>{y(!this.child,P.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){this.eventId=(new Date).getTime().toString(),h({id:c,specifier:this.eventId});try{this.parent||await this.preProcess(e)}catch(e){if(e.code)return this.processError(e),!1;throw e}const r=this.router.parseUrl(e);return r&&this.router.navigate(r),!0}preProcess(e){const t=this.router.parseUrl(e),r=t&&this.router.matchRoute(t);if(!r)return Promise.reject(O(P.MISSING_ROUTE,[e]));this.pendingRoute=B({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(O(P.PRENAV_FAILED,[e]))))}processError(e){h({id:d}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t){let r=this.router.generateUrl(e);if(r){r=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(r)}this._sendEvent(q,{url:r,replace:t,address:e})}generateUrl(e){const t=this.router.generateUrl(e);if(!t)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${t}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){W&&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}}function J(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",r=`${window.location.protocol}//${window.location.hostname}${t}`,i="/"===e.charAt(0)?"":"/";e=r+i+e}const t={},r=document.createElement("a");r.href=e;const i=r.search.substring(1);return i&&i.split("&").forEach((e=>{const[r,i=""]=e.split("=");t[M(r)]=M(i)})),{href:r.href,origin:`${r.protocol}//${r.hostname}${r.port?`:${r.port}`:""}`,pathname:r.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),r=t.href.replace(/:\d+/,""),i=t.origin.replace(/:\d+/,"");return r.replace(i,"")}i(Y,{fields:["pendingRoute","committedRoute","contextId","connected","preNavFilters","errorNavFilters","_handleNavigationEvent","_handleParentEvent"]});class Q extends Y{constructor(...e){super(...e),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(W&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&W&&this.catchBrowserUpdate(J(document.location.href))}disconnect(){super.disconnect(),W&&window.removeEventListener("popstate",this.onpopstate)}async process(e,t,r=!0){const i=await super.process(e);return i&&!this.historyDisabled&&r&&this.connected&&!this.parent&&(t?function(e,t){const r=t||{};window.history.replaceState(r,"",e)}(e):function(e,t){const r=t||{};window.history.pushState(r,"",e)}(e)),i}catchBrowserUpdate(e){this.process(e,!1,!1)}}i(Q,{fields:["historyDisabled"]});let K=!1;class Z extends s{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=W?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};this.router&&(this.routerApi=function(e,t={},r){const i=t.historyDisabled?new Y(t,r,e):new Q(t,r,e),n={addPreNavigate:e=>(i.addPreNavigate(e),n),addPostNavigate:e=>(i.subscribe(e),n),addErrorNavigate:e=>(i.addErrorNavigate(e),n),connect:()=>{i.connect(),y(!K||!!i.parent,P.MULTIPLE_ROOTS),K=K||!i.parent,n.id=i.contextId},disconnect:()=>{K=K&&!!i.parent,i.disconnect()}};return n}(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 r=this.querySelector("span.router-title");r&&(r.innerHTML=this.currentTitle)}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const r=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(r),!r.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,r){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:r})}}Z.renderMode="light",i(Z,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var ee=o(Z,{tmpl:m});export default ee;
|
|
@@ -66,7 +66,9 @@ var RouterContainer = class extends import_lwc.LightningElement {
|
|
|
66
66
|
this.currentTitle = title;
|
|
67
67
|
document.title = title;
|
|
68
68
|
}
|
|
69
|
-
this.
|
|
69
|
+
const a11yTitle = this.querySelector("span.router-title");
|
|
70
|
+
if (a11yTitle)
|
|
71
|
+
a11yTitle.innerHTML = this.currentTitle;
|
|
70
72
|
}
|
|
71
73
|
errorNavigate(error) {
|
|
72
74
|
this.dispatchEvent(this._createEvent("errornavigate", error));
|
|
@@ -91,6 +93,7 @@ var RouterContainer = class extends import_lwc.LightningElement {
|
|
|
91
93
|
});
|
|
92
94
|
}
|
|
93
95
|
};
|
|
96
|
+
RouterContainer.renderMode = "light";
|
|
94
97
|
__decorate([
|
|
95
98
|
import_lwc.api
|
|
96
99
|
], RouterContainer.prototype, "router", 2);
|
|
@@ -10,6 +10,7 @@ import type { MessageObject } from 'lwr/routerUtils';
|
|
|
10
10
|
import type { PageReference, Router, RoutingResult } from 'lwr/router';
|
|
11
11
|
import type { RouteChange } from 'lwr/domRouterUtils';
|
|
12
12
|
export default class RouterContainer extends LightningElement {
|
|
13
|
+
static renderMode: string;
|
|
13
14
|
routerApi?: RouterApi;
|
|
14
15
|
router?: Router<PageReference>;
|
|
15
16
|
historyDisabled: boolean;
|
|
@@ -12,7 +12,8 @@ import { hasDocument } from 'lwr/routerUtils';
|
|
|
12
12
|
* Provides a LWC router component. These can be nested and all report to the root router.
|
|
13
13
|
*/
|
|
14
14
|
export default class RouterContainer extends LightningElement {
|
|
15
|
-
// Instance of the Router class for this LWC.
|
|
15
|
+
static renderMode = 'light'; // Instance of the Router class for this LWC.
|
|
16
|
+
|
|
16
17
|
@api
|
|
17
18
|
router;
|
|
18
19
|
@api
|
|
@@ -71,10 +72,10 @@ export default class RouterContainer extends LightningElement {
|
|
|
71
72
|
document.title = title;
|
|
72
73
|
} // Update the inner HTML of the aria-live region for screen readers
|
|
73
74
|
// This DOM node must be touched for every route change
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
this.
|
|
77
|
+
const a11yTitle = this.querySelector('span.router-title');
|
|
78
|
+
if (a11yTitle) a11yTitle.innerHTML = this.currentTitle;
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* The errorNavigate hook surfaced as a CustomEvent.
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.8.
|
|
8
|
+
"version": "0.8.8",
|
|
9
9
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"utam:compile": "utam -c utam.config.cjs -t module"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@lwrjs/client-modules": "0.8.
|
|
52
|
-
"@lwrjs/diagnostics": "0.8.
|
|
53
|
-
"@lwrjs/shared-utils": "0.8.
|
|
51
|
+
"@lwrjs/client-modules": "0.8.8",
|
|
52
|
+
"@lwrjs/diagnostics": "0.8.8",
|
|
53
|
+
"@lwrjs/shared-utils": "0.8.8",
|
|
54
54
|
"ajv": "6.12.6"
|
|
55
55
|
},
|
|
56
56
|
"lwc": {
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=14.15.4 <19"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "4fa9f1d7c9cfb284e7c416ae9efc481b7f7d8d7a"
|
|
80
80
|
}
|