@lwrjs/router 0.17.2-alpha.8 → 0.17.2

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
- function e(e){if(null==e)throw new TypeError("Provider must be defined.")}class t{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(t,n){e(t);const o=n,s=this.getInfo(t);s.contextValue=n,s.consumers.forEach((e=>e.provide(o))),0===s.consumers.size&&o?.onComplete&&o.onComplete()}getContext(t){e(t);const{contextValue:n}=this.getInfo(t);return void 0!==n?n:this.defaultValue}clearContext(t){e(t),this.infoMap.delete(t)}subscribeContext(t,n){e(t);const{consumers:o,contextValue:s}=this.getInfo(t);o.has(n)||(o.add(n),n.provide(s))}unsubscribeContext(t,n){e(t),this.getInfo(t).consumers.delete(n)}}const n="LWR",o=1;function s(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}function a(e,t){return`${e.code}: ${s(e.message,t)}`}function i(e,t){const n={...e,message:s(e.message,t)};return e.address&&(n.address=s(e.address,t)),e.stack&&(n.stack=s(e.stack,t)),n}const r={INVALID_MIXIN_CMP:{code:`${n}4001`,message:"{0} must be an Element type",level:o},MISSING_CONTEXT:{code:`${n}4002`,message:"Could not find context to perform navigation action.",level:o},INVALID_CONTEXT:{code:`${n}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:o},MULTIPLE_ROOTS:{code:`${n}4004`,message:"Router connection failed. There can only be one root router.",level:o},MULTIPLE_CHILDREN:{code:`${n}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:o},MISSING_ROUTE:{code:`${n}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:o,address:"{0}"},MISSING_URL:{code:`${n}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:o,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:o,address:"{0}"},MISSING_ROUTE_CMP:{code:`${n}4016`,message:"Expected a route view component with a default export.",level:o},MISSING_DATA_CONTEXT:{code:`${n}4018`,message:"Could not find context to retrieve navigation data.",level:o},INVALID_ROUTE_QUERY:{code:`${n}4019`,message:"Invalid query param in route definition.",level:o},MISSING_PAGE_BINDING:{code:`${n}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:o,address:"{0}"},INVALID_PAGE_BINDING:{code:`${n}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:o,address:"{0}"},INVALID_URI_SYNTAX:{code:`${n}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:o,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${n}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:o,stack:"{2}"},VIEW_MISSING:{code:`${n}4024`,message:'Expected a view with name "{0}" in the viewset',level:o},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${n}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:o,stack:"{3}"},NO_ROUTE_MATCH:{code:`${n}4026`,message:"A routing match cannot be found for: {0}",level:o},INVALID_ROUTE_HANDLER:{code:`${n}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:o},DESTINATION_NOT_FOUND:{code:`${n}4028`,message:"Route handler returned 404: Not Found",level:o},DESTINATION_ERROR:{code:`${n}4029`,message:"Route handler returned error status {0}: {1}",level:o,stack:"{2}"},NO_INIT_URL:{code:`${n}4030`,message:'Cannot initialize a server router without a "url"',level:o}},c=new WeakMap;function l(e){const t=c.get(e);if(!t||!t.value)throw new Error(a(r.MISSING_CONTEXT));return t.value}function d(e,t){const n={id:e,value:t,update:e=>{n.value=e}};return c.set(n.id,n),n}function u(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,n){e.setContext(t,n)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,n){e.subscribeContext(t,n)}static unsubscribeContext(t,n){e.unsubscribeContext(t,n)}}).contextSchema={value:"required"},t}const I=u(new t(void 0)),v=u(new t(void 0)),g=new t(void 0),m=class extends(u(g)){async update(e,t){if(t){const n=e&&e.viewName?e.viewName:"default",o=t.viewset[n],s=o,a=s&&s.module||o;let c;if(a)try{const e=await a(),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;c=s.specifier?i(r.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,n,t.message,t.stack||""]):i(r.VIEW_IMPORT_FAILED,[n,t.message,t.stack||""])}else c=i(r.VIEW_MISSING,[n]);t.onComplete&&t.onComplete(c)}}};function h(e,t,n,o){l(e).navigate(t,n,o)}function f(e,t,n){return l(e).generateUrl(t,n)}const E=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,_=Symbol("Navigate"),N=Symbol("GenerateUrl"),p=Symbol("NavContext"),w=Symbol("NavContext"),C="undefined"==typeof window;function T(e){!function(e,t,n){if(!e)throw new Error(a(t,n))}("function"==typeof e.prototype.dispatchEvent,r.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[w](){if(!this[p]&&(this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{callback:e=>{this[p]=e}}})),!this[p]))throw new Error(a(r.MISSING_CONTEXT))}[_](e,t,n){C||(this[w](),h(this[p],e,t,n))}async[N](e,t){return C?null:(this[w](),f(this[p],e,t))}}}T.Navigate=_,T.GenerateUrl=N,T.NavContext=p;export{t as ContextInfo,v as CurrentPageReference,m as CurrentView,I as NavigationContext,T as NavigationMixin,u as generateContextualWireAdapter,f as generateUrl,l as getNavigationHelm,h as navigate,d as registerNavigationHelm};
1
+ function e(e){if(null==e)throw new TypeError("Provider must be defined.")}class t{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(t,o){e(t);const n=o,s=this.getInfo(t);s.contextValue=o,s.consumers.forEach((e=>e.provide(n))),0===s.consumers.size&&n?.onComplete&&n.onComplete()}getContext(t){e(t);const{contextValue:o}=this.getInfo(t);return void 0!==o?o:this.defaultValue}clearContext(t){e(t),this.infoMap.delete(t)}subscribeContext(t,o){e(t);const{consumers:n,contextValue:s}=this.getInfo(t);n.has(o)||(n.add(o),o.provide(s))}unsubscribeContext(t,o){e(t),this.getInfo(t).consumers.delete(o)}}const o="LWR",n=1;function s(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,o)=>t[o])):e}function a(e,t){return`${e.code}: ${s(e.message,t)}`}function i(e,t){const o={...e,message:s(e.message,t)};return e.address&&(o.address=s(e.address,t)),e.stack&&(o.stack=s(e.stack,t)),o}const r={INVALID_MIXIN_CMP:{code:`${o}4001`,message:"{0} must be an Element type",level:n},MISSING_CONTEXT:{code:`${o}4002`,message:"Could not find context to perform navigation action.",level:n},INVALID_CONTEXT:{code:`${o}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:n},MULTIPLE_ROOTS:{code:`${o}4004`,message:"Router connection failed. There can only be one root router.",level:n},MULTIPLE_CHILDREN:{code:`${o}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:n},MISSING_ROUTE:{code:`${o}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:n,address:"{0}"},MISSING_URL:{code:`${o}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:n,address:"{0}"},PRENAV_FAILED:{code:`${o}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${o}4009`,message:'Route definition with id "{0}" is missing a "uri" property.',level:n,address:"{0}"},MISSING_ROUTE_CMP:{code:`${o}4016`,message:"Expected a route view component with a default export.",level:n},MISSING_DATA_CONTEXT:{code:`${o}4018`,message:"Could not find context to retrieve navigation data.",level:n},INVALID_ROUTE_QUERY:{code:`${o}4019`,message:"Invalid query param in route definition.",level:n},MISSING_PAGE_BINDING:{code:`${o}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:n,address:"{0}"},INVALID_PAGE_BINDING:{code:`${o}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:n,address:"{0}"},INVALID_URI_SYNTAX:{code:`${o}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:n,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${o}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:n,stack:"{2}"},VIEW_MISSING:{code:`${o}4024`,message:'Expected a view with name "{0}" in the viewset',level:n},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${o}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:n,stack:"{3}"},NO_ROUTE_MATCH:{code:`${o}4026`,message:"A routing match cannot be found for: {0}",level:n},INVALID_ROUTE_HANDLER:{code:`${o}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:n},DESTINATION_NOT_FOUND:{code:`${o}4028`,message:"Route handler returned 404: Not Found",level:n},DESTINATION_ERROR:{code:`${o}4029`,message:"Route handler returned error status {0}: {1}",level:n,stack:"{2}"},NO_INIT_URL:{code:`${o}4030`,message:'Cannot initialize a server router without a "url"',level:n}},c=new WeakMap;function l(e){const t=c.get(e);if(!t||!t.value)throw new Error(a(r.MISSING_CONTEXT));return t.value}function d(e,t){const o={id:e,value:t,update:e=>{o.value=e}};return c.set(o.id,o),o}function u(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,o){e.setContext(t,o)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,o){e.subscribeContext(t,o)}static unsubscribeContext(t,o){e.unsubscribeContext(t,o)}}).contextSchema={value:"required"},t}const I=u(new t(void 0)),v=u(new t(void 0)),g=new t(void 0),m=class extends(u(g)){async update(e,t){if(t){const o=e&&e.viewName?e.viewName:"default",n=t.viewset[o],s=n,a=s&&s.module||n;let c;if(a)try{const e=await a(),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;c=s.specifier?i(r.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,o,t.message,t.stack||""]):i(r.VIEW_IMPORT_FAILED,[o,t.message,t.stack||""])}else c=i(r.VIEW_MISSING,[o]);t.onComplete&&t.onComplete(c)}}};function h(e,t,o,n){l(e).navigate(t,o,n)}function f(e,t,o){return l(e).generateUrl(t,o)}const _=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,E=Symbol("Navigate"),N=Symbol("GenerateUrl"),p=Symbol("NavContext"),w=Symbol("NavContext"),C="undefined"==typeof window;function T(e){!function(e,t,o){if(!e)throw new Error(a(t,o))}("function"==typeof e.prototype.dispatchEvent,r.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[w](){if(!this[p]&&(this.dispatchEvent(new CustomEvent(_,{bubbles:!0,composed:!0,detail:{callback:e=>{this[p]=e}}})),!this[p]))throw new Error(a(r.MISSING_CONTEXT))}[E](e,t,o){C||(this[w](),h(this[p],e,t,o))}async[N](e,t){return C?null:(this[w](),f(this[p],e,t))}}}T.Navigate=E,T.GenerateUrl=N,T.NavContext=p;export{t as ContextInfo,v as CurrentPageReference,m as CurrentView,I as NavigationContext,T as NavigationMixin,u as generateContextualWireAdapter,f as generateUrl,l as getNavigationHelm,h as navigate,d as registerNavigationHelm};
2
2
  //# sourceMappingURL=navigation.js.map
