@lwrjs/router 0.12.0-alpha.1 → 0.12.0-alpha.11

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 (53) hide show
  1. package/README.md +777 -0
  2. package/build/bundle/prod/lwr/navigation/navigation.js +1 -1
  3. package/build/bundle/prod/lwr/router/router.js +1 -1
  4. package/build/bundle/prod/lwr/routerContainer/routerContainer.js +1 -1
  5. package/build/cjs/modules/lwr/domRouter/domRouter.cjs +20 -10
  6. package/build/cjs/modules/lwr/historyRouter/historyRouter.cjs +3 -3
  7. package/build/cjs/modules/lwr/navigation/navigationApi.cjs +4 -4
  8. package/build/cjs/modules/lwr/navigation/navigationMixin.cjs +4 -4
  9. package/build/cjs/modules/lwr/router/router.cjs +14 -13
  10. package/build/cjs/modules/lwr/routerUtils/routeUtils.cjs +21 -8
  11. package/build/cjs/modules/lwr/routerUtils/routerUtils.cjs +1 -0
  12. package/build/cjs/modules/lwr/serverRouter/serverRouter.cjs +10 -10
  13. package/build/cjs/services/index.cjs +0 -1
  14. package/build/cjs/services/module-provider/index.cjs +13 -36
  15. package/build/cjs/services/module-provider/utils.cjs +18 -8
  16. package/build/es/modules/lwr/contextUtils/navigationApiStore.d.ts +3 -2
  17. package/build/es/modules/lwr/domRouter/domRouter.d.ts +14 -8
  18. package/build/es/modules/lwr/domRouter/domRouter.js +25 -10
  19. package/build/es/modules/lwr/historyRouter/historyRouter.d.ts +3 -2
  20. package/build/es/modules/lwr/historyRouter/historyRouter.js +4 -4
  21. package/build/es/modules/lwr/navigation/navigationApi.d.ts +9 -8
  22. package/build/es/modules/lwr/navigation/navigationApi.js +10 -10
  23. package/build/es/modules/lwr/navigation/navigationMixin.js +4 -4
  24. package/build/es/modules/lwr/router/router.d.ts +1 -1
  25. package/build/es/modules/lwr/router/router.js +15 -14
  26. package/build/es/modules/lwr/routerUtils/routeUtils.d.ts +7 -5
  27. package/build/es/modules/lwr/routerUtils/routeUtils.js +22 -8
  28. package/build/es/modules/lwr/routerUtils/routerUtils.d.ts +1 -1
  29. package/build/es/modules/lwr/routerUtils/routerUtils.js +1 -1
  30. package/build/es/modules/lwr/routerUtils/types.d.ts +17 -13
  31. package/build/es/modules/lwr/serverRouter/serverRouter.d.ts +4 -3
  32. package/build/es/modules/lwr/serverRouter/serverRouter.js +11 -11
  33. package/build/es/services/index.d.ts +3 -1
  34. package/build/es/services/index.js +0 -1
  35. package/build/es/services/module-provider/index.d.ts +6 -7
  36. package/build/es/services/module-provider/index.js +15 -47
  37. package/build/es/services/module-provider/utils.d.ts +2 -2
  38. package/build/es/services/module-provider/utils.js +24 -8
  39. package/build/modules/lwr/contextUtils/contextUtils.js +1 -0
  40. package/build/modules/lwr/domRouter/domRouter.js +27 -10
  41. package/build/modules/lwr/domRouterUtils/historyUtils.js +1 -0
  42. package/build/modules/lwr/historyRouter/historyRouter.js +4 -4
  43. package/build/modules/lwr/navigation/navigationApi.js +10 -10
  44. package/build/modules/lwr/navigation/navigationMixin.js +4 -4
  45. package/build/modules/lwr/router/router.js +15 -14
  46. package/build/modules/lwr/routerBridge/routerBridge.js +0 -1
  47. package/build/modules/lwr/routerContainer/utils.js +3 -1
  48. package/build/modules/lwr/routerUtils/routeDefUtils.js +0 -1
  49. package/build/modules/lwr/routerUtils/routeUtils.js +23 -8
  50. package/build/modules/lwr/routerUtils/routerUtils.js +1 -1
  51. package/build/modules/lwr/routerUtils/typeUtils.js +1 -0
  52. package/build/modules/lwr/serverRouter/serverRouter.js +11 -11
  53. package/package.json +9 -9
