@lwrjs/router 0.8.0-alpha.9 → 0.9.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/build/bundle/prod/lwr/navigation/navigation.js +1 -1
  2. package/build/bundle/prod/lwr/routerContainer/routerContainer.js +1 -1
  3. package/build/cjs/modules/lwr/contextProvider/contextProvider.cjs +11 -8
  4. package/build/cjs/modules/lwr/contextUtils/contextInfo.cjs +5 -1
  5. package/build/cjs/modules/lwr/domRouter/domRouter.cjs +11 -9
  6. package/build/cjs/modules/lwr/domRouterUtils/uriUtils.cjs +0 -5
  7. package/build/cjs/modules/lwr/historyRouter/historyRouter.cjs +4 -3
  8. package/build/cjs/modules/lwr/routerContainer/routerContainer.cjs +2 -1
  9. package/build/cjs/modules/lwr/routerUtils/domUtils.cjs +13 -0
  10. package/build/cjs/modules/lwr/routerUtils/routerUtils.cjs +2 -0
  11. package/build/cjs/services/index.cjs +10 -0
  12. package/build/cjs/services/module-provider/index.cjs +3 -11
  13. package/build/cjs/services/module-provider/utils.cjs +1 -1
  14. package/build/modules/lwr/contextProvider/contextProvider.d.ts +4 -4
  15. package/build/modules/lwr/contextProvider/contextProvider.js +14 -10
  16. package/build/modules/lwr/contextUtils/contextInfo.js +7 -1
  17. package/build/modules/lwr/domRouter/domRouter.js +13 -10
  18. package/build/modules/lwr/domRouterUtils/uriUtils.d.ts +0 -8
  19. package/build/modules/lwr/domRouterUtils/uriUtils.js +0 -13
  20. package/build/modules/lwr/historyRouter/historyRouter.js +4 -3
  21. package/build/modules/lwr/routerContainer/routerContainer.js +2 -1
  22. package/build/modules/lwr/routerUtils/domUtils.d.ts +2 -0
  23. package/build/modules/lwr/routerUtils/domUtils.js +2 -0
  24. package/build/modules/lwr/routerUtils/routerUtils.d.ts +1 -0
  25. package/build/modules/lwr/routerUtils/routerUtils.js +2 -1
  26. package/build/modules/lwr/routerUtils/types.d.ts +0 -1
  27. package/build/services/index.d.ts +1 -0
  28. package/build/services/index.js +12 -0
  29. package/build/services/module-provider/index.d.ts +0 -1
  30. package/build/services/module-provider/index.js +7 -18
  31. package/build/services/module-provider/utils.js +2 -2
  32. package/package.json +5 -5