@@ -1,2 +1,2 @@
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};
1
+ import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as s,registerDecorators as r,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";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,s){const{s:r,sp:o,st:n}=e;return[r("",g,m,i),n(v,2,[o(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 N{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,s=this.getInfo(e);s.contextValue=t,s.consumers.forEach((e=>e.provide(i))),0===s.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:s}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(s))}unsubscribeContext(e,t){b(e),this.getInfo(e).consumers.delete(t)}}const w="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:`${w}4001`,message:"{0} must be an Element type",level:_},MISSING_CONTEXT:{code:`${w}4002`,message:"Could not find context to perform navigation action.",level:_},INVALID_CONTEXT:{code:`${w}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:_},MULTIPLE_ROOTS:{code:`${w}4004`,message:"Router connection failed. There can only be one root router.",level:_},MULTIPLE_CHILDREN:{code:`${w}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:_},MISSING_ROUTE:{code:`${w}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:_,address:"{0}"},MISSING_URL:{code:`${w}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:_,address:"{0}"},PRENAV_FAILED:{code:`${w}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${w}4009`,message:'Route definition with id "{0}" is missing a "uri" property.',level:_,address:"{0}"},MISSING_ROUTE_CMP:{code:`${w}4016`,message:"Expected a route view component with a default export.",level:_},MISSING_DATA_CONTEXT:{code:`${w}4018`,message:"Could not find context to retrieve navigation data.",level:_},INVALID_ROUTE_QUERY:{code:`${w}4019`,message:"Invalid query param in route definition.",level:_},MISSING_PAGE_BINDING:{code:`${w}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:_,address:"{0}"},INVALID_PAGE_BINDING:{code:`${w}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:_,address:"{0}"},INVALID_URI_SYNTAX:{code:`${w}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:_,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${w}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:_,stack:"{2}"},VIEW_MISSING:{code:`${w}4024`,message:'Expected a view with name "{0}" in the viewset',level:_},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${w}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:_,stack:"{3}"},NO_ROUTE_MATCH:{code:`${w}4026`,message:"A routing match cannot be found for: {0}",level:_},INVALID_ROUTE_HANDLER:{code:`${w}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:_},DESTINATION_NOT_FOUND:{code:`${w}4028`,message:"Route handler returned 404: Not Found",level:_},DESTINATION_ERROR:{code:`${w}4029`,message:"Route handler returned error status {0}: {1}",level:_,stack:"{2}"},NO_INIT_URL:{code:`${w}4030`,message:'Cannot initialize a server router without a "url"',level:_}},P=new WeakMap;function y(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 $=y(new N(void 0)),O=y(new N(void 0)),S=new N(void 0),A=class extends(y(S)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",s=t.viewset[i],r=s,o=r&&r.module||s;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=r.specifier?x(T.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[r.specifier,i,t.message,t.stack||""]):x(T.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else n=x(T.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(n)}}};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 L(e=""){return e=e||"",decodeURIComponent(e)}function D(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const U="undefined"!=typeof document,k=`universalcontainergetnavigationcontext${D()}`,F=s(O),V=U?s(A):void 0,G=s($);function W(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 j(){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,o=!0)=>{(e=>{i.push(e)})(r),e&&o&&r.next(e),t&&s(t);const n=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(n)}}}}const H=`universalcontainernavigationevent${D()}`,B=`universalcontainerparentevent${D()}`;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:s}=t.detail;this.config.handleNavigation(s,i)?this.root&&!e?this.root.processError(x(T.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=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},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(B,(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}};P.set(i.id,i)}(this.contextId,e),W(this.contextId,this.target,G,$),W(void 0,this.target,F,O),W(void 0,this.target,V,A),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)};A.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),U&&(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,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(x(T.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(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 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(H,{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 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}`,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[L(i)]=L(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 z extends X{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(q(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)}}r(z,{fields:["historyDisabled"]});let Y=!1;class J extends n{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 X(t,i,e):new z(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(),C(!Y||!!s.parent,T.MULTIPLE_ROOTS),Y=Y||!s.parent,r.id=s.contextId},disconnect:()=>{Y=Y&&!!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})}}J.renderMode="light",r(J,{publicProps:{router:{config:0},historyDisabled:{config:0}}});const Q=o(J,{tmpl:I,sel:"lwr-router-container",apiVersion:63});export{Q as default};
2
2
  //# sourceMappingURL=routerContainer.js.map
@@ -7,8 +7,12 @@ function validateProvider(obj) {
7
7
  * Manages context for various providers
8
8
  */
9
9
  export class ContextInfo {
10
+ infoMap = new WeakMap();
11
+ /**
12
+ * The default value to be returned in the absence of a defined context
13
+ */
14
+ defaultValue;
10
15
  constructor(defaultValue) {
11
- this.infoMap = new WeakMap();
12
16
  this.defaultValue = defaultValue;
13
17
  }
14
18
  /**
@@ -2,76 +2,75 @@ import { ContextInfo } from './contextInfo.js';
2
2
  export { ContextInfo };
3
3
  export { getNavigationHelm, registerNavigationHelm } from './navigationApiStore.js';
4
4
  export function generateContextualWireAdapter(contextInstance) {
5
- var _a;
6
- const Adapter = (_a = class Adapter {
7
- constructor(callback) {
8
- this._callback = callback;
5
+ const Adapter = class Adapter {
6
+ constructor(callback) {
7
+ this._callback = callback;
8
+ }
9
+ connect() {
10
+ // There is no 'connect' because context is provided via the update API.
11
+ }
12
+ disconnect() {
13
+ // no-op
14
+ }
15
+ _callback;
16
+ // The default update method services wires that emit context as TEmit when their value changes.
17
+ // Wires that need more complex logic or use another emit type should override this method.
18
+ update(config, context) {
19
+ if (context) {
20
+ this._callback(context);
9
21
  }
10
- connect() {
11
- // There is no 'connect' because context is provided via the update API.
12
- }
13
- disconnect() {
14
- // no-op
15
- }
16
- // The default update method services wires that emit context as TEmit when their value changes.
17
- // Wires that need more complex logic or use another emit type should override this method.
18
- update(config, context) {
19
- if (context) {
20
- this._callback(context);
21
- }
22
- }
23
- /**
24
- * Set the context value directly associated with the target as a context provider.
25
- *
26
- * @param {EventTarget} targetProvider
27
- * @param {ContextId} contextValue
28
- */
29
- static setContext(targetProvider, contextValue) {
30
- contextInstance.setContext(targetProvider, contextValue);
31
- }
32
- /**
33
- * Get the context value directly associated with the target as a context provider.
34
- *
35
- * @param {EventTarget} targetProvider
36
- */
37
- static getContext(targetProvider) {
38
- return contextInstance.getContext(targetProvider);
39
- }
40
- /**
41
- * Clear the context value and registered subscribers directly associated with the
42
- * target as a context provider.
43
- *
44
- * @param {EventTarget} targetProvider
45
- */
46
- static clearContext(targetProvider) {
47
- contextInstance.clearContext(targetProvider);
48
- }
49
- /**
50
- * Subscribe a consumer to the context value directly associated with the target as
51
- * a context provider. Calls to #set(targetProvider, contextValue) with the same
52
- * target will invoke the consumer.provide(contextValue) function.
53
- *
54
- * NOTE: Mutations to the contextValue directly do not result in calls to
55
- * consumer.provide(contextValue).
56
- *
57
- * @param {EventTarget} targetProvider
58
- * @param {ContextConsumer} consumer object with a provide(context) function property.
59
- */
60
- static subscribeContext(targetProvider, consumer) {
61
- contextInstance.subscribeContext(targetProvider, consumer);
62
- }
63
- /**
64
- * Unsubscribe a previously subscribed consumer from listening to changes on the
65
- * target
66
- * @param {EventTarget} targetProvider
67
- * @param {ContextConsumer} consumer
68
- */
69
- static unsubscribeContext(targetProvider, consumer) {
70
- contextInstance.unsubscribeContext(targetProvider, consumer);
71
- }
72
- },
73
- _a.contextSchema = { value: 'required' },
74
- _a);
22
+ }
23
+ /**
24
+ * Set the context value directly associated with the target as a context provider.
25
+ *
26
+ * @param {EventTarget} targetProvider
27
+ * @param {ContextId} contextValue
28
+ */
29
+ static setContext(targetProvider, contextValue) {
30
+ contextInstance.setContext(targetProvider, contextValue);
31
+ }
32
+ /**
33
+ * Get the context value directly associated with the target as a context provider.
34
+ *
35
+ * @param {EventTarget} targetProvider
36
+ */
37
+ static getContext(targetProvider) {
38
+ return contextInstance.getContext(targetProvider);
39
+ }
40
+ /**
41
+ * Clear the context value and registered subscribers directly associated with the
42
+ * target as a context provider.
43
+ *
44
+ * @param {EventTarget} targetProvider
45
+ */
46
+ static clearContext(targetProvider) {
47
+ contextInstance.clearContext(targetProvider);
48
+ }
49
+ /**
50
+ * Subscribe a consumer to the context value directly associated with the target as
51
+ * a context provider. Calls to #set(targetProvider, contextValue) with the same
52
+ * target will invoke the consumer.provide(contextValue) function.
53
+ *
54
+ * NOTE: Mutations to the contextValue directly do not result in calls to
55
+ * consumer.provide(contextValue).
56
+ *
57
+ * @param {EventTarget} targetProvider
58
+ * @param {ContextConsumer} consumer object with a provide(context) function property.
59
+ */
60
+ static subscribeContext(targetProvider, consumer) {
61
+ contextInstance.subscribeContext(targetProvider, consumer);
62
+ }
63
+ /**
64
+ * Unsubscribe a previously subscribed consumer from listening to changes on the
65
+ * target
66
+ * @param {EventTarget} targetProvider
67
+ * @param {ContextConsumer} consumer
68
+ */
69
+ static unsubscribeContext(targetProvider, consumer) {
70
+ contextInstance.unsubscribeContext(targetProvider, consumer);
71
+ }
72
+ static contextSchema = { value: 'required' };
73
+ };
75
74
  return Adapter;