@@ -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,o){e(t);const n=o,a=this.getInfo(t);a.contextValue=o,a.consumers.forEach((e=>e.provide(n))),0===a.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:a}=this.getInfo(t);n.has(o)||(n.add(o),o.provide(a))}unsubscribeContext(t,o){e(t),this.getInfo(t).consumers.delete(o)}}const o="LWR",n=1;function a(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,o)=>t[o])):e}function s(e,t){return`${e.code}: ${a(e.message,t)}`}function i(e,t){const o={...e,message:a(e.message,t)};return e.address&&(o.address=a(e.address,t)),e.stack&&(o.stack=a(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:'A route definition must contain a "uri" property.',level:n},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 must provide page binding",level:n},INVALID_PAGE_BINDING:{code:`${o}4021`,message:"Invalid page binding in route definition",level:n},INVALID_URI_SYNTAX:{code:`${o}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:n},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(s(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=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],a=n,s=a&&a.module||n;let c;if(s)try{const e=await s(),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=a.specifier?i(r.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[a.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){l(e).navigate(t,o)}function f(e,t){return l(e).generateUrl(t)}const E=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,_="undefined"==typeof window,N=Symbol("Navigate"),p=Symbol("GenerateUrl"),C=Symbol("NavContext"),T=Symbol("NavContext");function w(e){!function(e,t,o){if(!e)throw new Error(s(t,o))}("function"==typeof e.prototype.dispatchEvent,r.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[T](){if(!this[C]&&(this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{callback:e=>{this[C]=e}}})),!this[C]))throw new Error(s(r.MISSING_CONTEXT))}[N](e,t){_||(this[T](),h(this[C],e,t))}async[p](e){return _?null:(this[T](),f(this[C],e))}}}w.Navigate=N,w.GenerateUrl=p,w.NavContext=C;export{t as ContextInfo,v as CurrentPageReference,m as CurrentView,I as NavigationContext,w 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=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,a=this.getInfo(t);a.contextValue=o,a.consumers.forEach((e=>e.provide(n))),0===a.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:a}=this.getInfo(t);n.has(o)||(n.add(o),o.provide(a))}unsubscribeContext(t,o){e(t),this.getInfo(t).consumers.delete(o)}}const o="LWR",n=1;function a(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,o)=>t[o])):e}function s(e,t){return`${e.code}: ${a(e.message,t)}`}function i(e,t){const o={...e,message:a(e.message,t)};return e.address&&(o.address=a(e.address,t)),e.stack&&(o.stack=a(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:'A route definition must contain a "uri" property.',level:n},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 must provide page binding",level:n},INVALID_PAGE_BINDING:{code:`${o}4021`,message:"Invalid page binding in route definition",level:n},INVALID_URI_SYNTAX:{code:`${o}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:n},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(s(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=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],a=n,s=a&&a.module||n;let c;if(s)try{const e=await s(),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=a.specifier?i(r.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[a.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 E=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,_="undefined"==typeof window,N=Symbol("Navigate"),p=Symbol("GenerateUrl"),C=Symbol("NavContext"),T=Symbol("NavContext");function w(e){!function(e,t,o){if(!e)throw new Error(s(t,o))}("function"==typeof e.prototype.dispatchEvent,r.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[T](){if(!this[C]&&(this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{callback:e=>{this[C]=e}}})),!this[C]))throw new Error(s(r.MISSING_CONTEXT))}[N](e,t,o){_||(this[T](),h(this[C],e,t,o))}async[p](e,t){return _?null:(this[T](),f(this[C],e,t))}}}w.Navigate=N,w.GenerateUrl=p,w.NavContext=C;export{t as ContextInfo,v as CurrentPageReference,m as CurrentView,I as NavigationContext,w 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
- function e(e=""){return e=e||"",decodeURIComponent(e)}function t(e){"/"!==(e=e||"/").charAt(0)&&(e="/"+e);const t=e.match(/^[^#?]+/);if(null!==t){const e=t[0];return"/"===e?"/":e.replace(/\/$/,"")}return"/"}function n(t){const n=(t=t||"").indexOf("#");n>=0&&(t=t.substring(0,n));const r=t.indexOf("?"),o=r>=0?t.substr(r+1):null,i={};return o&&o.split("&").forEach((t=>{if(t.indexOf("=")>=0){const[n,r=""]=t.split("=");i[e(n)]=e(r)}else i[e(t)]=null})),i}function r(e={}){const t=Object.keys(e);return t.length?`?${t.map((t=>{const n=e[t];return null===n?t:`${t}=${function(e=""){return e=e||"",encodeURIComponent(e)}(n)}`})).join("&")}`:""}function o(e){return!!(e&&e.length>1)&&e.startsWith(":")}function i(e){return!!e&&(!!o(e)&&e.substr(1))}function s(e){return Object.values(e).reduce(((e,{routeParamName:t})=>{const n=i(t);return n&&e.push(n),e}),[])}function a(t,n){const{regex:r,params:o}=n,i=r.exec(t);if(i){const[,...t]=i,n={};return o.forEach(((r,o)=>{const{name:i}=r,s=t[o];n[i]=s?e(s):s})),n}return null}function u(t,n){if(t&&n){const{queryMatcher:r}=n,o=r(t);if(o){const t={};return Object.keys(o).forEach((n=>{const r=o[n],{value:i,routeParamName:s}=r,a=s?s.substr(1):n;t[a]=i?e(i):i})),t}}return null}function c(e,r){if(r){const{original:{page:{type:i="",attributes:s={},state:c={}}={}}={}}=r,l=t(e),f=n(e),d=a(l,r),p=u(f,r);if(d&&p){const e={...d,...p},t={};Object.keys(s).forEach((n=>{const r=s[n];let i;if(r&&o(r)){const t=r.substr(1);i=e[t]}else i=r;t[n]=i}));const n={};Object.keys(c).forEach((t=>{const r=c[t];let i;if(r&&o(r)){const t=r.substr(1);i=e[t]}else i=r;n[t]=i}));const a=function(e,t){const{compiledQuery:n}=t,r=Object.keys(n).filter((e=>{const{literalValue:t}=n[e];return!t})),o={};return Object.keys(e).forEach((t=>{const n=e[t];r.indexOf(t)<0&&(o[t]=n)})),o}(f,r);return{type:i,attributes:{...t},state:{...a,...n}}}}return null}function l(e,r){const o=t(e),i=n(e),s=r?r.filter((e=>e.regex.test(o))):[],[c]=s.filter((e=>{const{queryMatcher:t}=e;return t(i)&&function(e,t,n){const{original:{patterns:r=null}={}}=n||{};if(r){const o={...a(e,n),...u(t,n)};return Object.keys(r).every((e=>{const t=r[e],n=new RegExp(t),i=o[e]||"";return n.test(i)}))}return!0}(o,i,e)}));return c||null}function f(e,t,n=""){n&&0===e.indexOf(n)&&(e=e.replace(n,""));const r=l(e,t);let o;if(!r)return null;{const t=c(e,r);if(t){return o={route:{id:r.original.id,attributes:{...t.attributes},state:{...t.state},pageReference:{type:t.type,attributes:{...t.attributes},state:{...t.state}}},routeDefinition:r},o}}return null}function d(e,t,n=""){const r=function(e,t){if(!e)return null;const{type:n,attributes:r={},state:i={}}=e;if(n){const[e]=t.filter((e=>{const{original:{page:{type:t=null,attributes:s={},state:a={}}={}}}=e,u=t===n,c=Object.keys(s).every((e=>Object.keys(r).indexOf(e)>=0)),l=Object.keys(s).length===Object.keys(r).length,f=Object.keys(a).every((e=>Object.keys(i).indexOf(e)>=0)),d=Object.keys(s).filter((e=>{const t=s[e];return!t||!o(t)})).every((e=>s[e]===r[e])),p=Object.keys(a).filter((e=>{const t=a[e];return null===t||!o(t)})).every((e=>a[e]===i[e]));return u&&c&&l&&d&&f&&p}));return e||null}return null}(e,t);return r?h(e,r,n):null}function p(e,t,n){const{attributeBindings:r,stateBindings:o}=n,{attributes:s,state:a}=t,u={};return e.forEach((e=>{const[t]=Object.keys(r).filter((t=>i(r[t])===e));if(t)u[e]=s[t];else{const[t]=Object.keys(o).filter((t=>i(o[t])===e));t&&(u[e]=a[t])}})),u}function h(e,t,n=""){const{params:a,original:{page:u={}}={},toPath:c,compiledQuery:l}=t,{attributes:f={},state:d={}}=u,h=c(p(a.filter((({name:e})=>"string"==typeof e)).map((({name:e})=>e)),e,{attributeBindings:f,stateBindings:d})),g=function(e,t,n){const{compiledQuery:r,original:{page:{state:s={}}}}=n,{state:a={}}=e||{},u={};Object.keys(a).filter((e=>!o(s[e]))).forEach((e=>u[e]=a[e]));const c={};return Object.keys(t).forEach((e=>{const n=t[e],[o]=Object.keys(r).filter((t=>{const n=r[t],{routeParamName:o}=n;return i(o)===e}));if(o){c[o]=n}})),{...u,...c}}(e,p(s(l),e,{attributeBindings:f,stateBindings:d}),t);return`${n}${h}${r(g)}`}function g(e,t=2){if(function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}(e))try{Object.freeze(e),t>0&&Object.keys(e).forEach((n=>{if(function(e,t){return t in e}(e,n)){const r=e[n];r&&"object"==typeof r&&g(r,t-1)}}))}catch(e){}return e}const m="LWR",E=1;function y(e,t){return`${e.code}: ${function(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}(e.message,t)}`}function b(e,t,n){if(!e)throw new Error(y(t,n))}const I={INVALID_MIXIN_CMP:{code:`${m}4001`,message:"{0} must be an Element type",level:E},MISSING_CONTEXT:{code:`${m}4002`,message:"Could not find context to perform navigation action.",level:E},INVALID_CONTEXT:{code:`${m}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:E},MULTIPLE_ROOTS:{code:`${m}4004`,message:"Router connection failed. There can only be one root router.",level:E},MULTIPLE_CHILDREN:{code:`${m}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:E},MISSING_ROUTE:{code:`${m}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:E,address:"{0}"},MISSING_URL:{code:`${m}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:E,address:"{0}"},PRENAV_FAILED:{code:`${m}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${m}4009`,message:'A route definition must contain a "uri" property.',level:E},MISSING_ROUTE_CMP:{code:`${m}4016`,message:"Expected a route view component with a default export.",level:E},MISSING_DATA_CONTEXT:{code:`${m}4018`,message:"Could not find context to retrieve navigation data.",level:E},INVALID_ROUTE_QUERY:{code:`${m}4019`,message:"Invalid query param in route definition.",level:E},MISSING_PAGE_BINDING:{code:`${m}4020`,message:"Route definition must provide page binding",level:E},INVALID_PAGE_BINDING:{code:`${m}4021`,message:"Invalid page binding in route definition",level:E},INVALID_URI_SYNTAX:{code:`${m}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:E},VIEW_IMPORT_FAILED:{code:`${m}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:E,stack:"{2}"},VIEW_MISSING:{code:`${m}4024`,message:'Expected a view with name "{0}" in the viewset',level:E},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${m}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:E,stack:"{3}"},NO_ROUTE_MATCH:{code:`${m}4026`,message:"A routing match cannot be found for: {0}",level:E},INVALID_ROUTE_HANDLER:{code:`${m}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:E},DESTINATION_NOT_FOUND:{code:`${m}4028`,message:"Route handler returned 404: Not Found",level:E},DESTINATION_ERROR:{code:`${m}4029`,message:"Route handler returned error status {0}: {1}",level:E,stack:"{2}"},NO_INIT_URL:{code:`${m}4030`,message:'Cannot initialize a server router without a "url"',level:E}};function v(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function R(e){return e&&e.sensitive?"":"i"}function $(e,t={}){const n=function(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];if("*"!==r&&"+"!==r&&"?"!==r)if("\\"!==r)if("{"!==r)if("}"!==r)if(":"!==r)if("("!==r)t.push({type:"CHAR",index:n,value:e[n++]});else{let r=1,o="",i=n+1;if("?"===e[i])throw new TypeError(`Pattern cannot start with "?" at ${i}`);for(;i<e.length;)if("\\"!==e[i]){if(")"===e[i]){if(r--,0===r){i++;break}}else if("("===e[i]&&(r++,"?"!==e[i+1]))throw new TypeError(`Capturing groups are not allowed at ${i}`);o+=e[i++]}else o+=e[i++]+e[i++];if(r)throw new TypeError(`Unbalanced pattern at ${n}`);if(!o)throw new TypeError(`Missing pattern at ${n}`);t.push({type:"PATTERN",index:n,value:o}),n=i}else{let r="",o=n+1;for(;o<e.length;){const t=e.charCodeAt(o);if(!(t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||95===t))break;r+=e[o++]}if(!r)throw new TypeError(`Missing parameter name at ${n}`);t.push({type:"NAME",index:n,value:r}),n=o}else t.push({type:"CLOSE",index:n,value:e[n++]});else t.push({type:"OPEN",index:n,value:e[n++]});else t.push({type:"ESCAPED_CHAR",index:n++,value:e[n++]});else t.push({type:"MODIFIER",index:n,value:e[n++]})}return t.push({type:"END",index:n,value:""}),t}(e),{prefixes:r="./"}=t,o=`[^${v(t.delimiter||"/#?")}]+?`,i=[];let s=0,a=0,u="";const c=e=>{if(a<n.length&&n[a].type===e)return n[a++].value},l=e=>{const t=c(e);if(void 0!==t)return t;const{type:r,index:o}=n[a];throw new TypeError(`Unexpected ${r} at ${o}, expected ${e}`)},f=()=>{let e,t="";for(;e=c("CHAR")||c("ESCAPED_CHAR");)t+=e;return t};for(;a<n.length;){const e=c("CHAR"),t=c("NAME"),n=c("PATTERN");if(t||n){let a=e||"";-1===r.indexOf(a)&&(u+=a,a=""),u&&(i.push(u),u=""),i.push({name:t||s++,prefix:a,suffix:"",pattern:n||o,modifier:c("MODIFIER")||""});continue}const a=e||c("ESCAPED_CHAR");if(a){u+=a;continue}u&&(i.push(u),u="");if(c("OPEN")){const e=f(),t=c("NAME")||"",n=c("PATTERN")||"",r=f();l("CLOSE"),i.push({name:t||(n?s++:""),pattern:t&&!n?o:n,prefix:e,suffix:r,modifier:c("MODIFIER")||""})}else l("END")}return i}function O(e,t){return function(e,t={}){const n=R(t),{encode:r=(e=>e),validate:o=!0}=t,i=e.map((e=>{if("object"==typeof e)return new RegExp(`^(?:${e.pattern})$`,n)}));return t=>{let n="";for(let s=0;s<e.length;s++){const a=e[s];if("string"==typeof a){n+=a;continue}const u=t?t[a.name]:void 0,c="?"===a.modifier||"*"===a.modifier,l="*"===a.modifier||"+"===a.modifier;if(Array.isArray(u)){if(!l)throw new TypeError(`Expected "${a.name}" to not repeat, but got an array`);if(0===u.length){if(c)continue;throw new TypeError(`Expected "${a.name}" to not be empty`)}for(let e=0;e<u.length;e++){const t=r(u[e],a);if(o&&!i[s].test(t))throw new TypeError(`Expected all "${a.name}" to match "${a.pattern}", but got "${t}"`);n+=a.prefix+t+a.suffix}continue}if("string"==typeof u||"number"==typeof u){const e=r(String(u),a);if(o&&!i[s].test(e))throw new TypeError(`Expected "${a.name}" to match "${a.pattern}", but got "${e}"`);n+=a.prefix+e+a.suffix;continue}if(c)continue;const f=l?"an array":"a string";throw new TypeError(`Expected "${a.name}" to be ${f}`)}return n}}($(e,t),t)}function N(e,t,n){return function(e,t,n={}){const{strict:r=!1,start:o=!0,end:i=!0,encode:s=(e=>e)}=n,a=`[${v(n.endsWith||"")}]|$`,u=`[${v(n.delimiter||"/#?")}]`;let c=o?"^":"";for(const n of e)if("string"==typeof n)c+=v(s(n));else{const e=v(s(n.prefix)),r=v(s(n.suffix));if(n.pattern)if(t&&t.push(n),e||r)if("+"===n.modifier||"*"===n.modifier){const t="*"===n.modifier?"?":"";c+=`(?:${e}((?:${n.pattern})(?:${r}${e}(?:${n.pattern}))*)${r})${t}`}else c+=`(?:${e}(${n.pattern})${r})${n.modifier}`;else c+=`(${n.pattern})${n.modifier}`;else c+=`(?:${e}${r})${n.modifier}`}if(i)r||(c+=`${u}?`),c+=n.endsWith?`(?=${a})`:"$";else{const t=e[e.length-1],n="string"==typeof t?u.indexOf(t[t.length-1])>-1:void 0===t;r||(c+=`(?:${u}(?=${a}))?`),n||(c+=`(?=${u}|${a})`)}return new RegExp(c,R(n))}($(e,n),t,n)}function _(e,t,n){return e instanceof RegExp?function(e,t){if(!t)return e;const n=e.source.match(/\((?!\?)/g);if(n)for(let e=0;e<n.length;e++)t.push({name:e,prefix:"",suffix:"",modifier:"",pattern:""});return e}(e,t):Array.isArray(e)?function(e,t,n){const r=e.map((e=>_(e,t,n).source));return new RegExp(`(?:${r.join("|")})`,R(n))}(e,t,n):N(e,t,n)}const{INVALID_ROUTE_QUERY:A,MISSING_ROUTE_TEMPLATE:x,MISSING_PAGE_BINDING:T,INVALID_PAGE_BINDING:w,INVALID_URI_SYNTAX:D}=I;function U(e){const{routes:r,caseSensitive:a}=e;return r.map((e=>function(e,r=!1){const a=[],{uri:u,page:c}=e;b(!!u,x),b(function(e=""){const t=["*","(",")",";"].some((t=>e.indexOf(t)>=0));return!t}(u),D),b(!!c,T);const l=t(u),f=n(u),d=_(l,a,{sensitive:r,end:!1!==e.exact}),p=O(l,{encode:encodeURIComponent}),h=function(e){const t={};return Object.keys(e).forEach((n=>{const r=e[n];b(!o(n)||null===r,A),o(n)?t[n.substr(1)]={routeParamName:n}:r&&o(r)?t[n]={routeParamName:r}:t[n]={literalValue:null===r?null:r}})),t}(f),g=function(e,t=!1){const n=n=>{const r=Object.keys(n),o=Object.keys(e);return o.every((e=>r.indexOf(e)>=0))?o.reduce(((r,o)=>{if(null===r)return null;const{literalValue:i,routeParamName:s}=e[o],a=n[o];let u=!0;return"string"==typeof i?u=t?i===a:i.toUpperCase()===(null==a?a:a.toUpperCase()):null===i&&(u=a===i),r=u?{...r,[o]:{value:a,routeParamName:s}}:null}),{}):null};return n}(h,r),m={original:e,regex:d,params:a,toPath:p,compiledQuery:h,queryMatcher:g};return b(function(e){const{original:{page:t}={},params:n,compiledQuery:r}=e,a=t?t.type:t,u=(t?t.attributes:t)||{},c=(t?t.state:t)||{};if("string"!=typeof a||"object"!=typeof u||"object"!=typeof c)return!1;const l=Object.values(n).map((({name:e})=>e)),f=s(r),d=[...l,...f],p=Object.values(u).filter(o).map(i),h=Object.values(c).filter(o).map(i),g=d.every((e=>"string"==typeof e&&(p.indexOf(e)>=0||h.indexOf(e)>=0))),m=d.length===p.length+h.length;return!!(t&&a&&u&&c&&g&&m)}(m),w),m}(e,a)))}function P(){let e,t,n=[];const r=r=>{n.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{n.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{n.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),n=[],e=void 0,t=void 0},subscribe:(o,i=!0)=>{(e=>{n.push(e)})(o),e&&i&&o.next(e),t&&r(t);const s=n.length-1;return{unsubscribe:()=>(e=>{n=[...n.slice(0,e),...n.slice(e+1)]})(s)}}}}class C{constructor(e){this.deprecatedConfig={},this.routeHandlerId=0,this.compiledRoutes=[],this.routeObservable=P(),this.config={basePath:e.basePath||"",caseSensitive:Boolean(e.caseSensitive),routes:e.routes||[],generateUrl:e=>d(e,this.compiledRoutes,this.config.basePath),parseUrl:e=>function(e,t,n=""){const r=f(e,t,n);return r&&r.route&&r.route.pageReference?r.route.pageReference:null}(e,this.compiledRoutes,this.config.basePath)};const{DEPRECATED_getRouteFromUrl:t,DEPRECATED_getUrlFromRoute:n}=e;t&&(this.deprecatedConfig.DEPRECATED_getRouteFromUrl=t),n&&(this.deprecatedConfig.DEPRECATED_getUrlFromRoute=n),this.compiledRoutes=U(this.config)}generateUrl(e){const{DEPRECATED_getUrlFromRoute:t}=this.deprecatedConfig;return t?t(e,this.config.generateUrl):this.config.generateUrl(e)}parseUrl(e){const{DEPRECATED_getRouteFromUrl:t}=this.deprecatedConfig;return t?t(e,this.config.parseUrl):this.config.parseUrl(e)}matchRoute(e){const t="string"==typeof e?e:this.generateUrl(e);if(null===t)return null;const n=f(t,this.compiledRoutes,this.config.basePath),r=n&&h(n.route.pageReference,n.routeDefinition,this.config.basePath);return n&&r?{pathMatch:r,route:n.route,routeDefinition:n.routeDefinition.original}:null}async resolveView(e){return new Promise(((t,n)=>{const r=this.matchRoute(e);return r?r.routeDefinition.handler?.().then((e=>{const o=e.default;if(!o)return n(y(I.INVALID_ROUTE_HANDLER,[r.routeDefinition.id]));const i=new o(t);i&&i.update(r.route)})):n(y(I.NO_ROUTE_MATCH,[JSON.stringify(e)]))}))}navigate(e){const t=this.matchRoute(e);if(!t)throw new Error(y(I.MISSING_ROUTE,[JSON.stringify(e)]));this.pendingRoute={...t},this._mapView(this.pendingRoute)}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}async _mapView(e){const t=Math.random();this.routeHandlerId=t;const n=await(e.routeDefinition.handler?.()),r=n?.default;if(!r)throw new Error(y(I.INVALID_ROUTE_HANDLER,[e.routeDefinition.id]));return this.routeHandler=new r((e=>{this._updateView(t,e)})),this.routeHandler&&this.routeHandler.update(e.route),!0}_updateView(e,t){if(!t||e!==this.routeHandlerId)return;if(!this.pendingRoute)throw new Error("Trying to commit route state without a route");const n=g(t.viewset);this.routeObservable.next({...this.pendingRoute,...t,viewset:n})}}function S(e={}){return new C(e)}export{S as createRouter};
1
+ function e(e=""){return e=e||"",decodeURIComponent(e)}function t(e){"/"!==(e=e||"/").charAt(0)&&(e="/"+e);const t=e.match(/^[^#?]+/);if(null!==t){const e=t[0];return"/"===e?"/":e.replace(/\/$/,"")}return"/"}function n(t){const n=(t=t||"").indexOf("#");n>=0&&(t=t.substring(0,n));const r=t.indexOf("?"),o=r>=0?t.substr(r+1):null,i={};return o&&o.split("&").forEach((t=>{if(t.indexOf("=")>=0){const[n,r=""]=t.split("=");i[e(n)]=e(r)}else i[e(t)]=null})),i}function r(e={}){const t=Object.keys(e);return t.length?`?${t.map((t=>{const n=e[t];return null===n?t:`${t}=${function(e=""){return e=e||"",encodeURIComponent(e)}(n)}`})).join("&")}`:""}function o(e){return!!(e&&e.length>1)&&e.startsWith(":")}function i(e){return!!e&&(!!o(e)&&e.substr(1))}function s(e){return Object.values(e).reduce(((e,{routeParamName:t})=>{const n=i(t);return n&&e.push(n),e}),[])}function a(t,n){const{regex:r,params:o}=n,i=r.exec(t);if(i){const[,...t]=i,n={};return o.forEach(((r,o)=>{const{name:i}=r,s=t[o];n[i]=s?e(s):s})),n}return null}function u(t,n){if(t&&n){const{queryMatcher:r}=n,o=r(t);if(o){const t={};return Object.keys(o).forEach((n=>{const r=o[n],{value:i,routeParamName:s}=r,a=s?s.substr(1):n;t[a]=i?e(i):i})),t}}return null}function c(e,r){if(r){const{original:{page:{type:i="",attributes:s={},state:c={}}={}}={}}=r,l=t(e),f=n(e),d=a(l,r),p=u(f,r);if(d&&p){const e={...d,...p},t={};Object.keys(s).forEach((n=>{const r=s[n];let i;if(r&&o(r)){const t=r.substr(1);i=e[t]}else i=r;t[n]=i}));const n={};Object.keys(c).forEach((t=>{const r=c[t];let i;if(r&&o(r)){const t=r.substr(1);i=e[t]}else i=r;n[t]=i}));const a=function(e,t){const{compiledQuery:n}=t,r=Object.keys(n).filter((e=>{const{literalValue:t}=n[e];return!t})),o={};return Object.keys(e).forEach((t=>{const n=e[t];r.indexOf(t)<0&&(o[t]=n)})),o}(f,r);return{type:i,attributes:{...t},state:{...a,...n}}}}return null}const l={locale:"en-US",defaultLocale:"en-US"};function f(e,r){const o=t(e),i=n(e),s=r?r.filter((e=>e.regex.test(o))):[],[c]=s.filter((e=>{const{queryMatcher:t}=e;return t(i)&&function(e,t,n){const{original:{patterns:r=null}={}}=n||{};if(r){const o={...a(e,n),...u(t,n)};return Object.keys(r).every((e=>{const t=r[e],n=new RegExp(t),i=o[e]||"";return n.test(i)}))}return!0}(o,i,e)}));return c||null}function d(e,t,n="",r=l,o){if(n&&0===e?.indexOf(n)&&(e=e.replace(n,"")),o?.locale||r?.locale){const t=`/${o?.locale||r.locale}`;0===e?.indexOf(t)&&(e=e.replace(t,""))}const i=f(e,t);let s;if(!i)return null;{const t=c(e,i);if(t){return s={route:{id:i.original.id,attributes:{...t.attributes},state:{...t.state},pageReference:{type:t.type,attributes:{...t.attributes},state:{...t.state}}},routeDefinition:i},s}}return null}function p(e,t,n="",r=l,i){const s=function(e,t){if(!e)return null;const{type:n,attributes:r={},state:i={}}=e;if(n){const[e]=t.filter((e=>{const{original:{page:{type:t=null,attributes:s={},state:a={}}={}}}=e,u=t===n,c=Object.keys(s).every((e=>Object.keys(r).indexOf(e)>=0)),l=Object.keys(s).length===Object.keys(r).length,f=Object.keys(a).every((e=>Object.keys(i).indexOf(e)>=0)),d=Object.keys(s).filter((e=>{const t=s[e];return!t||!o(t)})).every((e=>s[e]===r[e])),p=Object.keys(a).filter((e=>{const t=a[e];return null===t||!o(t)})).every((e=>a[e]===i[e]));return u&&c&&l&&d&&f&&p}));return e||null}return null}(e,t);return s?g(e,s,n,r,i):null}function h(e,t,n){const{attributeBindings:r,stateBindings:o}=n,{attributes:s,state:a}=t,u={};return e.forEach((e=>{const[t]=Object.keys(r).filter((t=>i(r[t])===e));if(t)u[e]=s[t];else{const[t]=Object.keys(o).filter((t=>i(o[t])===e));t&&(u[e]=a[t])}})),u}function g(e,t,n="",a=l,u){const{params:c,original:{page:f={}}={},toPath:d,compiledQuery:p}=t,{attributes:g={},state:m={}}=f,E=d(h(c.filter((({name:e})=>"string"==typeof e)).map((({name:e})=>e)),e,{attributeBindings:g,stateBindings:m})),y=function(e,t,n){const{compiledQuery:r,original:{page:{state:s={}}}}=n,{state:a={}}=e||{},u={};Object.keys(a).filter((e=>!o(s[e]))).forEach((e=>u[e]=a[e]));const c={};return Object.keys(t).forEach((e=>{const n=t[e],[o]=Object.keys(r).filter((t=>{const n=r[t],{routeParamName:o}=n;return i(o)===e}));if(o){c[o]=n}})),{...u,...c}}(e,h(s(p),e,{attributeBindings:g,stateBindings:m}),t),b=r(y),I=u?.locale||a&&a.locale;return`${n}${I!==a.defaultLocale?`/${I}`:""}${E}${b}`}function m(e,t=2){if(function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}(e))try{Object.freeze(e),t>0&&Object.keys(e).forEach((n=>{if(function(e,t){return t in e}(e,n)){const r=e[n];r&&"object"==typeof r&&m(r,t-1)}}))}catch(e){}return e}const E="LWR",y=1;function b(e,t){return`${e.code}: ${function(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}(e.message,t)}`}function I(e,t,n){if(!e)throw new Error(b(t,n))}const v={INVALID_MIXIN_CMP:{code:`${E}4001`,message:"{0} must be an Element type",level:y},MISSING_CONTEXT:{code:`${E}4002`,message:"Could not find context to perform navigation action.",level:y},INVALID_CONTEXT:{code:`${E}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:y},MULTIPLE_ROOTS:{code:`${E}4004`,message:"Router connection failed. There can only be one root router.",level:y},MULTIPLE_CHILDREN:{code:`${E}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:y},MISSING_ROUTE:{code:`${E}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:y,address:"{0}"},MISSING_URL:{code:`${E}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:y,address:"{0}"},PRENAV_FAILED:{code:`${E}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${E}4009`,message:'A route definition must contain a "uri" property.',level:y},MISSING_ROUTE_CMP:{code:`${E}4016`,message:"Expected a route view component with a default export.",level:y},MISSING_DATA_CONTEXT:{code:`${E}4018`,message:"Could not find context to retrieve navigation data.",level:y},INVALID_ROUTE_QUERY:{code:`${E}4019`,message:"Invalid query param in route definition.",level:y},MISSING_PAGE_BINDING:{code:`${E}4020`,message:"Route definition must provide page binding",level:y},INVALID_PAGE_BINDING:{code:`${E}4021`,message:"Invalid page binding in route definition",level:y},INVALID_URI_SYNTAX:{code:`${E}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:y},VIEW_IMPORT_FAILED:{code:`${E}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:y,stack:"{2}"},VIEW_MISSING:{code:`${E}4024`,message:'Expected a view with name "{0}" in the viewset',level:y},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${E}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:y,stack:"{3}"},NO_ROUTE_MATCH:{code:`${E}4026`,message:"A routing match cannot be found for: {0}",level:y},INVALID_ROUTE_HANDLER:{code:`${E}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:y},DESTINATION_NOT_FOUND:{code:`${E}4028`,message:"Route handler returned 404: Not Found",level:y},DESTINATION_ERROR:{code:`${E}4029`,message:"Route handler returned error status {0}: {1}",level:y,stack:"{2}"},NO_INIT_URL:{code:`${E}4030`,message:'Cannot initialize a server router without a "url"',level:y}};function R(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function $(e){return e&&e.sensitive?"":"i"}function O(e,t={}){const n=function(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];if("*"!==r&&"+"!==r&&"?"!==r)if("\\"!==r)if("{"!==r)if("}"!==r)if(":"!==r)if("("!==r)t.push({type:"CHAR",index:n,value:e[n++]});else{let r=1,o="",i=n+1;if("?"===e[i])throw new TypeError(`Pattern cannot start with "?" at ${i}`);for(;i<e.length;)if("\\"!==e[i]){if(")"===e[i]){if(r--,0===r){i++;break}}else if("("===e[i]&&(r++,"?"!==e[i+1]))throw new TypeError(`Capturing groups are not allowed at ${i}`);o+=e[i++]}else o+=e[i++]+e[i++];if(r)throw new TypeError(`Unbalanced pattern at ${n}`);if(!o)throw new TypeError(`Missing pattern at ${n}`);t.push({type:"PATTERN",index:n,value:o}),n=i}else{let r="",o=n+1;for(;o<e.length;){const t=e.charCodeAt(o);if(!(t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||95===t))break;r+=e[o++]}if(!r)throw new TypeError(`Missing parameter name at ${n}`);t.push({type:"NAME",index:n,value:r}),n=o}else t.push({type:"CLOSE",index:n,value:e[n++]});else t.push({type:"OPEN",index:n,value:e[n++]});else t.push({type:"ESCAPED_CHAR",index:n++,value:e[n++]});else t.push({type:"MODIFIER",index:n,value:e[n++]})}return t.push({type:"END",index:n,value:""}),t}(e),{prefixes:r="./"}=t,o=`[^${R(t.delimiter||"/#?")}]+?`,i=[];let s=0,a=0,u="";const c=e=>{if(a<n.length&&n[a].type===e)return n[a++].value},l=e=>{const t=c(e);if(void 0!==t)return t;const{type:r,index:o}=n[a];throw new TypeError(`Unexpected ${r} at ${o}, expected ${e}`)},f=()=>{let e,t="";for(;e=c("CHAR")||c("ESCAPED_CHAR");)t+=e;return t};for(;a<n.length;){const e=c("CHAR"),t=c("NAME"),n=c("PATTERN");if(t||n){let a=e||"";-1===r.indexOf(a)&&(u+=a,a=""),u&&(i.push(u),u=""),i.push({name:t||s++,prefix:a,suffix:"",pattern:n||o,modifier:c("MODIFIER")||""});continue}const a=e||c("ESCAPED_CHAR");if(a){u+=a;continue}u&&(i.push(u),u="");if(c("OPEN")){const e=f(),t=c("NAME")||"",n=c("PATTERN")||"",r=f();l("CLOSE"),i.push({name:t||(n?s++:""),pattern:t&&!n?o:n,prefix:e,suffix:r,modifier:c("MODIFIER")||""})}else l("END")}return i}function N(e,t){return function(e,t={}){const n=$(t),{encode:r=(e=>e),validate:o=!0}=t,i=e.map((e=>{if("object"==typeof e)return new RegExp(`^(?:${e.pattern})$`,n)}));return t=>{let n="";for(let s=0;s<e.length;s++){const a=e[s];if("string"==typeof a){n+=a;continue}const u=t?t[a.name]:void 0,c="?"===a.modifier||"*"===a.modifier,l="*"===a.modifier||"+"===a.modifier;if(Array.isArray(u)){if(!l)throw new TypeError(`Expected "${a.name}" to not repeat, but got an array`);if(0===u.length){if(c)continue;throw new TypeError(`Expected "${a.name}" to not be empty`)}for(let e=0;e<u.length;e++){const t=r(u[e],a);if(o&&!i[s].test(t))throw new TypeError(`Expected all "${a.name}" to match "${a.pattern}", but got "${t}"`);n+=a.prefix+t+a.suffix}continue}if("string"==typeof u||"number"==typeof u){const e=r(String(u),a);if(o&&!i[s].test(e))throw new TypeError(`Expected "${a.name}" to match "${a.pattern}", but got "${e}"`);n+=a.prefix+e+a.suffix;continue}if(c)continue;const f=l?"an array":"a string";throw new TypeError(`Expected "${a.name}" to be ${f}`)}return n}}(O(e,t),t)}function _(e,t,n){return function(e,t,n={}){const{strict:r=!1,start:o=!0,end:i=!0,encode:s=(e=>e)}=n,a=`[${R(n.endsWith||"")}]|$`,u=`[${R(n.delimiter||"/#?")}]`;let c=o?"^":"";for(const n of e)if("string"==typeof n)c+=R(s(n));else{const e=R(s(n.prefix)),r=R(s(n.suffix));if(n.pattern)if(t&&t.push(n),e||r)if("+"===n.modifier||"*"===n.modifier){const t="*"===n.modifier?"?":"";c+=`(?:${e}((?:${n.pattern})(?:${r}${e}(?:${n.pattern}))*)${r})${t}`}else c+=`(?:${e}(${n.pattern})${r})${n.modifier}`;else c+=`(${n.pattern})${n.modifier}`;else c+=`(?:${e}${r})${n.modifier}`}if(i)r||(c+=`${u}?`),c+=n.endsWith?`(?=${a})`:"$";else{const t=e[e.length-1],n="string"==typeof t?u.indexOf(t[t.length-1])>-1:void 0===t;r||(c+=`(?:${u}(?=${a}))?`),n||(c+=`(?=${u}|${a})`)}return new RegExp(c,$(n))}(O(e,n),t,n)}function A(e,t,n){return e instanceof RegExp?function(e,t){if(!t)return e;const n=e.source.match(/\((?!\?)/g);if(n)for(let e=0;e<n.length;e++)t.push({name:e,prefix:"",suffix:"",modifier:"",pattern:""});return e}(e,t):Array.isArray(e)?function(e,t,n){const r=e.map((e=>A(e,t,n).source));return new RegExp(`(?:${r.join("|")})`,$(n))}(e,t,n):_(e,t,n)}const{INVALID_ROUTE_QUERY:x,MISSING_ROUTE_TEMPLATE:T,MISSING_PAGE_BINDING:w,INVALID_PAGE_BINDING:D,INVALID_URI_SYNTAX:U}=v;function P(e){const{routes:r,caseSensitive:a}=e;return r.map((e=>function(e,r=!1){const a=[],{uri:u,page:c}=e;I(!!u,T),I(function(e=""){const t=["*","(",")",";"].some((t=>e.indexOf(t)>=0));return!t}(u),U),I(!!c,w);const l=t(u),f=n(u),d=A(l,a,{sensitive:r,end:!1!==e.exact}),p=N(l,{encode:encodeURIComponent}),h=function(e){const t={};return Object.keys(e).forEach((n=>{const r=e[n];I(!o(n)||null===r,x),o(n)?t[n.substr(1)]={routeParamName:n}:r&&o(r)?t[n]={routeParamName:r}:t[n]={literalValue:null===r?null:r}})),t}(f),g=function(e,t=!1){const n=n=>{const r=Object.keys(n),o=Object.keys(e);return o.every((e=>r.indexOf(e)>=0))?o.reduce(((r,o)=>{if(null===r)return null;const{literalValue:i,routeParamName:s}=e[o],a=n[o];let u=!0;return"string"==typeof i?u=t?i===a:i.toUpperCase()===(null==a?a:a.toUpperCase()):null===i&&(u=a===i),r=u?{...r,[o]:{value:a,routeParamName:s}}:null}),{}):null};return n}(h,r),m={original:e,regex:d,params:a,toPath:p,compiledQuery:h,queryMatcher:g};return I(function(e){const{original:{page:t}={},params:n,compiledQuery:r}=e,a=t?t.type:t,u=(t?t.attributes:t)||{},c=(t?t.state:t)||{};if("string"!=typeof a||"object"!=typeof u||"object"!=typeof c)return!1;const l=Object.values(n).map((({name:e})=>e)),f=s(r),d=[...l,...f],p=Object.values(u).filter(o).map(i),h=Object.values(c).filter(o).map(i),g=d.every((e=>"string"==typeof e&&(p.indexOf(e)>=0||h.indexOf(e)>=0))),m=d.length===p.length+h.length;return!!(t&&a&&u&&c&&g&&m)}(m),D),m}(e,a)))}function C(){let e,t,n=[];const r=r=>{n.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{n.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{n.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),n=[],e=void 0,t=void 0},subscribe:(o,i=!0)=>{(e=>{n.push(e)})(o),e&&i&&o.next(e),t&&r(t);const s=n.length-1;return{unsubscribe:()=>(e=>{n=[...n.slice(0,e),...n.slice(e+1)]})(s)}}}}class S{constructor(e){this.deprecatedConfig={},this.routeHandlerId=0,this.compiledRoutes=[],this.routeObservable=C(),this.config={basePath:e.basePath||"",i18n:e.i18n||l,caseSensitive:Boolean(e.caseSensitive),routes:e.routes||[],generateUrl:(e,t)=>p(e,this.compiledRoutes,this.config.basePath,this.config.i18n,t),parseUrl:e=>function(e,t,n="",r=l){const o=d(e,t,n,r);return o&&o.route&&o.route.pageReference?o.route.pageReference:null}(e,this.compiledRoutes,this.config.basePath,this.config.i18n)};const{DEPRECATED_getRouteFromUrl:t,DEPRECATED_getUrlFromRoute:n}=e;t&&(this.deprecatedConfig.DEPRECATED_getRouteFromUrl=t),n&&(this.deprecatedConfig.DEPRECATED_getUrlFromRoute=n),this.compiledRoutes=P(this.config)}generateUrl(e,t){const{DEPRECATED_getUrlFromRoute:n}=this.deprecatedConfig;return n?n(e,this.config.generateUrl,t):this.config.generateUrl(e,t)}parseUrl(e){const{DEPRECATED_getRouteFromUrl:t}=this.deprecatedConfig;return t?t(e,this.config.parseUrl):this.config.parseUrl(e)}matchRoute(e,t){const n="string"==typeof e?e:this.generateUrl(e,t);if(null===n)return null;const r=d(n,this.compiledRoutes,this.config.basePath,this.config.i18n,t),o=r&&g(r.route.pageReference,r.routeDefinition,this.config.basePath,this.config.i18n,t);return r&&o?{pathMatch:o,route:r.route,routeDefinition:r.routeDefinition.original}:null}async resolveView(e,t){return new Promise(((n,r)=>{const o=this.matchRoute(e,t);return o?o.routeDefinition.handler?.().then((e=>{const t=e.default;if(!t)return r(b(v.INVALID_ROUTE_HANDLER,[o.routeDefinition.id]));const i=new t(n);i&&i.update(o.route)})):r(b(v.NO_ROUTE_MATCH,[JSON.stringify(e)]))}))}navigate(e,t){const n=this.matchRoute(e,t);if(!n)throw new Error(b(v.MISSING_ROUTE,[JSON.stringify(e)]));this.pendingRoute={...n},this._mapView(this.pendingRoute)}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}async _mapView(e){const t=Math.random();this.routeHandlerId=t;const n=await(e.routeDefinition.handler?.()),r=n?.default;if(!r)throw new Error(b(v.INVALID_ROUTE_HANDLER,[e.routeDefinition.id]));return this.routeHandler=new r((e=>{this._updateView(t,e)})),this.routeHandler&&this.routeHandler.update(e.route),!0}_updateView(e,t){if(!t||e!==this.routeHandlerId)return;if(!this.pendingRoute)throw new Error("Trying to commit route state without a route");const n=m(t.viewset);this.routeObservable.next({...this.pendingRoute,...t,viewset:n})}}function j(e={}){return new S(e)}export{j as createRouter};
2
2
  //# sourceMappingURL=router.js.map
@@ -1,2 +1,2 @@
1
- import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as r,registerDecorators as s,registerComponent as o,LightningElement as n}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as h,logOperationStart as l}from"lwr/profiler";var u=[function(e,t,i){return"span.router-title"+(e?"["+e+"]":"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}];const p=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,v={key:0},g=[];function m(e,t,i,r){const{s:s,st:o}=e;return[s("",v,g,i),o(p(),2)]}var f=t(m);function E(e){if(null==e)throw new TypeError("Provider must be defined.")}m.slots=[""],m.stylesheets=[],m.renderMode="light",u&&m.stylesheets.push.apply(m.stylesheets,u),m.stylesheetToken="lwc-7bis3qj4jjc",m.legacyStylesheetToken="lwr-routerContainer_routerContainer",i(m);class I{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){E(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){E(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){E(e),this.infoMap.delete(e)}subscribeContext(e,t){E(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){E(e),this.getInfo(e).consumers.delete(t)}}const b="LWR",N=1;function w(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function _(e,t){const i={...e,message:w(e.message,t)};return e.address&&(i.address=w(e.address,t)),e.stack&&(i.stack=w(e.stack,t)),i}function R(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${w(e.message,t)}`}(t,i))}const x={INVALID_MIXIN_CMP:{code:`${b}4001`,message:"{0} must be an Element type",level:N},MISSING_CONTEXT:{code:`${b}4002`,message:"Could not find context to perform navigation action.",level:N},INVALID_CONTEXT:{code:`${b}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:N},MULTIPLE_ROOTS:{code:`${b}4004`,message:"Router connection failed. There can only be one root router.",level:N},MULTIPLE_CHILDREN:{code:`${b}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:N},MISSING_ROUTE:{code:`${b}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:N,address:"{0}"},MISSING_URL:{code:`${b}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:N,address:"{0}"},PRENAV_FAILED:{code:`${b}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${b}4009`,message:'A route definition must contain a "uri" property.',level:N},MISSING_ROUTE_CMP:{code:`${b}4016`,message:"Expected a route view component with a default export.",level:N},MISSING_DATA_CONTEXT:{code:`${b}4018`,message:"Could not find context to retrieve navigation data.",level:N},INVALID_ROUTE_QUERY:{code:`${b}4019`,message:"Invalid query param in route definition.",level:N},MISSING_PAGE_BINDING:{code:`${b}4020`,message:"Route definition must provide page binding",level:N},INVALID_PAGE_BINDING:{code:`${b}4021`,message:"Invalid page binding in route definition",level:N},INVALID_URI_SYNTAX:{code:`${b}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:N},VIEW_IMPORT_FAILED:{code:`${b}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:N,stack:"{2}"},VIEW_MISSING:{code:`${b}4024`,message:'Expected a view with name "{0}" in the viewset',level:N},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${b}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:N,stack:"{3}"},NO_ROUTE_MATCH:{code:`${b}4026`,message:"A routing match cannot be found for: {0}",level:N},INVALID_ROUTE_HANDLER:{code:`${b}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:N},DESTINATION_NOT_FOUND:{code:`${b}4028`,message:"Route handler returned 404: Not Found",level:N},DESTINATION_ERROR:{code:`${b}4029`,message:"Route handler returned error status {0}: {1}",level:N,stack:"{2}"},NO_INIT_URL:{code:`${b}4030`,message:'Cannot initialize a server router without a "url"',level:N}},C=new WeakMap;function T(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,i){e.setContext(t,i)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,i){e.subscribeContext(t,i)}static unsubscribeContext(t,i){e.unsubscribeContext(t,i)}}).contextSchema={value:"required"},t}const P=T(new I(void 0)),y=T(new I(void 0)),S=new I(void 0),A=class extends(T(S)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,o=s&&s.module||r;let n;if(o)try{const e=await o(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;n=s.specifier?_(x.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):_(x.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else n=_(x.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(n)}}};function $(){const e=[],t=t=>{"function"==typeof t&&e.push(t)};return{add:(e=[])=>{Array.isArray(e)?e.forEach((e=>t(e))):t(e)},compile:t=>0===e.length?Promise.resolve(!0):e.reduce(((e,i)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(i(t))))),Promise.resolve(!0)).then((e=>!1!==e)).catch((e=>{if(e instanceof Error)throw e;return!1})),empty:()=>0===e.length}}function M(e=""){return e=e||"",decodeURIComponent(e)}function L(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const O="undefined"!=typeof document,U=`universalcontainergetnavigationcontext${L()}`,D=r(y),k=O?r(A):void 0,F=r(P);function V(e,t,i,r){i&&r&&(r.setContext(t,e),i(t,{consumerConnectedCallback:r.subscribeContext.bind(r,t),consumerDisconnectedCallback:r.unsubscribeContext.bind(r,t)}))}function G(){let e,t,i=[];const r=r=>{i.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{i.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{i.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),i=[],e=void 0,t=void 0},subscribe:(s,o=!0)=>{(e=>{i.push(e)})(s),e&&o&&s.next(e),t&&r(t);const n=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(n)}}}}const W=`universalcontainernavigationevent${L()}`,j=`universalcontainerparentevent${L()}`;class H{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=$(),this.errorNavFilters=$(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:r}=t.detail;this.config.handleNavigation(r,i)?this.root&&!e?this.root.processError(_(x.MISSING_URL,[JSON.stringify(r)])):this.parent||this.process(e,i):t.stopPropagation()}},this._handleParentEvent=e=>{e.stopImmediatePropagation();const t=e;t&&t.detail&&"function"==typeof t.detail&&t.detail(this)},this.config={handleNavigation:e.handleNavigation||(()=>!0)},this.target=i||window,this.router=t,this.router.contextId=this.contextId,this.routeObservable=G()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,i){if(i)this.processError(i);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;h({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},y.setContext(this.target,e.route.pageReference),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),h({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(j,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:e=>this.generateUrl(e),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};C.set(i.id,i)}(this.contextId,e),V(this.contextId,this.target,F,P),V(void 0,this.target,D,y),V(void 0,this.target,k,A),this.router.subscribe((e=>{if(404===e.status)return void this.processError(_(x.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(_(x.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(l({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};A.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),O&&(this.target.addEventListener(W,this._handleNavigationEvent),this.target.addEventListener(j,this._handleParentEvent),this.target.addEventListener(U,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(W,this._handleNavigationEvent),this.target.removeEventListener(j,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{R(!this.child,x.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t){this.eventId=(new Date).getTime().toString(),l({id:c,specifier:this.eventId});try{this.parent||await this.preProcess(e)}catch(e){if(e.code)return this.processError(e),!1;throw e}const i=this.router.parseUrl(e);return i&&this.router.navigate(i),!0}preProcess(e){const t=this.router.parseUrl(e),i=t&&this.router.matchRoute(t);if(!i)return Promise.reject(_(x.MISSING_ROUTE,[e]));this.pendingRoute={url:e,...i};return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(_(x.PRENAV_FAILED,[e]))))}processError(e){l({id:d}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t){let i=this.router.generateUrl(e);if(i){i=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(i)}this._sendEvent(W,{url:i,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){O&&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 B(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",i=`${window.location.protocol}//${window.location.hostname}${t}`,r="/"===e.charAt(0)?"":"/";e=i+r+e}const t={},i=document.createElement("a");i.href=e;const r=i.search.substring(1);return r&&r.split("&").forEach((e=>{const[i,r=""]=e.split("=");t[M(i)]=M(r)})),{href:i.href,origin:`${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`,pathname:i.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),i=t.href.replace(/:\d+/,""),r=t.origin.replace(/:\d+/,"");return i.replace(r,"")}class X extends H{constructor(){super(...arguments),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(O&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&O&&this.catchBrowserUpdate(B(window.location.href))}disconnect(){super.disconnect(),O&&window.removeEventListener("popstate",this.onpopstate)}async process(e,t,i=!0){const r=await super.process(e);return r&&!this.historyDisabled&&i&&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 q=!1;class z extends n{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=O?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};O&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new H(t,i,e):new X(t,i,e),s={addPreNavigate:e=>(r.addPreNavigate(e),s),addPostNavigate:e=>(r.subscribe(e),s),addErrorNavigate:e=>(r.addErrorNavigate(e),s),connect:()=>{r.connect(),R(!q||!!r.parent,x.MULTIPLE_ROOTS),q=q||!r.parent,s.id=r.contextId},disconnect:()=>{q=q&&!!r.parent,r.disconnect()}};return s}(this,e,this.router),this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect())}preNavigate(e){const t=this._createEvent("prenavigate",e,!0);return this.dispatchEvent(t),!t.defaultPrevented}postNavigate(e){this.dispatchEvent(this._createEvent("postnavigate",e));const t=e.routeDefinition.metadata&&e.routeDefinition.metadata.title;t&&(this.currentTitle=t,document.title=t);const i=this.querySelector("span.router-title");i&&(i.innerHTML=this.currentTitle)}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const i=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(i),!i.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,i){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:i})}}z.renderMode="light",s(z,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var Y=o(z,{tmpl:f,sel:"lwr-router-container",apiVersion:60});export{Y as default};
1
+ import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as r,registerDecorators as s,registerComponent as o,LightningElement as n}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as l,logOperationStart as h}from"lwr/profiler";var u=[function(e,t,i){return"span.router-title"+(e?"["+e+"]":"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}];const p=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,v={key:0},g=[];function m(e,t,i,r){const{s:s,st:o}=e;return[s("",v,g,i),o(p(),2)]}var f=t(m);function E(e){if(null==e)throw new TypeError("Provider must be defined.")}m.slots=[""],m.stylesheets=[],m.renderMode="light",u&&m.stylesheets.push.apply(m.stylesheets,u),m.stylesheetToken="lwc-7bis3qj4jjc",m.legacyStylesheetToken="lwr-routerContainer_routerContainer",i(m);class I{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){E(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){E(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){E(e),this.infoMap.delete(e)}subscribeContext(e,t){E(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){E(e),this.getInfo(e).consumers.delete(t)}}const b="LWR",N=1;function w(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function _(e,t){const i={...e,message:w(e.message,t)};return e.address&&(i.address=w(e.address,t)),e.stack&&(i.stack=w(e.stack,t)),i}function R(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${w(e.message,t)}`}(t,i))}const x={INVALID_MIXIN_CMP:{code:`${b}4001`,message:"{0} must be an Element type",level:N},MISSING_CONTEXT:{code:`${b}4002`,message:"Could not find context to perform navigation action.",level:N},INVALID_CONTEXT:{code:`${b}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:N},MULTIPLE_ROOTS:{code:`${b}4004`,message:"Router connection failed. There can only be one root router.",level:N},MULTIPLE_CHILDREN:{code:`${b}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:N},MISSING_ROUTE:{code:`${b}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:N,address:"{0}"},MISSING_URL:{code:`${b}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:N,address:"{0}"},PRENAV_FAILED:{code:`${b}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${b}4009`,message:'A route definition must contain a "uri" property.',level:N},MISSING_ROUTE_CMP:{code:`${b}4016`,message:"Expected a route view component with a default export.",level:N},MISSING_DATA_CONTEXT:{code:`${b}4018`,message:"Could not find context to retrieve navigation data.",level:N},INVALID_ROUTE_QUERY:{code:`${b}4019`,message:"Invalid query param in route definition.",level:N},MISSING_PAGE_BINDING:{code:`${b}4020`,message:"Route definition must provide page binding",level:N},INVALID_PAGE_BINDING:{code:`${b}4021`,message:"Invalid page binding in route definition",level:N},INVALID_URI_SYNTAX:{code:`${b}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:N},VIEW_IMPORT_FAILED:{code:`${b}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:N,stack:"{2}"},VIEW_MISSING:{code:`${b}4024`,message:'Expected a view with name "{0}" in the viewset',level:N},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${b}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:N,stack:"{3}"},NO_ROUTE_MATCH:{code:`${b}4026`,message:"A routing match cannot be found for: {0}",level:N},INVALID_ROUTE_HANDLER:{code:`${b}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:N},DESTINATION_NOT_FOUND:{code:`${b}4028`,message:"Route handler returned 404: Not Found",level:N},DESTINATION_ERROR:{code:`${b}4029`,message:"Route handler returned error status {0}: {1}",level:N,stack:"{2}"},NO_INIT_URL:{code:`${b}4030`,message:'Cannot initialize a server router without a "url"',level:N}},C=new WeakMap;function T(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,i){e.setContext(t,i)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,i){e.subscribeContext(t,i)}static unsubscribeContext(t,i){e.unsubscribeContext(t,i)}}).contextSchema={value:"required"},t}const P=T(new I(void 0)),y=T(new I(void 0)),S=new I(void 0),A=class extends(T(S)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,o=s&&s.module||r;let n;if(o)try{const e=await o(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;n=s.specifier?_(x.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):_(x.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else n=_(x.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(n)}}};function O(){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 $(e=""){return e=e||"",decodeURIComponent(e)}function M(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const L="undefined"!=typeof document,U=`universalcontainergetnavigationcontext${M()}`,D=r(y),k=L?r(A):void 0,F=r(P);function V(e,t,i,r){i&&r&&(r.setContext(t,e),i(t,{consumerConnectedCallback:r.subscribeContext.bind(r,t),consumerDisconnectedCallback:r.unsubscribeContext.bind(r,t)}))}function G(){let e,t,i=[];const r=r=>{i.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{i.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{i.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),i=[],e=void 0,t=void 0},subscribe:(s,o=!0)=>{(e=>{i.push(e)})(s),e&&o&&s.next(e),t&&r(t);const n=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(n)}}}}const W=`universalcontainernavigationevent${M()}`,j=`universalcontainerparentevent${M()}`;class H{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=O(),this.errorNavFilters=O(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:r}=t.detail;this.config.handleNavigation(r,i)?this.root&&!e?this.root.processError(_(x.MISSING_URL,[JSON.stringify(r)])):this.parent||this.process(e,i):t.stopPropagation()}},this._handleParentEvent=e=>{e.stopImmediatePropagation();const t=e;t&&t.detail&&"function"==typeof t.detail&&t.detail(this)},this.config={handleNavigation:e.handleNavigation||(()=>!0)},this.target=i||window,this.router=t,this.router.contextId=this.contextId,this.routeObservable=G()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,i){if(i)this.processError(i);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;l({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},y.setContext(this.target,e.route.pageReference),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),l({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(j,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:(e,t)=>this.generateUrl(e,t),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};C.set(i.id,i)}(this.contextId,e),V(this.contextId,this.target,F,P),V(void 0,this.target,D,y),V(void 0,this.target,k,A),this.router.subscribe((e=>{if(404===e.status)return void this.processError(_(x.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(_(x.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(h({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),L&&(this.target.addEventListener(W,this._handleNavigationEvent),this.target.addEventListener(j,this._handleParentEvent),this.target.addEventListener(U,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(W,this._handleNavigationEvent),this.target.removeEventListener(j,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{R(!this.child,x.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t,i,r){this.eventId=(new Date).getTime().toString(),h({id:c,specifier:this.eventId});try{this.parent||await this.preProcess(e,i)}catch(e){if(e.code)return this.processError(e),!1;throw e}const s=this.router.parseUrl(e);return s&&this.router.navigate(s,i),!0}preProcess(e,t){const i=this.router.parseUrl(e),r=i&&this.router.matchRoute(i,t);if(!r)return Promise.reject(_(x.MISSING_ROUTE,[e]));this.pendingRoute={url:e,...r};return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(_(x.PRENAV_FAILED,[e]))))}processError(e){h({id:d}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t,i){const r=this.filterNavigateOptions(i);let s=this.router.generateUrl(e,r);if(s){s=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(s)}this._sendEvent(W,{url:s,replace:t,address:e})}generateUrl(e,t){const i=this.filterNavigateOptions(t),r=this.router.generateUrl(e,i);if(!r)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${r}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){L&&this.target.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_stripUrlForChild(e){return this.pendingRoute&&0===e.indexOf(this.pendingRoute.pathMatch)?e.replace(this.pendingRoute.pathMatch,""):e}filterNavigateOptions(e){const t=!this.parent;return{...e,locale:t?e?.locale:void 0}}}function B(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",i=`${window.location.protocol}//${window.location.hostname}${t}`,r="/"===e.charAt(0)?"":"/";e=i+r+e}const t={},i=document.createElement("a");i.href=e;const r=i.search.substring(1);return r&&r.split("&").forEach((e=>{const[i,r=""]=e.split("=");t[$(i)]=$(r)})),{href:i.href,origin:`${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`,pathname:i.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),i=t.href.replace(/:\d+/,""),r=t.origin.replace(/:\d+/,"");return i.replace(r,"")}class X extends H{constructor(){super(...arguments),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(L&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&L&&this.catchBrowserUpdate(B(window.location.href))}disconnect(){super.disconnect(),L&&window.removeEventListener("popstate",this.onpopstate)}async process(e,t,i,r=!0){const s=await super.process(e,t,i,r);return s&&!this.historyDisabled&&r&&this.connected&&!this.parent&&(t?function(e,t){const i=t||{};window.history.replaceState(i,"",e)}(e):function(e,t){const i=t||{};window.history.pushState(i,"",e)}(e)),s}catchBrowserUpdate(e){this.process(e,!1,{},!1)}}let q=!1;class z extends n{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=L?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};L&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new H(t,i,e):new X(t,i,e),s={addPreNavigate:e=>(r.addPreNavigate(e),s),addPostNavigate:e=>(r.subscribe(e),s),addErrorNavigate:e=>(r.addErrorNavigate(e),s),connect:()=>{r.connect(),R(!q||!!r.parent,x.MULTIPLE_ROOTS),q=q||!r.parent,s.id=r.contextId},disconnect:()=>{q=q&&!!r.parent,r.disconnect()}};return s}(this,e,this.router),this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect())}preNavigate(e){const t=this._createEvent("prenavigate",e,!0);return this.dispatchEvent(t),!t.defaultPrevented}postNavigate(e){this.dispatchEvent(this._createEvent("postnavigate",e));const t=e.routeDefinition.metadata&&e.routeDefinition.metadata.title;t&&(this.currentTitle=t,document.title=t);const i=this.querySelector("span.router-title");i&&(i.innerHTML=this.currentTitle)}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const i=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(i),!i.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,i){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:i})}}z.renderMode="light",s(z,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var Y=o(z,{tmpl:f,sel:"lwr-router-container",apiVersion:61});export{Y as default};
2
2
  //# sourceMappingURL=routerContainer.js.map
@@ -116,7 +116,7 @@ var DomRouterImpl = class {
116
116
  });