@@ -1 +1 @@
1
- import{registerDecorators as e}from"lwc";function t(e){if(null==e)throw new TypeError("Provider must be defined.")}class n{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,n){t(e);const o=this.getInfo(e);o.contextValue=n,o.consumers.forEach((e=>e.provide(n)))}getContext(e){t(e);const{contextValue:n}=this.getInfo(e);return void 0!==n?n:this.defaultValue}clearContext(e){t(e),this.infoMap.delete(e)}subscribeContext(e,n){t(e);const{consumers:o,contextValue:r}=this.getInfo(e);o.has(n)||(o.add(n),n.provide(r))}unsubscribeContext(e,n){t(e),this.getInfo(e).consumers.delete(n)}}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}e(n,{fields:["infoMap"]});const i=1;function s(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}function c(e,t){return`${e.code}: ${s(e.message,t)}`}function l(e,t){const n=r(r({},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 u={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:i},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:i},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:i},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:i},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:i},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:i,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:i,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:i},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:i},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:i},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:i},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:i},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:i},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:i},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:i,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:i},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:i,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:i},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:i}},d=new WeakMap;function I(e){const t=d.get(e);if(!t||!t.value)throw new Error(c(u.MISSING_CONTEXT));return t.value}function v(e,t){const n={id:e,value:t,update:e=>{n.value=e}};return d.set(n.id,n),n}function g(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 f=g(new n(void 0)),m=g(new n(void 0)),p=new n(void 0),h=class extends(g(p)){async update(e,t){if(t){const n=e&&e.viewName?e.viewName:"default",o=t.viewset[n],r=o,a=r&&r.module||o;let i;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;i=r.specifier?l(u.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[r.specifier,n,t.message,t.stack||""]):l(u.VIEW_IMPORT_FAILED,[n,t.message,t.stack||""])}else i=l(u.VIEW_MISSING,[n]);t.onComplete&&t.onComplete(i)}}};function b(e,t,n){I(e).navigate(t,n)}function E(e,t){return I(e).generateUrl(t)}const _=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,R=Symbol("Navigate"),w=Symbol("GenerateUrl"),L=Symbol("NavContext"),N=Symbol("NavContext");function C(e){!function(e,t,n){if(!e)throw new Error(c(t,n))}("function"==typeof e.prototype.dispatchEvent,u.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[N](){if(!this[L]&&(this.dispatchEvent(new CustomEvent(_,{bubbles:!0,composed:!0,detail:{callback:e=>{this[L]=e}}})),!this[L]))throw new Error(c(u.MISSING_CONTEXT))}[R](e,t){this[N](),b(this[L],e,t)}async[w](e){return this[N](),E(this[L],e)}}}C.Navigate=R,C.GenerateUrl=w,C.NavContext=L;export{n as ContextInfo,m as CurrentPageReference,h as CurrentView,f as NavigationContext,C as NavigationMixin,g as generateContextualWireAdapter,E as generateUrl,I as getNavigationHelm,b as navigate,v as registerNavigationHelm};
1
+ import{registerDecorators as e}from"lwc";function t(e){if(null==e)throw new TypeError("Provider must be defined.")}class n{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,n){t(e);const o=n,r=this.getInfo(e);r.contextValue=n,r.consumers.forEach((e=>e.provide(o))),0===r.consumers.size&&o?.onComplete&&o.onComplete()}getContext(e){t(e);const{contextValue:n}=this.getInfo(e);return void 0!==n?n:this.defaultValue}clearContext(e){t(e),this.infoMap.delete(e)}subscribeContext(e,n){t(e);const{consumers:o,contextValue:r}=this.getInfo(e);o.has(n)||(o.add(n),n.provide(r))}unsubscribeContext(e,n){t(e),this.getInfo(e).consumers.delete(n)}}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}e(n,{fields:["infoMap"]});const s=1;function i(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}function c(e,t){return`${e.code}: ${i(e.message,t)}`}function l(e,t){const n=r(r({},e),{},{message:i(e.message,t)});return e.address&&(n.address=i(e.address,t)),e.stack&&(n.stack=i(e.stack,t)),n}const u={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:s},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:s},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:s},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:s},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:s},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:s,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:s,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:s},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:s},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:s},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:s},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:s},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:s},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:s},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:s,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:s},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:s,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:s},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:s}},d=new WeakMap;function I(e){const t=d.get(e);if(!t||!t.value)throw new Error(c(u.MISSING_CONTEXT));return t.value}function v(e,t){const n={id:e,value:t,update:e=>{n.value=e}};return d.set(n.id,n),n}function g(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 f=g(new n(void 0)),m=g(new n(void 0)),p=new n(void 0),h=class extends(g(p)){async update(e,t){if(t){const n=e&&e.viewName?e.viewName:"default",o=t.viewset[n],r=o,a=r&&r.module||o;let s;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;s=r.specifier?l(u.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[r.specifier,n,t.message,t.stack||""]):l(u.VIEW_IMPORT_FAILED,[n,t.message,t.stack||""])}else s=l(u.VIEW_MISSING,[n]);t.onComplete&&t.onComplete(s)}}};function b(e,t,n){I(e).navigate(t,n)}function E(e,t){return I(e).generateUrl(t)}const _=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,R=Symbol("Navigate"),w=Symbol("GenerateUrl"),L=Symbol("NavContext"),N=Symbol("NavContext");function C(e){!function(e,t,n){if(!e)throw new Error(c(t,n))}("function"==typeof e.prototype.dispatchEvent,u.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[N](){if(!this[L]&&(this.dispatchEvent(new CustomEvent(_,{bubbles:!0,composed:!0,detail:{callback:e=>{this[L]=e}}})),!this[L]))throw new Error(c(u.MISSING_CONTEXT))}[R](e,t){this[N](),b(this[L],e,t)}async[w](e){return this[N](),E(this[L],e)}}}C.Navigate=R,C.GenerateUrl=w,C.NavContext=L;export{n as ContextInfo,m as CurrentPageReference,h as CurrentView,f as NavigationContext,C as NavigationMixin,g as generateContextualWireAdapter,E as generateUrl,I as getNavigationHelm,b as navigate,v as registerNavigationHelm};
@@ -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={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 f=e(g);function m(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){m(e);const r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(t)))}getContext(e){m(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){m(e),this.infoMap.delete(e)}subscribeContext(e,t){m(e);const{consumers:r,contextValue:i}=this.getInfo(e);r.has(t)||(r.add(t),t.provide(i))}unsubscribeContext(e,t){m(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 y(e,t,r){if(!e)throw new Error(function(e,t){return`${e.code}: ${N(e.message,t)}`}(t,r))}const P={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}},O=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?_(P.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[n.specifier,r,t.message,t.stack||""]):_(P.VIEW_IMPORT_FAILED,[r,t.message,t.stack||""])}else s=_(P.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 M(e=""){return e=e||"",decodeURIComponent(e)}function A(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const U=`universalcontainergetnavigationcontext${A()}`,W=i(C),j=i(D),k=i(L);function F(e,t,r,i){i.setContext(t,e),r(t,{consumerConnectedCallback:i.subscribeContext.bind(i,t),consumerDisconnectedCallback:i.unsubscribeContext.bind(i,t)})}function V(){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 G(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 $(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?G(Object(r),!0).forEach((function(t){H(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):G(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function H(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const B=`universalcontainernavigationevent${A()}`,X=`universalcontainerparentevent${A()}`;class q{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(_(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=V()}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||$($({},e),{},{url:t}),this.committedRoute=$($({},this.pendingRoute),e),C.setContext(this.target,e.route.pageReference),this.routeObservable.next($($({},this.committedRoute),{},{viewset:e.viewset})),d({id:a,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(X,(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}};O.set(r.id,r)}(this.contextId,e),F(this.contextId,this.target,k,L),F(void 0,this.target,W,C),F(void 0,this.target,j,D),this.router.subscribe((e=>{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),this.target.addEventListener(B,this._handleNavigationEvent),this.target.addEventListener(X,this._handleParentEvent),this.target.addEventListener(U,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)})),this.connected=!0}disconnect(){this.target.removeEventListener(B,this._handleNavigationEvent),this.target.removeEventListener(X,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(),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(_(P.MISSING_ROUTE,[e]));this.pendingRoute=$({url:e},r);return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(_(P.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(B,{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){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[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,"")}r(q,{fields:["pendingRoute","committedRoute","contextId","connected","preNavFilters","errorNavFilters","_handleNavigationEvent","_handleParentEvent"]});class z extends q{constructor(...e){super(...e),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){this.parent||this.catchBrowserUpdate(Y(document.location.href))}disconnect(){super.disconnect(),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(z,{fields:["historyDisabled"]});let J=!1;class Q extends o{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=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 q(t,r,e):new z(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(!J||!!i.parent,P.MULTIPLE_ROOTS),J=J||!i.parent,n.id=i.contextId},disconnect:()=>{J=J&&!!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").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(Q,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var K=n(Q,{tmpl:f});export default K;
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={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 y(e,t,r){if(!e)throw new Error(function(e,t){return`${e.code}: ${N(e.message,t)}`}(t,r))}const P={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}},O=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?_(P.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[n.specifier,r,t.message,t.stack||""]):_(P.VIEW_IMPORT_FAILED,[r,t.message,t.stack||""])}else s=_(P.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 M(e=""){return e=e||"",decodeURIComponent(e)}function A(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const U="undefined"!=typeof document,W=`universalcontainergetnavigationcontext${A()}`,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${A()}`,q=`universalcontainerparentevent${A()}`;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(_(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;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}};O.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=>{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((()=>{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(),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(_(P.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(_(P.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[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,"")}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(),y(!Q||!!i.parent,P.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").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;
@@ -30,14 +30,17 @@ __export(exports, {
30
30
  provideContext: () => provideContext
31
31
  });
32
32
  var import_lwc = __toModule(require("lwc"));
33
+ var import_routerUtils = __toModule(require("lwr/routerUtils"));
33
34
  var import_navigation = __toModule(require("lwr/navigation"));
34
- var currentPageReferenceContextualizer = (0, import_lwc.createContextProvider)(import_navigation.CurrentPageReference);
35
- var currentViewContextualizer = (0, import_lwc.createContextProvider)(import_navigation.CurrentView);
36
- var navigationContextContextualizer = (0, import_lwc.createContextProvider)(import_navigation.NavigationContext);
35
+ var currentPageReferenceContextualizer = import_routerUtils.hasDocument ? (0, import_lwc.createContextProvider)(import_navigation.CurrentPageReference) : void 0;
36
+ var currentViewContextualizer = import_routerUtils.hasDocument ? (0, import_lwc.createContextProvider)(import_navigation.CurrentView) : void 0;
37
+ var navigationContextContextualizer = import_routerUtils.hasDocument ? (0, import_lwc.createContextProvider)(import_navigation.NavigationContext) : void 0;
37
38
  function provideContext(contextValue, providerNode, contextualizer, contextualAdapter) {
38
- contextualAdapter.setContext(providerNode, contextValue);
39
- contextualizer(providerNode, {
40
- consumerConnectedCallback: contextualAdapter.subscribeContext.bind(contextualAdapter, providerNode),
41
- consumerDisconnectedCallback: contextualAdapter.unsubscribeContext.bind(contextualAdapter, providerNode)
42
- });
39
+ if (contextualizer && contextualAdapter) {
40
+ contextualAdapter.setContext(providerNode, contextValue);
41
+ contextualizer(providerNode, {
42
+ consumerConnectedCallback: contextualAdapter.subscribeContext.bind(contextualAdapter, providerNode),
43
+ consumerDisconnectedCallback: contextualAdapter.unsubscribeContext.bind(contextualAdapter, providerNode)
44
+ });
45
+ }
43
46
  }
@@ -30,9 +30,13 @@ var ContextInfo = class {
30
30
  }
31
31
  setContext(targetProvider, contextValue) {
32
32
  validateProvider(targetProvider);
33
+ const value = contextValue;
33
34
  const info = this.getInfo(targetProvider);
34
35
  info.contextValue = contextValue;
35
- info.consumers.forEach((consumer) => consumer.provide(contextValue));
36
+ info.consumers.forEach((consumer) => consumer.provide(value));
37
+ if (info.consumers.size === 0 && value?.onComplete) {
38
+ value.onComplete();
39
+ }
36
40
  }
37
41
  getContext(targetProvider) {
38
42
  validateProvider(targetProvider);
@@ -137,14 +137,16 @@ var DomRouterImpl = class {
137
137
  this.updateWires(result, url);
138
138
  }
139
139
  }, true);
140
- this.target.addEventListener(NAV_EVENT, this._handleNavigationEvent);
141
- this.target.addEventListener(PARENT_EVENT, this._handleParentEvent);
142
- this.target.addEventListener(import_navigationMixinHacks.CONTEXT_ID_BACKDOOR, (event) => {
143
- const navCtxEvent = event;
144
- if (navCtxEvent.detail.callback) {
145
- navCtxEvent.detail.callback(this.contextId);
146
- }
147
- });
140
+ if (import_routerUtils.hasDocument) {
141
+ this.target.addEventListener(NAV_EVENT, this._handleNavigationEvent);
142
+ this.target.addEventListener(PARENT_EVENT, this._handleParentEvent);
143
+ this.target.addEventListener(import_navigationMixinHacks.CONTEXT_ID_BACKDOOR, (event) => {
144
+ const navCtxEvent = event;
145
+ if (navCtxEvent.detail.callback) {
146
+ navCtxEvent.detail.callback(this.contextId);
147
+ }
148
+ });
149
+ }
148
150
  this.connected = true;
149
151
  }
150
152
  disconnect() {
@@ -252,7 +254,7 @@ var DomRouterImpl = class {
252
254
  }, Boolean(replay));
253
255
  }
254
256
  _sendEvent(name, payload) {
255
- this.target.dispatchEvent(new CustomEvent(name, {
257
+ import_routerUtils.hasDocument && this.target.dispatchEvent(new CustomEvent(name, {
256
258
  bubbles: true,
257
259
  composed: true,
258
260
  detail: payload
@@ -24,7 +24,6 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/router/src/modules/lwr/domRouterUtils/uriUtils.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
- getPathFromAnyUrl: () => getPathFromAnyUrl,
28
27
  getRelativeUrl: () => getRelativeUrl,
29
28
  getUrlObject: () => getUrlObject
30
29
  });
@@ -60,7 +59,3 @@ function getRelativeUrl(url) {
60
59
  const origin = urlObj.origin.replace(/:\d+/, "");
61
60
  return href.replace(origin, "");
62
61
  }
63
- function getPathFromAnyUrl(url) {
64
- const path = getUrlObject(url).pathname;
65
- return path === "/" ? "/" : path.replace(/\/$/, "");
66
- }
@@ -29,6 +29,7 @@ __export(exports, {
29
29
  });
30
30
  var import_domRouter = __toModule(require("lwr/domRouter"));
31
31
  var import_domRouterUtils = __toModule(require("lwr/domRouterUtils"));
32
+ var import_routerUtils = __toModule(require("lwr/routerUtils"));
32
33
  var HistoryRouter = class extends import_domRouter.DomRouterImpl {
33
34
  constructor() {
34
35
  super(...arguments);
@@ -37,18 +38,18 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
37
38
  connect() {
38
39
  super.connect();
39
40
  if (!this.historyDisabled) {
40
- window.addEventListener("popstate", this.onpopstate.bind(this));
41
+ import_routerUtils.hasDocument && window.addEventListener("popstate", this.onpopstate.bind(this));
41
42
  this.onpopstate();
42
43
  }
43
44
  }
44
45
  onpopstate() {
45
- if (!this.parent) {
46
+ if (!this.parent && import_routerUtils.hasDocument) {
46
47
  this.catchBrowserUpdate((0, import_domRouterUtils.getRelativeUrl)(document.location.href));
47
48
  }
48
49
  }
49
50
  disconnect() {
50
51
  super.disconnect();
51
- window.removeEventListener("popstate", this.onpopstate);
52
+ import_routerUtils.hasDocument && window.removeEventListener("popstate", this.onpopstate);
52
53
  }
53
54
  async process(url, shouldReplace, updateHistory = true) {
54
55
  const canContinue = await super.process(url);
@@ -37,11 +37,12 @@ __export(exports, {
37
37
  });
38
38
  var import_lwc = __toModule(require("lwc"));
39
39
  var import_utils = __toModule(require("./utils"));
40
+ var import_routerUtils = __toModule(require("lwr/routerUtils"));
40
41
  var RouterContainer = class extends import_lwc.LightningElement {
41
42
  constructor() {
42
43
  super();
43
44
  this.historyDisabled = false;
44
- this.currentTitle = document.title;
45
+ this.currentTitle = import_routerUtils.hasDocument ? document.title : "";
45
46
  }
46
47
  connectedCallback() {
47
48
  const config = {
@@ -0,0 +1,13 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {get: all[name], enumerable: true});
6
+ };
7
+
8
+ // packages/@lwrjs/router/src/modules/lwr/routerUtils/domUtils.ts
9
+ __markAsModule(exports);
10
+ __export(exports, {
11
+ hasDocument: () => hasDocument
12
+ });
13
+ var hasDocument = typeof document !== "undefined";
@@ -36,6 +36,7 @@ __export(exports, {
36
36
  getUrlFromPageReference: () => import_routeUtils.getUrlFromPageReference,
37
37
  getUrlFromPageReferenceAndRouteDef: () => import_routeUtils.getUrlFromPageReferenceAndRouteDef,
38
38
  guid: () => import_typeUtils.guid,
39
+ hasDocument: () => import_domUtils.hasDocument,
39
40
  isObject: () => import_typeUtils.isObject,
40
41
  isValidRoute: () => import_typeUtils.isValidRoute,
41
42
  matchRouteByUrl: () => import_routeUtils.matchRouteByUrl,
@@ -49,6 +50,7 @@ var import_typeUtils = __toModule(require("./typeUtils"));
49
50
  var import_parseUtils = __toModule(require("./parseUtils"));
50
51
  var import_pathToRegexp = __toModule(require("./pathToRegexp"));
51
52
  var import_uriUtils = __toModule(require("./uriUtils"));
53
+ var import_domUtils = __toModule(require("./domUtils"));
52
54
  var pathToRegexp = {
53
55
  pathToRegexp: import_pathToRegexp.pathToRegexp,
54
56
  compile: import_pathToRegexp.compile
@@ -25,6 +25,7 @@ var __toModule = (module2) => {
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  DEFAULT_SCHEMA: () => DEFAULT_SCHEMA,
28
+ deleteRouterConfigJsonCacheEntry: () => deleteRouterConfigJsonCacheEntry,
28
29
  getClientRoutes: () => getClientRoutes
29
30
  });
30
31
  var import_ajv = __toModule(require("ajv"));
@@ -90,8 +91,16 @@ var RouteDefinitionSchema = {
90
91
  };
91
92
  var ajv = new import_ajv.default();
92
93
  var validate = ajv.compile(RouteDefinitionSchema);
94
+ var routerConfigJsonCache = new Map();
95
+ function deleteRouterConfigJsonCacheEntry(path) {
96
+ routerConfigJsonCache.delete(path);
97
+ }
93
98
  function getClientRoutes(path) {
99
+ if (routerConfigJsonCache.has(path)) {
100
+ return routerConfigJsonCache.get(path);
101
+ }
94
102
  if (!(0, import_fs.existsSync)(path)) {
103
+ console.warn("@lwrjs/router services cannot find client route JSON at:", path);
95
104
  return void 0;
96
105
  }
97
106
  try {
@@ -112,6 +121,7 @@ function getClientRoutes(path) {
112
121
  throw new Error('A route definition must contain either "handler" or "component"');
113
122
  }
114
123
  });
124
+ routerConfigJsonCache.set(path, json);
115
125
  return json;
116
126
  } catch (e) {
117
127
  throw (0, import_diagnostics.createSingleDiagnosticError)({
@@ -34,7 +34,6 @@ var RouterModuleProvider = class {
34
34
  constructor({routesDir = DEFAULT_DIR}, context) {
35
35
  this.name = "router-module-provider";
36
36
  this.watchedFileMap = new Map();
37
- this.routerConfigJsonCache = new Map();
38
37
  this.routerModuleCache = new Map();
39
38
  const {
40
39
  appEmitter,
@@ -56,7 +55,7 @@ var RouterModuleProvider = class {
56
55
  if (!moduleId) {
57
56
  throw new Error("We are observing an unprocessed Router Config file, this should not happen...");
58
57
  }
59
- this.routerConfigJsonCache.delete(configPath);
58
+ (0, import__.deleteRouterConfigJsonCacheEntry)(configPath);
60
59
  this.routerModuleCache.delete(configPath);
61
60
  if (!deleted) {
62
61
  const recompiledModule = await this.getModule(moduleId);
@@ -78,15 +77,8 @@ var RouterModuleProvider = class {
78
77
  let config;
79
78
  const routerId = (0, import_utils.parseSpecifier)(specifier);
80
79
  if (routerId) {
81
- const cacheKey = (0, import_utils.getRouterConfigPath)(this.routesDir, specifier);
82
- if (this.routerConfigJsonCache.has(cacheKey)) {
83
- config = this.routerConfigJsonCache.get(cacheKey);
84
- } else {
85
- config = (0, import__.getClientRoutes)(cacheKey);
86
- if (config) {
87
- this.routerConfigJsonCache.set(cacheKey, config);
88
- }
89
- }
80
+ const configPath = (0, import_utils.getRouterConfigPath)(this.routesDir, specifier);
81
+ config = (0, import__.getClientRoutes)(configPath);
90
82
  }
91
83
  return config;
92
84
  }
@@ -43,7 +43,7 @@ function setUpWatcher(onModuleChange) {
43
43
  const watcher = (0, import_shared_utils.createFileWatcher)();
44
44
  watcher.on("change", (0, import_shared_utils.debounce)((file) => onModuleChange(file), 500));
45
45
  watcher.on("unlink", (0, import_shared_utils.debounce)((file) => onModuleChange(file, true), 500));
46
- watcher.on("add", (file) => console.log(`Watching Router Config file at "${file}"`));
46
+ watcher.on("add", (file) => import_shared_utils.logger.info(`Watching Router Config file at "${file}"`));
47
47
  return watcher;
48
48
  }
49
49
  function getHandlerClassName(specifier) {
@@ -1,8 +1,8 @@
1
1
  import { Contextualizer } from 'lwc';
2
2
  import type { ContextualWireAdapter } from 'lwr/contextUtils';
3
- export declare const currentPageReferenceContextualizer: Contextualizer;
4
- export declare const currentViewContextualizer: Contextualizer;
5
- export declare const navigationContextContextualizer: Contextualizer;
3
+ export declare const currentPageReferenceContextualizer: Contextualizer | undefined;
4
+ export declare const currentViewContextualizer: Contextualizer | undefined;
5
+ export declare const navigationContextContextualizer: Contextualizer | undefined;
6
6
  /**
7
7
  *
8
8
  * @param {TContext} contextValue - Context API object
@@ -10,5 +10,5 @@ export declare const navigationContextContextualizer: Contextualizer;
10
10
  * @param {Contextualizer} contextualizer - Function for providing this context to subtree nodes wired to a specific adapter
11
11
  * @param {ContextualWireAdapter<TContext, TEmit, TConfig>} contextualAdapter - Contextual wire adapter capable of subscribing to context changes
12
12
  */
13
- export declare function provideContext<TContext, TEmit, TConfig>(contextValue: TContext, providerNode: EventTarget, contextualizer: Contextualizer, contextualAdapter: ContextualWireAdapter<TContext, TEmit, TConfig>): void;
13
+ export declare function provideContext<TContext, TEmit, TConfig>(contextValue: TContext, providerNode: EventTarget, contextualizer?: Contextualizer, contextualAdapter?: ContextualWireAdapter<TContext, TEmit, TConfig>): void;
14
14
  //# sourceMappingURL=contextProvider.d.ts.map
@@ -1,8 +1,10 @@
1
1
  import { createContextProvider } from 'lwc';
2
+ import { hasDocument } from 'lwr/routerUtils';
2
3
  import { CurrentPageReference, CurrentView, NavigationContext } from 'lwr/navigation';
3
- export const currentPageReferenceContextualizer = createContextProvider(CurrentPageReference);
4
- export const currentViewContextualizer = createContextProvider(CurrentView);
5
- export const navigationContextContextualizer = createContextProvider(NavigationContext);
4
+ // Creating a context with LWC requires eventing APIs, which are not available from "@lwc/engine-server"
5
+ export const currentPageReferenceContextualizer = hasDocument ? createContextProvider(CurrentPageReference) : undefined;
6
+ export const currentViewContextualizer = hasDocument ? createContextProvider(CurrentView) : undefined;
7
+ export const navigationContextContextualizer = hasDocument ? createContextProvider(NavigationContext) : undefined;
6
8
  /**
7
9
  *
8
10
  * @param {TContext} contextValue - Context API object
@@ -12,11 +14,13 @@ export const navigationContextContextualizer = createContextProvider(NavigationC
12
14
  */
13
15
 
14
16
  export function provideContext(contextValue, providerNode, contextualizer, contextualAdapter) {
15
- // Set up provider to give context to wire adpaters so that a component connected
16
- // under the providerNode subtree and wired to those adapters will receive this id
17
- contextualAdapter.setContext(providerNode, contextValue);
18
- contextualizer(providerNode, {
19
- consumerConnectedCallback: contextualAdapter.subscribeContext.bind(contextualAdapter, providerNode),
20
- consumerDisconnectedCallback: contextualAdapter.unsubscribeContext.bind(contextualAdapter, providerNode)
21
- });
17
+ if (contextualizer && contextualAdapter) {
18
+ // Set up provider to give context to wire adpaters so that a component connected
19
+ // under the providerNode subtree and wired to those adapters will receive this id
20
+ contextualAdapter.setContext(providerNode, contextValue);
21
+ contextualizer(providerNode, {
22
+ consumerConnectedCallback: contextualAdapter.subscribeContext.bind(contextualAdapter, providerNode),
23
+ consumerDisconnectedCallback: contextualAdapter.unsubscribeContext.bind(contextualAdapter, providerNode)
24
+ });
25
+ }
22
26
  }
@@ -47,9 +47,15 @@ export class ContextInfo {
47
47
 
48
48
  setContext(targetProvider, contextValue) {
49
49
  validateProvider(targetProvider);
50
+ const value = contextValue;
50
51
  const info = this.getInfo(targetProvider);
51
52
  info.contextValue = contextValue;
52
- info.consumers.forEach(consumer => consumer.provide(contextValue));
53
+ info.consumers.forEach(consumer => consumer.provide(value));
54
+
55
+ if (info.consumers.size === 0 && value?.onComplete) {
56
+ // Ensure that wire callbacks are executed even if the wire has 0 subscribers
57
+ value.onComplete();
58
+ }
53
59
  }
54
60
  /**
55
61
  * Get the context value directly associated with the target as a context provider.
@@ -9,7 +9,7 @@
9
9
  import { CurrentPageReference, CurrentView, NavigationContext, registerNavigationHelm } from 'lwr/navigation';
10
10
  import { currentPageReferenceContextualizer, currentViewContextualizer, navigationContextContextualizer, provideContext } from 'lwr/contextProvider';
11
11
  import { generateMessageObject, invariant, messages } from 'lwr/routerErrors';
12
- import { createFilterChain, guid } from 'lwr/routerUtils';
12
+ import { createFilterChain, guid, hasDocument } from 'lwr/routerUtils';
13
13
  import { createObservable } from 'lwr/observable'; // @ts-ignore Need to import from client-modules package
14
14
 
15
15
  import { ROUTER_ERROR, ROUTER_NAV, ROUTER_VIEW } from 'lwr/metrics'; // @ts-ignore
@@ -165,16 +165,19 @@ export class DomRouterImpl {
165
165
  }
166
166
  }, true); // add listener for navigation and parent events
167
167
 
168
- this.target.addEventListener(NAV_EVENT, this._handleNavigationEvent);
169
- this.target.addEventListener(PARENT_EVENT, this._handleParentEvent); // Only used by NavigationMixin, which can't use `@wire` because it's part of the navigation API, and can't import anything from lwc.
168
+ if (hasDocument) {
169
+ this.target.addEventListener(NAV_EVENT, this._handleNavigationEvent);
170
+ this.target.addEventListener(PARENT_EVENT, this._handleParentEvent); // Only used by NavigationMixin, which can't use `@wire` because it's part of the navigation API, and can't import anything from lwc.
170
171
 
171
- this.target.addEventListener(CONTEXT_ID_BACKDOOR, event => {
172
- const navCtxEvent = event;
172
+ this.target.addEventListener(CONTEXT_ID_BACKDOOR, event => {
173
+ const navCtxEvent = event;
174
+
175
+ if (navCtxEvent.detail.callback) {
176
+ navCtxEvent.detail.callback(this.contextId);
177
+ }
178
+ });
179
+ }
173
180
 
174
- if (navCtxEvent.detail.callback) {
175
- navCtxEvent.detail.callback(this.contextId);
176
- }
177
- });
178
181
  this.connected = true;
179
182
  }
180
183
 
@@ -474,7 +477,7 @@ export class DomRouterImpl {
474
477
  };
475
478
 
476
479
  _sendEvent(name, payload) {
477
- this.target.dispatchEvent(new CustomEvent(name, {
480
+ hasDocument && this.target.dispatchEvent(new CustomEvent(name, {
478
481
  bubbles: true,
479
482
  composed: true,
480
483
  detail: payload
@@ -27,12 +27,4 @@ export declare function getUrlObject(url?: string): UrlObject;
27
27
  * @return {string}
28
28
  */
29
29
  export declare function getRelativeUrl(url: string): string;
30
- /**
31
- * f(url) -> "/some/relative/path"
32
- *
33
- * @param {string} url - URL string to parse for a path
34
- *
35
- * @returns {string}
36
- */
37
- export declare function getPathFromAnyUrl(url: string): string;
38
30
  //# sourceMappingURL=uriUtils.d.ts.map
@@ -72,17 +72,4 @@ export function getRelativeUrl(url) {
72
72
  const href = urlObj.href.replace(/:\d+/, '');
73
73
  const origin = urlObj.origin.replace(/:\d+/, '');
74
74
  return href.replace(origin, '');
75
- }
76
- /**
77
- * f(url) -> "/some/relative/path"
78
- *
79
- * @param {string} url - URL string to parse for a path
80
- *
81
- * @returns {string}
82
- */
83
-
84
- export function getPathFromAnyUrl(url) {
85
- const path = getUrlObject(url).pathname; // Remove trailing slash.
86
-
87
- return path === '/' ? '/' : path.replace(/\/$/, '');
88
75
  }
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { DomRouterImpl } from 'lwr/domRouter';
8
8
  import { getRelativeUrl, replace, set } from 'lwr/domRouterUtils';
9
+ import { hasDocument } from 'lwr/routerUtils';
9
10
 
10
11
  /*
11
12
  * Provides a Router rooted to the window, which controls the browser history by default.
@@ -22,7 +23,7 @@ export class HistoryRouter extends DomRouterImpl {
22
23
 
23
24
  if (!this.historyDisabled) {
24
25
  // Subscribe to the Window.popstate event to listen for URL changes.
25
- window.addEventListener('popstate', this.onpopstate.bind(this)); // Initialize using the current URL state
26
+ hasDocument && window.addEventListener('popstate', this.onpopstate.bind(this)); // Initialize using the current URL state
26
27
 
27
28
  this.onpopstate();
28
29
  }
@@ -30,14 +31,14 @@ export class HistoryRouter extends DomRouterImpl {
30
31
 
31
32
  onpopstate() {
32
33
  // Only the root should update the url since it has the full context
33
- if (!this.parent) {
34
+ if (!this.parent && hasDocument) {
34
35
  this.catchBrowserUpdate(getRelativeUrl(document.location.href));
35
36
  }
36
37
  }
37
38
 
38
39
  disconnect() {
39
40
  super.disconnect();
40
- window.removeEventListener('popstate', this.onpopstate);
41
+ hasDocument && window.removeEventListener('popstate', this.onpopstate);
41
42
  }
42
43
  /**
43
44
  * Override.
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { LightningElement, api } from 'lwc';
8
8
  import { createNavigationContext } from './utils';
9
+ import { hasDocument } from 'lwr/routerUtils';
9
10
 
10
11
  /*
11
12
  * Provides a LWC router component. These can be nested and all report to the root router.
@@ -19,7 +20,7 @@ export default class RouterContainer extends LightningElement {
19
20
 
20
21
  constructor() {
21
22
  super();
22
- this.currentTitle = document.title;
23
+ this.currentTitle = hasDocument ? document.title : '';
23
24
  }
24
25
  /**
25
26
  * Create a router attached to this component.
@@ -0,0 +1,2 @@
1
+ export declare const hasDocument: boolean;
2
+ //# sourceMappingURL=domUtils.d.ts.map
@@ -0,0 +1,2 @@
1
+ /* eslint-disable lwr/no-unguarded-apis */
2
+ export const hasDocument = typeof document !== 'undefined';
@@ -15,6 +15,7 @@ export declare const pathToRegexp: {
15
15
  compile: typeof ptrCompile;
16
16
  };
17
17
  export { getPathFromUrl, getQueryFromUrl, getQueryString, encode, decode } from './uriUtils';
18
+ export { hasDocument } from './domUtils';
18
19
  export type { Key } from './pathToRegexp';
19
20
  export type { Filter, FilterChain } from './filterUtils';
20
21
  export type { CompiledRouteDefinition, CompiledRoutingMatch, Constructor, Constructable, MessageObject, Module, PageReference, RouteCallback, RouteDefinition, RouteHandler, RouteHandlerCallback, RouteHandlerClass, RouteHandlerModule, Router, RouterConfig, RouteDestination, RouteInstance, RoutingMatch, RoutingResult, StringAttributes, UrlMapper, ViewSet, ViewInfo, RouterSerializationConfig, } from './types';
@@ -14,4 +14,5 @@ export const pathToRegexp = {
14
14
  pathToRegexp: ptr,
15
15
  compile: ptrCompile
16
16
  };
17
- export { getPathFromUrl, getQueryFromUrl, getQueryString, encode, decode } from './uriUtils';
17
+ export { getPathFromUrl, getQueryFromUrl, getQueryString, encode, decode } from './uriUtils';
18
+ export { hasDocument } from './domUtils';
@@ -82,7 +82,6 @@ export interface RouteInstance {
82
82
  state: NullableStringAttributes;
83
83
  pageReference: PageReference;
84
84
  }
85
- export declare type RouteTarget = string | PageReference;
86
85
  export declare type RouteDestination = {
87
86
  viewset: ViewSet;
88
87
  };
@@ -19,6 +19,7 @@ export interface PageReference {
19
19
  attributes: Record<string, string | null>;
20
20
  state: Record<string, string | null>;
21
21
  }
22
+ export declare function deleteRouterConfigJsonCacheEntry(path: string): void;
22
23
  /**
23
24
  * Given a Routes Config path, return the array of Config Route Definitions
24
25
  * @param path - A path to a Route Config files
@@ -62,12 +62,23 @@ const RouteDefinitionSchema = {
62
62
  };
63
63
  const ajv = new Ajv();
64
64
  const validate = ajv.compile(RouteDefinitionSchema);
65
+ // Cache the Router Config JSON objects read from the file system, by file path
66
+ const routerConfigJsonCache = new Map();
67
+ export function deleteRouterConfigJsonCacheEntry(path) {
68
+ routerConfigJsonCache.delete(path);
69
+ }
65
70
  /**
66
71
  * Given a Routes Config path, return the array of Config Route Definitions
67
72
  * @param path - A path to a Route Config files
68
73
  */
69
74
  export function getClientRoutes(path) {
75
+ if (routerConfigJsonCache.has(path)) {
76
+ // Cache hit
77
+ return routerConfigJsonCache.get(path);
78
+ }
79
+ // Cache miss, read from file system
70
80
  if (!existsSync(path)) {
81
+ console.warn('@lwrjs/router services cannot find client route JSON at:', path);
71
82
  return undefined;
72
83
  }
73
84
  try {
@@ -92,6 +103,7 @@ export function getClientRoutes(path) {
92
103
  throw new Error('A route definition must contain either "handler" or "component"');
93
104
  }
94
105
  });
106
+ routerConfigJsonCache.set(path, json); // Cache the JSON
95
107
  return json;
96
108
  }
97
109
  catch (e) {
@@ -9,7 +9,6 @@ export default class RouterModuleProvider implements ModuleProvider {
9
9
  private routerEmitter;
10
10
  private routerWatcher?;
11
11
  private watchedFileMap;
12
- private routerConfigJsonCache;
13
12
  private routerModuleCache;
14
13
  constructor({ routesDir }: RouterProviderOptions, context: ProviderContext);
15
14
  onRouterModuleChange(configPath: string, deleted?: boolean): Promise<void>;
@@ -1,15 +1,14 @@
1
1
  import { hashContent, normalizeResourcePath } from '@lwrjs/shared-utils';
2
2
  import { generateModule, getRouterConfigPath, parseSpecifier, setUpWatcher } from './utils.js';
3
- import { getClientRoutes } from '../index.js';
3
+ import { deleteRouterConfigJsonCacheEntry, getClientRoutes } from '../index.js';
4
4
  const DEFAULT_DIR = '$rootDir/src/routes';
5
5
  export default class RouterModuleProvider {
6
6
  constructor({ routesDir = DEFAULT_DIR }, context) {
7
7
  this.name = 'router-module-provider';
8
8
  this.watchedFileMap = new Map(); // <config path, module id>
9
9
  // Two layers of caching:
10
- // 1. Cache the Router Config JSON objects read from the file system, by config path
10
+ // 1. Cache the Router Config JSON objects read from the file system, by config path (routerConfigJsonCache in ../index)
11
11
  // 2. Cache the modules generated from the config, by config path
12
- this.routerConfigJsonCache = new Map();
13
12
  this.routerModuleCache = new Map();
14
13
  const { appEmitter, config: { rootDir, contentDir, layoutsDir }, runtimeEnvironment: { lwrVersion, watchFiles }, } = context;
15
14
  this.version = lwrVersion;
@@ -25,7 +24,7 @@ export default class RouterModuleProvider {
25
24
  this.routerWatcher = watchFiles ? setUpWatcher(this.onRouterModuleChange.bind(this)) : undefined;
26
25
  }
27
26
  // When Router Metadata changes on the file system:
28
- // 1. delete the config data from the routerConfigJsonCache
27
+ // 1. delete the config data from the routerConfigJsonCache (in ../index)
29
28
  // 2. delete the module from the routerModuleCache
30
29
  // 3. recompile the module based on the new data and emit
31
30
  async onRouterModuleChange(configPath, deleted = false) {
@@ -33,7 +32,7 @@ export default class RouterModuleProvider {
33
32
  if (!moduleId) {
34
33
  throw new Error('We are observing an unprocessed Router Config file, this should not happen...');
35
34
  }
36
- this.routerConfigJsonCache.delete(configPath);
35
+ deleteRouterConfigJsonCacheEntry(configPath);
37
36
  this.routerModuleCache.delete(configPath);
38
37
  if (!deleted) {
39
38
  const recompiledModule = await this.getModule(moduleId);
@@ -62,19 +61,9 @@ export default class RouterModuleProvider {
62
61
  let config;
63
62
  const routerId = parseSpecifier(specifier);
64
63
  if (routerId) {
65
- // Fetch the Router Config JSON from the cache or file system
66
- const cacheKey = getRouterConfigPath(this.routesDir, specifier);
67
- if (this.routerConfigJsonCache.has(cacheKey)) {
68
- // Cache hit
69
- config = this.routerConfigJsonCache.get(cacheKey);
70
- }
71
- else {
72
- // Cache miss, read from file system
73
- config = getClientRoutes(cacheKey);
74
- if (config) {
75
- this.routerConfigJsonCache.set(cacheKey, config);
76
- }
77
- }
64
+ // Fetch the Router Config JSON
65
+ const configPath = getRouterConfigPath(this.routesDir, specifier);
66
+ config = getClientRoutes(configPath);
78
67
  }
79
68
  return config;
80
69
  }
@@ -1,4 +1,4 @@
1
- import { createFileWatcher, debounce } from '@lwrjs/shared-utils';
1
+ import { createFileWatcher, debounce, logger } from '@lwrjs/shared-utils';
2
2
  export const SPECIFIER_PREFIX = '@lwrjs/router/';
3
3
  /**
4
4
  * Parse a specifier into its Router Config ID
@@ -25,7 +25,7 @@ export function setUpWatcher(onModuleChange) {
25
25
  const watcher = createFileWatcher();
26
26
  watcher.on('change', debounce((file) => onModuleChange(file), 500));
27
27
  watcher.on('unlink', debounce((file) => onModuleChange(file, true), 500));
28
- watcher.on('add', (file) => console.log(`Watching Router Config file at "${file}"`));
28
+ watcher.on('add', (file) => logger.info(`Watching Router Config file at "${file}"`));
29
29
  return watcher;
30
30
  }
31
31
  /**
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.8.0-alpha.9",
8
+ "version": "0.9.0-alpha.0",
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.0-alpha.9",
52
- "@lwrjs/diagnostics": "0.8.0-alpha.9",
53
- "@lwrjs/shared-utils": "0.8.0-alpha.9",
51
+ "@lwrjs/client-modules": "0.9.0-alpha.0",
52
+ "@lwrjs/diagnostics": "0.9.0-alpha.0",
53
+ "@lwrjs/shared-utils": "0.9.0-alpha.0",
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": "037c471903c6753fc6866ef598571b0df83e58f9"
79
+ "gitHead": "6890d8619b295a49ee1ed8253a372337d83863be"
80
80
  }