76
75
  }
77
76
  //# sourceMappingURL=contextUtils.js.map
@@ -18,6 +18,19 @@ export const NAV_EVENT = `universalcontainernavigationevent${guid()}`;
18
18
  // Event fired to find nearest parent
19
19
  export const PARENT_EVENT = `universalcontainerparentevent${guid()}`;
20
20
  export class DomRouterImpl {
21
+ config;
22
+ target;
23
+ router;
24
+ pendingRoute = null;
25
+ committedRoute = null;
26
+ routeObservable;
27
+ eventId; // used for instrumentation
28
+ contextId = Object.freeze(() => undefined);
29
+ connected = false;
30
+ parent;
31
+ child;
32
+ preNavFilters = createFilterChain();
33
+ errorNavFilters = createFilterChain();
21
34
  /**
22
35
  * Create and configure the Router.
23
36
  *
@@ -26,54 +39,6 @@ export class DomRouterImpl {
26
39
  * @param {HTMLElement} target - DOM node to attach to
27
40
  */
28
41
  constructor(config, router, target) {
29
- this.pendingRoute = null;
30
- this.committedRoute = null;
31
- this.contextId = Object.freeze(() => undefined);
32
- this.connected = false;
33
- this.preNavFilters = createFilterChain();
34
- this.errorNavFilters = createFilterChain();
35
- /**
36
- * Inspect a navigation event bubbling up from a descendent component.
37
- * This node can choose to stop the event by returning false.
38
- * If propagation is not stopped, and this node is the root (no parent),
39
- * then begin the root -> leaf processing of this new route.
40
- * This will update the navigation event subscribers in each DomRouter, top down.
41
- *
42
- * @param {Event} event - With detail: { url, options }
43
- */
44
- this._handleNavigationEvent = (event) => {
45
- const navigationEvent = event;
46
- if (navigationEvent.detail && typeof navigationEvent.detail === 'object') {
47
- const { url, replace, address } = navigationEvent.detail;
48
- const continueNavigation = this.config.handleNavigation(address, replace);
49
- if (!continueNavigation) {
50
- navigationEvent.stopPropagation();
51
- }
52
- else {
53
- if (this.root && !url) {
54
- // handle navigation can avoid the error message if it indicates navigation
55
- // shouldn't continue, even if url is missing
56
- this.root.processError(generateMessageObject(messages.MISSING_URL, [JSON.stringify(address)]));
57
- }
58
- else if (!this.parent) {
59
- this.process(url, replace);
60
- }
61
- }
62
- }
63
- };
64
- /**
65
- * Be discovered as a parent for descendent components.
66
- * Stop immediate propagation because we only want 1 parent to be found.
67
- *
68
- * @param {Event} event - With detail: callback
69
- */
70
- this._handleParentEvent = (event) => {
71
- event.stopImmediatePropagation();
72
- const parentRouterEvent = event;
73
- if (parentRouterEvent && parentRouterEvent.detail && typeof parentRouterEvent.detail === 'function') {
74
- parentRouterEvent.detail(this);
75
- }
76
- };
77
42
  this.config = {
78
43
  handleNavigation: config.handleNavigation || (() => true),
79
44
  };
@@ -414,6 +379,48 @@ export class DomRouterImpl {
414
379
  },
415
380
  }, Boolean(replay));