117
117
  const contextApi = {
118
118
  navigate: (address, replace) => this.navigate(address, replace),
119
- generateUrl: (address) => this.generateUrl(address),
119
+ generateUrl: (address, options) => this.generateUrl(address, options),
120
120
  subscribe: (callback, replay) => this.subscribe(callback, replay)
121
121
  };
122
122
  (0, import_navigation.registerNavigationHelm)(this.contextId, contextApi);
@@ -197,12 +197,12 @@ var DomRouterImpl = class {
197
197
  }
198
198
  }
199
199
  }
200
- async process(url, replace) {
200
+ async process(url, _shouldReplace, options, _updateHistory) {
201
201
  this.eventId = new Date().getTime().toString();
202
202
  (0, import_profiler.logOperationStart)({id: import_metrics.ROUTER_NAV, specifier: this.eventId});
203
203
  try {
204
204
  if (!this.parent) {
205
- await this.preProcess(url);
205
+ await this.preProcess(url, options);
206
206
  }
207
207
  } catch (e) {
208
208
  if (e.code) {
@@ -213,13 +213,13 @@ var DomRouterImpl = class {
213
213
  }
214
214
  const address = this.router.parseUrl(url);
215
215
  if (address) {
216
- this.router.navigate(address);
216
+ this.router.navigate(address, options);
217
217
  }
218
218
  return true;
219
219
  }
220
- preProcess(url) {
220
+ preProcess(url, options) {
221
221
  const address = this.router.parseUrl(url);
222
- const routingMatch = address && this.router.matchRoute(address);
222
+ const routingMatch = address && this.router.matchRoute(address, options);
223
223
  if (!routingMatch) {
224
224
  return Promise.reject((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.MISSING_ROUTE, [url]));
225
225
  }
@@ -241,16 +241,18 @@ var DomRouterImpl = class {
241
241
  this.child.processError(messageObject);
242
242
  }
243
243
  }
244
- navigate(address, replace) {
245
- let url = this.router.generateUrl(address);
244
+ navigate(address, replace, options) {
245
+ const routerOptions = this.filterNavigateOptions(options);
246
+ let url = this.router.generateUrl(address, routerOptions);
246
247
  if (url) {
247
248
  const parentPath = this.parent && this.parent.committedRoute && this.parent.committedRoute.pathMatch || "";
248
249
  url = parentPath.concat(url);
249
250
  }
250
251
  this._sendEvent(NAV_EVENT, {url, replace, address});
251
252
  }
252
- generateUrl(address) {
253
- const url = this.router.generateUrl(address);
253
+ generateUrl(address, options) {
254
+ const routerOptions = this.filterNavigateOptions(options);
255
+ const url = this.router.generateUrl(address, routerOptions);
254
256
  if (!url) {
255
257
  return null;
256
258
  }
@@ -279,6 +281,14 @@ var DomRouterImpl = class {
279
281
  }
280
282
  return url;
281
283
  }
284
+ filterNavigateOptions(options) {
285
+ const isRoot = !this.parent;
286
+ const routerOptions = {
287
+ ...options,
288
+ locale: isRoot ? options?.locale : void 0
289
+ };
290
+ return routerOptions;
291
+ }
282
292
  };
283
293
  function createDomRouter(config, router, target) {
284
294
  return new DomRouterImpl(config, router, target);
@@ -51,8 +51,8 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
51
51
  super.disconnect();
52
52
  import_routerUtils.hasDocument && window.removeEventListener("popstate", this.onpopstate);
53
53
  }
54
- async process(url, shouldReplace, updateHistory = true) {
55
- const canContinue = await super.process(url);
54
+ async process(url, shouldReplace, options, updateHistory = true) {
55
+ const canContinue = await super.process(url, shouldReplace, options, updateHistory);
56
56
  if (canContinue && !this.historyDisabled && updateHistory && this.connected && !this.parent) {
57
57
  if (shouldReplace) {
58
58
  (0, import_domRouterUtils.replace)(url);
@@ -63,7 +63,7 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
63
63
  return canContinue;
64
64
  }
65
65
  catchBrowserUpdate(url) {
66
- this.process(url, false, false);
66
+ this.process(url, false, {}, false);
67
67
  }
68
68
  };
69
69
  function createHistoryRouter(config, router, target) {
@@ -28,11 +28,11 @@ __export(exports, {
28
28
  navigate: () => navigate
29
29
  });
30
30
  var import_contextUtils = __toModule(require("lwr/contextUtils"));
31
- function navigate(context, pageReference, replace) {
31
+ function navigate(context, pageReference, replace, options) {
32
32
  const api = (0, import_contextUtils.getNavigationHelm)(context);
33
- api.navigate(pageReference, replace);
33
+ api.navigate(pageReference, replace, options);
34
34
  }
35
- function generateUrl(context, pageReference) {
35
+ function generateUrl(context, pageReference, options) {
36
36
  const api = (0, import_contextUtils.getNavigationHelm)(context);
37
- return api.generateUrl(pageReference);
37
+ return api.generateUrl(pageReference, options);
38
38
  }
@@ -55,16 +55,16 @@ function NavigationMixin(Base) {
55
55
  }
56
56
  }
57
57
  }
58
- [Navigate](pageRef, replace) {
58
+ [Navigate](pageRef, replace, options) {
59
59
  if (!isSSR) {
60
60
  this[GetContext]();
61
- (0, import_navigationApi.navigate)(this[NavContext], pageRef, replace);
61
+ (0, import_navigationApi.navigate)(this[NavContext], pageRef, replace, options);
62
62
  }
63
63
  }
64
- async [GenerateUrl](pageRef) {
64
+ async [GenerateUrl](pageRef, options) {
65
65
  if (!isSSR) {
66
66
  this[GetContext]();
67
- return (0, import_navigationApi.generateUrl)(this[NavContext], pageRef);
67
+ return (0, import_navigationApi.generateUrl)(this[NavContext], pageRef, options);
68
68
  } else {
69
69
  return null;
70
70
  }
@@ -37,10 +37,11 @@ var RouterImpl = class {
37
37
  this.routeObservable = (0, import_observable.createObservable)();
38
38
  this.config = {
39
39
  basePath: config.basePath || "",
40
+ i18n: config.i18n || import_routerUtils.DEFAULT_I18N_ROUTER_CONFIG,
40
41
  caseSensitive: Boolean(config.caseSensitive),
41
42
  routes: config.routes || [],
42
- generateUrl: (address) => (0, import_routerUtils.getUrlFromPageReference)(address, this.compiledRoutes, this.config.basePath),
43
- parseUrl: (url) => (0, import_routerUtils.getPageReferenceFromUrl)(url, this.compiledRoutes, this.config.basePath)
43
+ generateUrl: (address, options) => (0, import_routerUtils.getUrlFromPageReference)(address, this.compiledRoutes, this.config.basePath, this.config.i18n, options),
44
+ parseUrl: (url) => (0, import_routerUtils.getPageReferenceFromUrl)(url, this.compiledRoutes, this.config.basePath, this.config.i18n)
44
45
  };
45
46
  const {DEPRECATED_getRouteFromUrl, DEPRECATED_getUrlFromRoute} = config;
46
47
  if (DEPRECATED_getRouteFromUrl) {
@@ -51,12 +52,12 @@ var RouterImpl = class {
51
52
  }
52
53
  this.compiledRoutes = (0, import_routerUtils.parseRoutes)(this.config);
53
54
  }
54
- generateUrl(address) {
55
+ generateUrl(address, options) {
55
56
  const {DEPRECATED_getUrlFromRoute: getUrlFromRoute} = this.deprecatedConfig;
56
57
  if (getUrlFromRoute) {
57
- return getUrlFromRoute(address, this.config.generateUrl);
58
+ return getUrlFromRoute(address, this.config.generateUrl, options);
58
59
  } else {
59
- return this.config.generateUrl(address);
60
+ return this.config.generateUrl(address, options);
60
61
  }
61
62
  }
62
63
  parseUrl(url) {
@@ -67,13 +68,13 @@ var RouterImpl = class {
67
68
  return this.config.parseUrl(url);
68
69
  }
69
70
  }
70
- matchRoute(address) {
71
- const url = typeof address === "string" ? address : this.generateUrl(address);
71
+ matchRoute(address, options) {
72
+ const url = typeof address === "string" ? address : this.generateUrl(address, options);
72
73
  if (url === null) {
73
74
  return null;
74
75
  }
75
- const match = (0, import_routerUtils.matchRouteByUrl)(url, this.compiledRoutes, this.config.basePath);
76
- const pathMatch = match && (0, import_routerUtils.getUrlFromPageReferenceAndRouteDef)(match.route.pageReference, match.routeDefinition, this.config.basePath);
76
+ const match = (0, import_routerUtils.matchRouteByUrl)(url, this.compiledRoutes, this.config.basePath, this.config.i18n, options);
77
+ const pathMatch = match && (0, import_routerUtils.getUrlFromPageReferenceAndRouteDef)(match.route.pageReference, match.routeDefinition, this.config.basePath, this.config.i18n, options);
77
78
  if (!match || !pathMatch) {
78
79
  return null;
79
80
  }
@@ -83,9 +84,9 @@ var RouterImpl = class {
83
84
  routeDefinition: match.routeDefinition.original
84
85
  };
85
86
  }
86
- async resolveView(address) {
87
+ async resolveView(address, options) {
87
88
  return new Promise((resolve, reject) => {
88
- const routingMatch = this.matchRoute(address);
89
+ const routingMatch = this.matchRoute(address, options);
89
90
  if (!routingMatch) {
90
91
  return reject((0, import_routerErrors.generateMessage)(import_routerErrors.messages.NO_ROUTE_MATCH, [JSON.stringify(address)]));
91
92
  }
@@ -101,8 +102,8 @@ var RouterImpl = class {
101
102
  });
102
103
  });
103
104
  }
104
- navigate(address) {
105
- const routingMatch = this.matchRoute(address);
105
+ navigate(address, options) {
106
+ const routingMatch = this.matchRoute(address, options);
106
107
  if (!routingMatch) {
107
108
  throw new Error((0, import_routerErrors.generateMessage)(import_routerErrors.messages.MISSING_ROUTE, [JSON.stringify(address)]));
108
109
  }
@@ -24,6 +24,7 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/router/src/modules/lwr/routerUtils/routeUtils.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
+ DEFAULT_I18N_ROUTER_CONFIG: () => DEFAULT_I18N_ROUTER_CONFIG,
27
28
  getPageReferenceFromUrl: () => getPageReferenceFromUrl,
28
29
  getUrlFromPageReference: () => getUrlFromPageReference,
29
30
  getUrlFromPageReferenceAndRouteDef: () => getUrlFromPageReferenceAndRouteDef,
@@ -31,6 +32,10 @@ __export(exports, {
31
32
  });
32
33
  var import_uriUtils = __toModule(require("./uriUtils"));
33
34
  var import_routeDefUtils = __toModule(require("./routeDefUtils"));
35
+ var DEFAULT_I18N_ROUTER_CONFIG = {
36
+ locale: "en-US",
37
+ defaultLocale: "en-US"
38
+ };
34
39
  function isRoutePatternsMatched(path, queryObj, routeDef) {
35
40
  const {original: {patterns = null} = {}} = routeDef || {};
36
41
  if (patterns) {
@@ -59,10 +64,16 @@ function getRouteDefinitionForUri(uri, routeDefs) {
59
64
  });
60
65
  return matched || null;
61
66
  }
62
- function matchRouteByUrl(url, routeDefs, basePath = "") {
63
- if (basePath && url.indexOf(basePath) === 0) {
67
+ function matchRouteByUrl(url, routeDefs, basePath = "", i18n = DEFAULT_I18N_ROUTER_CONFIG, options) {
68
+ if (basePath && url?.indexOf(basePath) === 0) {
64
69
  url = url.replace(basePath, "");
65
70
  }
71
+ if (options?.locale || i18n?.locale) {
72
+ const localePath = `/${options?.locale || i18n.locale}`;
73
+ if (url?.indexOf(localePath) === 0) {
74
+ url = url.replace(localePath, "");
75
+ }
76
+ }
66
77
  const routeDef = getRouteDefinitionForUri(url, routeDefs);
67
78
  let matchInfo;
68
79
  if (!routeDef) {
@@ -89,10 +100,10 @@ function matchRouteByUrl(url, routeDefs, basePath = "") {
89
100
  }
90
101
  return null;
91
102
  }
92
- function getUrlFromPageReference(pageReference, routeDefs, basePath = "") {
103
+ function getUrlFromPageReference(pageReference, routeDefs, basePath = "", i18n = DEFAULT_I18N_ROUTER_CONFIG, options) {
93
104
  const routeDef = (0, import_routeDefUtils.matchRouteDefinitionByPageReference)(pageReference, routeDefs);
94
105
  if (routeDef) {
95
- return getUrlFromPageReferenceAndRouteDef(pageReference, routeDef, basePath);
106
+ return getUrlFromPageReferenceAndRouteDef(pageReference, routeDef, basePath, i18n, options);
96
107
  }
97
108
  return null;
98
109
  }
@@ -117,7 +128,7 @@ function extractBindingValues(parameters, pageReference, pageBindings) {
117
128
  });
118
129
  return parameterValueMapping;
119
130
  }
120
- function getUrlFromPageReferenceAndRouteDef(pageReference, routeDef, basePath = "") {
131
+ function getUrlFromPageReferenceAndRouteDef(pageReference, routeDef, basePath = "", i18n = DEFAULT_I18N_ROUTER_CONFIG, options) {
121
132
  const {params, original: {page = {}} = {}, toPath, compiledQuery} = routeDef;
122
133
  const {attributes: attributeBindings = {}, state: stateBindings = {}} = page;
123
134
  const pathParamNames = params.filter(({name}) => {
@@ -137,7 +148,9 @@ function getUrlFromPageReferenceAndRouteDef(pageReference, routeDef, basePath =
137
148
  });
138
149
  const queryObject = getQueryObjectForParametersAndPageReference(pageReference, queryParameters, routeDef);
139
150
  const queryString = (0, import_uriUtils.getQueryString)(queryObject);
140
- return `${basePath}${toPathUrl}${queryString}`;
151
+ const locale = options?.locale || i18n && i18n.locale;
152
+ const localePart = locale !== i18n.defaultLocale ? `/${locale}` : "";
153
+ return `${basePath}${localePart}${toPathUrl}${queryString}`;
141
154
  }
142
155
  function getQueryObjectForParametersAndPageReference(pageReference, queryParameters, routeDef) {
143
156
  const {
@@ -170,8 +183,8 @@ function getQueryObjectForParametersAndPageReference(pageReference, queryParamet
170
183
  ...queryParamKeyValueMap
171
184
  };
172
185
  }
173
- function getPageReferenceFromUrl(url, routeDefs, basePath = "") {
174
- const routingMatch = matchRouteByUrl(url, routeDefs, basePath);
186
+ function getPageReferenceFromUrl(url, routeDefs, basePath = "", i18n = DEFAULT_I18N_ROUTER_CONFIG) {
187
+ const routingMatch = matchRouteByUrl(url, routeDefs, basePath, i18n);
175
188
  if (routingMatch && routingMatch.route && routingMatch.route.pageReference) {
176
189
  return routingMatch.route.pageReference;
177
190
  }
@@ -24,6 +24,7 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/router/src/modules/lwr/routerUtils/routerUtils.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
+ DEFAULT_I18N_ROUTER_CONFIG: () => import_routeUtils.DEFAULT_I18N_ROUTER_CONFIG,
27
28
  createFilterChain: () => import_filterUtils.createFilterChain,
28
29
  decode: () => import_uriUtils.decode,
29
30
  encode: () => import_uriUtils.encode,
@@ -45,19 +45,19 @@ var ServerRouter = class {
45
45
  this.errorNavHook = config.errorNavigate;
46
46
  this.initWires(config.url);
47
47
  }
48
- async navigate(address) {
48
+ async navigate(address, _replace, options) {
49
49
  if (import_routerUtils.hasDocument) {
50
50
  if (this.handleNavHook && !this.handleNavHook(address)) {
51
51
  return;
52
52
  }
53
- const url = await this.getValidatedUrl(address);
53
+ const url = await this.getValidatedUrl(address, options);
54
54
  if (url) {
55
55
  document.location.href = url;
56
56
  }
57
57
  }
58
58
  }
59
- generateUrl(address) {
60
- return this.router.generateUrl(address);
59
+ generateUrl(address, options) {
60
+ return this.router.generateUrl(address, options);
61
61
  }
62
62
  initWires(url) {
63
63
  if (!url && import_routerUtils.hasDocument) {
@@ -68,15 +68,15 @@ var ServerRouter = class {
68
68
  return;
69
69
  }
70
70
  url = this.getRelativeUrl(url);
71
- const routingMatch = this.router.matchRoute(url);
71
+ const routingMatch = this.router.matchRoute(url, {});
72
72
  if (!routingMatch) {
73
73
  this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.MISSING_ROUTE, [url]));
74
74
  return;
75
75
  }
76
76
  this.currentRoute = routingMatch;
77
77
  (0, import_navigation.registerNavigationHelm)(this.contextId, {
78
- navigate: (address) => this.navigate(address),
79
- generateUrl: (address) => this.generateUrl(address),
78
+ navigate: (address, replace, options) => this.navigate(address, replace, options),
79
+ generateUrl: (address, options) => this.generateUrl(address, options),
80
80
  subscribe: () => {
81
81
  throw new Error("The server router does not support the subscribe API");
82
82
  }
@@ -99,8 +99,8 @@ var ServerRouter = class {
99
99
  }
100
100
  return url;
101
101
  }
102
- async getValidatedUrl(address) {
103
- const routingMatch = this.router.matchRoute(address);
102
+ async getValidatedUrl(address, options) {
103
+ const routingMatch = this.router.matchRoute(address, {});
104
104
  if (!routingMatch) {
105
105
  this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.NO_ROUTE_MATCH, [JSON.stringify(address)]));
106
106
  return;
@@ -113,7 +113,7 @@ var ServerRouter = class {
113
113
  this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.PRENAV_FAILED, [JSON.stringify(address)]));
114
114
  return;
115
115
  }
116
- return this.router.generateUrl(address);
116
+ return this.router.generateUrl(address, options);
117
117
  }
118
118
  processError(messageObject) {
119
119
  (0, import_profiler.logOperationStart)({id: import_metrics.ROUTER_ERROR});
@@ -79,7 +79,6 @@ var RouteDefinitionSchema = {
79
79
  type: "object",
80
80
  properties: {
81
81
  schema: {type: "string", pattern: `^${DEFAULT_SCHEMA}$`},
82
- basePath: {type: "string", minLength: 1},
83
82
  caseSensitive: {type: "boolean"},
84
83
  routes: {
85
84
  type: "array",