416
381
  }
382
+ /**
383
+ * Inspect a navigation event bubbling up from a descendent component.
384
+ * This node can choose to stop the event by returning false.
385
+ * If propagation is not stopped, and this node is the root (no parent),
386
+ * then begin the root -> leaf processing of this new route.
387
+ * This will update the navigation event subscribers in each DomRouter, top down.
388
+ *
389
+ * @param {Event} event - With detail: { url, options }
390
+ */
391
+ _handleNavigationEvent = (event) => {
392
+ const navigationEvent = event;
393
+ if (navigationEvent.detail && typeof navigationEvent.detail === 'object') {
394
+ const { url, replace, address } = navigationEvent.detail;
395
+ const continueNavigation = this.config.handleNavigation(address, replace);
396
+ if (!continueNavigation) {
397
+ navigationEvent.stopPropagation();
398
+ }
399
+ else {
400
+ if (this.root && !url) {
401
+ // handle navigation can avoid the error message if it indicates navigation
402
+ // shouldn't continue, even if url is missing
403
+ this.root.processError(generateMessageObject(messages.MISSING_URL, [JSON.stringify(address)]));
404
+ }
405
+ else if (!this.parent) {
406
+ this.process(url, replace);
407
+ }
408
+ }
409
+ }
410
+ };
411
+ /**
412
+ * Be discovered as a parent for descendent components.
413
+ * Stop immediate propagation because we only want 1 parent to be found.
414
+ *
415
+ * @param {Event} event - With detail: callback
416
+ */
417
+ _handleParentEvent = (event) => {
418
+ event.stopImmediatePropagation();
419
+ const parentRouterEvent = event;
420
+ if (parentRouterEvent && parentRouterEvent.detail && typeof parentRouterEvent.detail === 'function') {
421
+ parentRouterEvent.detail(this);
422
+ }
423
+ };
417
424
  _sendEvent(name, payload) {
418
425
  hasDocument &&
419
426
  this.target.dispatchEvent(new CustomEvent(name, {
@@ -11,10 +11,7 @@ import { hasDocument } from 'lwr/routerUtils';
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
- constructor() {
15
- super(...arguments);
16
- this.historyDisabled = false;
17
- }
14
+ historyDisabled = false;
18
15
  /**
19
16
  * Override.
20
17
  * Initialize with the current route and listen to the popstate event for future changes.
@@ -7,14 +7,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { LightningElement, api, wire } from 'lwc';
8
8
  import { CurrentView } from 'lwr/navigation';
9
9
  export default class Outlet extends LightningElement {
10
- constructor() {
11
- super(...arguments);
12
- this.refocusOff = false;
13
- this.viewName = 'default';
14
- this.viewCtor = undefined;
15
- this.previousViewCtor = undefined;
16
- this.hasError = false;
17
- }
10
+ static renderMode = 'light';
11
+ refocusOff = false;
12
+ outletErrorCallback;
13
+ viewName = 'default';
14
+ viewCtor = undefined;
15
+ previousViewCtor = undefined;
16
+ hasError = false;
18
17
  // Get a reference to the current view
19
18
  setView(currentView) {
20
19
  this.hasError = false;
@@ -53,7 +52,6 @@ export default class Outlet extends LightningElement {
53
52
  }
54
53
  }
55
54
  }
56
- Outlet.renderMode = 'light';
57
55
  __decorate([
58
56
  api
59
57
  ], Outlet.prototype, "refocusOff", void 0);
@@ -8,14 +8,20 @@ import { freeze, getUrlFromPageReference, getPageReferenceFromUrl, matchRouteByU
8
8
  import { generateMessage, messages } from 'lwr/routerErrors';
9
9
  import { createObservable } from 'lwr/observable';
10
10
  class RouterImpl {
11
+ config;
12
+ deprecatedConfig = {};
13
+ compiledRoutes;
14
+ // The in-flight route state to be committed once the view mapping is handled
15
+ pendingRoute;
16
+ routeObservable;
17
+ routeHandler;
18
+ routeHandlerId = 0;
11
19
  /**
12
20
  * Create and configure the Router.
13
21
  *
14
22
  * @param {object} config - The router config object, all properties are optional
15
23
  */
16
24
  constructor(config) {
17
- this.deprecatedConfig = {};
18
- this.routeHandlerId = 0;
19
25
  this.compiledRoutes = [];
20
26
  this.routeObservable = createObservable();
21
27
  this.config = {
@@ -2,24 +2,10 @@ import { PARENT_EVENT } from 'lwr/domRouter';
2
2
  // Bridge navigation events, without access to a <lwr-router-container> or NavigationContext
3
3
  // Used to allow a bridge between a LWR Router and vanilla HTML/JS (eg: in LWR Everywhere)
4
4
  class DomRouterBridge {
5
+ config;
6
+ target;
7
+ bridgedRouter;
5
8
  constructor(config = {}, target = window) {
6
- // Routers send out the PARENT_EVENT to build a router hierarchy
7
- // Listen for this event to find the topmost router located beneath the bridge in the DOM
8
- // NOTE: because of the restrictions on "lwr/router" hierachy, this is only called 0 or 1 time(s)
9
- // - only ONE root router is allowed in a document
10
- // - sibling routers are NOT allowed
11
- this.handleParentEvent = (event) => {
12
- const parentEvent = event;
13
- if (parentEvent && parentEvent.detail && typeof parentEvent.detail === 'function') {
14
- // event.detail() will call this.addChild()
15
- parentEvent.detail(this);
16
- if (this.bridgedRouter) {
17
- // Ensure the bridge does not become part of the router hierarchy
18
- this.bridgedRouter.parent = undefined;
19
- this.target.removeEventListener(PARENT_EVENT, this.handleParentEvent);
20
- }
21
- }
22
- };
23
9
  // Provide fallbacks for missing config values
24
10
  this.config = {
25
11
  historyDisabled: !!config.historyDisabled,
@@ -40,6 +26,23 @@ class DomRouterBridge {
40
26
  this.target = target;
41
27
  this.target.addEventListener(PARENT_EVENT, this.handleParentEvent);
42
28
  }
29
+ // Routers send out the PARENT_EVENT to build a router hierarchy
30
+ // Listen for this event to find the topmost router located beneath the bridge in the DOM
31
+ // NOTE: because of the restrictions on "lwr/router" hierachy, this is only called 0 or 1 time(s)
32
+ // - only ONE root router is allowed in a document
33
+ // - sibling routers are NOT allowed
34
+ handleParentEvent = (event) => {
35
+ const parentEvent = event;
36
+ if (parentEvent && parentEvent.detail && typeof parentEvent.detail === 'function') {
37
+ // event.detail() will call this.addChild()
38
+ parentEvent.detail(this);
39
+ if (this.bridgedRouter) {
40
+ // Ensure the bridge does not become part of the router hierarchy
41
+ this.bridgedRouter.parent = undefined;
42
+ this.target.removeEventListener(PARENT_EVENT, this.handleParentEvent);
43
+ }
44
+ }
45
+ };
43
46
  // Save an observed router and subscribe to its navigation and error updates
44
47
  async addChild(child) {
45
48
  this.bridgedRouter = child;
@@ -17,9 +17,14 @@ import { hasDocument } from 'lwr/routerUtils';
17
17
  * Provides a LWC router component. These can be nested and all report to the root router.
18
18
  */
19
19
  export default class RouterContainer extends LightningElement {
20
+ static renderMode = 'light';
21
+ // Instance of the Router class for this LWC.
22
+ routerApi;
23
+ router;
24
+ historyDisabled = false;
25
+ currentTitle;
20
26
  constructor() {
21
27
  super();
22
- this.historyDisabled = false;
23
28
  this.currentTitle = hasDocument ? document.title : '';
24
29
  }
25
30
  /**
@@ -106,7 +111,6 @@ export default class RouterContainer extends LightningElement {
106
111
  });
107
112
  }
108
113
  }
109
- RouterContainer.renderMode = 'light';
110
114
  __decorate([
111
115
  api
112
116
  ], RouterContainer.prototype, "router", void 0);
@@ -7,8 +7,14 @@ import { createRouter } from 'lwr/router';
7
7
  import { generateMessageObject, messages } from 'lwr/routerErrors';
8
8
  import { hasDocument } from 'lwr/routerUtils';
9
9
  export class ServerRouter {
10
+ router;
11
+ target;
12
+ contextId = Object.freeze(() => undefined);
13
+ handleNavHook;
14
+ preNavHook;
15
+ errorNavHook;
16
+ currentRoute;
10
17
  constructor(config, router, target) {
11
- this.contextId = Object.freeze(() => undefined);
12
18
  this.router = router;
13
19
  this.target = target;
14
20
  this.handleNavHook = config.handleNavigation;
@@ -3,9 +3,15 @@ import { generateModule, getRouterConfigPath, parseSpecifier, setUpWatcher } fro
3
3
  import { deleteRouterConfigJsonCacheEntry, getClientRoutes } from '../index.js';
4
4
  const DEFAULT_DIR = '$rootDir/src/routes';
5
5
  export default class RouterModuleProvider {
6
+ name = 'router-module-provider';
7
+ version;
8
+ routesDir;
9
+ appBasePath;
10
+ i18n;
11
+ // Watch the Router Config files and recompile the modules on change
12
+ routerWatcher;
13
+ watchedFileSet = new Set(); // <config path, module id>
6
14
  constructor({ routesDir = DEFAULT_DIR }, context) {
7
- this.name = 'router-module-provider';
8
- this.watchedFileSet = new Set(); // <config path, module id>
9
15
  const { config: { rootDir, contentDir, i18n, layoutsDir }, runtimeEnvironment: { lwrVersion, watchFiles }, watcherFactory, } = context;
10
16
  this.version = lwrVersion;
11
17
  this.i18n = i18n;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.17.2-alpha.8",
8
+ "version": "0.17.2",
9
9
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
10
10
  "repository": {
11
11
  "type": "git",
@@ -53,21 +53,21 @@
53
53
  "test:server": "jest --config ./jest.server.config.cjs"
54
54
  },
55
55
  "dependencies": {
56
- "@lwrjs/client-modules": "0.17.2-alpha.8",
57
- "@lwrjs/diagnostics": "0.17.2-alpha.8",
58
- "@lwrjs/shared-utils": "0.17.2-alpha.8",
56
+ "@lwrjs/client-modules": "0.17.2",
57
+ "@lwrjs/diagnostics": "0.17.2",
58
+ "@lwrjs/shared-utils": "0.17.2",
59
59
  "ajv": "6.12.6"
60
60
  },
61
61
  "devDependencies": {
62
- "@lwc/jest-preset": "^16.1.0",
63
- "@lwrjs/fs-watch": "0.17.2-alpha.8",
62
+ "@lwc/jest-preset": "^18.1.2",
63
+ "@lwrjs/fs-watch": "0.17.2",
64
64
  "@rollup/plugin-typescript": "^11.1.6",
65
- "jest": "^26.6.3",
65
+ "jest": "29.7.0",
66
66
  "memfs": "^4.13.0",
67
67
  "rollup": "^2.79.2",
68
- "ts-jest": "^26.5.6",
68
+ "ts-jest": "^29.2.6",
69
69
  "typescript": "^4.9.5",
70
- "utam": "3.2.1"
70
+ "utam": "3.2.2"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "lwc": ">= 2.x"
@@ -94,10 +94,10 @@
94
94
  ]
95
95
  },
96
96
  "engines": {
97
- "node": ">=18.0.0"
97
+ "node": ">=20.0.0"
98
98
  },
99
99
  "volta": {
100
100
  "extends": "../../../package.json"
101
101
  },
102
- "gitHead": "ee1182e7d876cf92e579ee88c48b25047486b4f8"
102
+ "gitHead": "d64d8888a28da36c05e3d8d9baf51416551863a9"
103
103
  }