@lwrjs/router 0.15.0-alpha.9 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bundle/prod/lwr/navigation/navigation.js +1 -1
- package/build/bundle/prod/lwr/router/router.js +1 -1
- package/build/bundle/prod/lwr/routerContainer/routerContainer.js +1 -1
- package/build/cjs/modules/lwr/routerErrors/routerErrors.cjs +12 -8
- package/build/cjs/modules/lwr/routerUtils/parseUtils.cjs +5 -5
- package/build/cjs/modules/lwr/routerUtils/routeUtils.cjs +2 -2
- package/build/cjs/modules/lwr/serverRouter/serverRouter.cjs +1 -6
- package/build/es/modules/lwr/contextProvider/contextProvider.js +1 -1
- package/build/es/modules/lwr/routerErrors/routerErrors.js +8 -4
- package/build/es/modules/lwr/routerUtils/parseUtils.js +6 -6
- package/build/es/modules/lwr/routerUtils/routeUtils.js +2 -2
- package/build/es/modules/lwr/serverRouter/serverRouter.js +3 -7
- package/build/modules/lwr/contextProvider/contextProvider.js +1 -1
- package/build/modules/lwr/contextProvider/contextProvider.js-meta.xml +6 -0
- package/build/modules/lwr/contextUtils/contextUtils.js-meta.xml +6 -0
- package/build/modules/lwr/currentPageReference/currentPageReference.js-meta.xml +6 -0
- package/build/modules/lwr/currentView/currentView.js-meta.xml +6 -0
- package/build/modules/lwr/domRouter/domRouter.js-meta.xml +6 -0
- package/build/modules/lwr/domRouterUtils/domRouterUtils.js-meta.xml +6 -0
- package/build/modules/lwr/historyRouter/historyRouter.js-meta.xml +6 -0
- package/build/modules/lwr/navigation/navigation.js-meta.xml +1 -1
- package/build/modules/lwr/navigationContext/navigationContext.js-meta.xml +6 -0
- package/build/modules/lwr/navigationMixinHacks/navigationMixinHacks.js-meta.xml +6 -0
- package/build/modules/lwr/observable/observable.js-meta.xml +6 -0
- package/build/modules/lwr/outlet/outlet.js-meta.xml +1 -1
- package/build/modules/lwr/router/router.js-meta.xml +1 -1
- package/build/modules/lwr/routerBridge/routerBridge.js-meta.xml +1 -1
- package/build/modules/lwr/routerContainer/routerContainer.js-meta.xml +1 -1
- package/build/modules/lwr/routerErrors/routerErrors.js +12 -8
- package/build/modules/lwr/routerErrors/routerErrors.js-meta.xml +6 -0
- package/build/modules/lwr/routerUtils/parseUtils.js +6 -5
- package/build/modules/lwr/routerUtils/routeUtils.js +2 -2
- package/build/modules/lwr/routerUtils/routerUtils.js-meta.xml +6 -0
- package/build/modules/lwr/serverRouter/serverRouter.js +3 -7
- package/build/modules/lwr/serverRouter/serverRouter.js-meta.xml +6 -0
- package/package.json +8 -8
|
@@ -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,
|
|
1
|
+
function e(e){if(null==e)throw new TypeError("Provider must be defined.")}class t{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(t,n){e(t);const o=n,s=this.getInfo(t);s.contextValue=n,s.consumers.forEach((e=>e.provide(o))),0===s.consumers.size&&o?.onComplete&&o.onComplete()}getContext(t){e(t);const{contextValue:n}=this.getInfo(t);return void 0!==n?n:this.defaultValue}clearContext(t){e(t),this.infoMap.delete(t)}subscribeContext(t,n){e(t);const{consumers:o,contextValue:s}=this.getInfo(t);o.has(n)||(o.add(n),n.provide(s))}unsubscribeContext(t,n){e(t),this.getInfo(t).consumers.delete(n)}}const n="LWR",o=1;function s(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}function a(e,t){return`${e.code}: ${s(e.message,t)}`}function i(e,t){const n={...e,message:s(e.message,t)};return e.address&&(n.address=s(e.address,t)),e.stack&&(n.stack=s(e.stack,t)),n}const r={INVALID_MIXIN_CMP:{code:`${n}4001`,message:"{0} must be an Element type",level:o},MISSING_CONTEXT:{code:`${n}4002`,message:"Could not find context to perform navigation action.",level:o},INVALID_CONTEXT:{code:`${n}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:o},MULTIPLE_ROOTS:{code:`${n}4004`,message:"Router connection failed. There can only be one root router.",level:o},MULTIPLE_CHILDREN:{code:`${n}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:o},MISSING_ROUTE:{code:`${n}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:o,address:"{0}"},MISSING_URL:{code:`${n}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:o,address:"{0}"},PRENAV_FAILED:{code:`${n}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${n}4009`,message:'Route definition with id "{0}" is missing a "uri" property.',level:o,address:"{0}"},MISSING_ROUTE_CMP:{code:`${n}4016`,message:"Expected a route view component with a default export.",level:o},MISSING_DATA_CONTEXT:{code:`${n}4018`,message:"Could not find context to retrieve navigation data.",level:o},INVALID_ROUTE_QUERY:{code:`${n}4019`,message:"Invalid query param in route definition.",level:o},MISSING_PAGE_BINDING:{code:`${n}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:o,address:"{0}"},INVALID_PAGE_BINDING:{code:`${n}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:o,address:"{0}"},INVALID_URI_SYNTAX:{code:`${n}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:o,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${n}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:o,stack:"{2}"},VIEW_MISSING:{code:`${n}4024`,message:'Expected a view with name "{0}" in the viewset',level:o},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${n}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:o,stack:"{3}"},NO_ROUTE_MATCH:{code:`${n}4026`,message:"A routing match cannot be found for: {0}",level:o},INVALID_ROUTE_HANDLER:{code:`${n}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:o},DESTINATION_NOT_FOUND:{code:`${n}4028`,message:"Route handler returned 404: Not Found",level:o},DESTINATION_ERROR:{code:`${n}4029`,message:"Route handler returned error status {0}: {1}",level:o,stack:"{2}"},NO_INIT_URL:{code:`${n}4030`,message:'Cannot initialize a server router without a "url"',level:o}},c=new WeakMap;function l(e){const t=c.get(e);if(!t||!t.value)throw new Error(a(r.MISSING_CONTEXT));return t.value}function d(e,t){const n={id:e,value:t,update:e=>{n.value=e}};return c.set(n.id,n),n}function u(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,n){e.setContext(t,n)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,n){e.subscribeContext(t,n)}static unsubscribeContext(t,n){e.unsubscribeContext(t,n)}}).contextSchema={value:"required"},t}const I=u(new t(void 0)),v=u(new t(void 0)),g=new t(void 0),m=class extends(u(g)){async update(e,t){if(t){const n=e&&e.viewName?e.viewName:"default",o=t.viewset[n],s=o,a=s&&s.module||o;let c;if(a)try{const e=await a(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;c=s.specifier?i(r.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,n,t.message,t.stack||""]):i(r.VIEW_IMPORT_FAILED,[n,t.message,t.stack||""])}else c=i(r.VIEW_MISSING,[n]);t.onComplete&&t.onComplete(c)}}};function h(e,t,n,o){l(e).navigate(t,n,o)}function f(e,t,n){return l(e).generateUrl(t,n)}const E=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,_="undefined"==typeof window,N=Symbol("Navigate"),p=Symbol("GenerateUrl"),w=Symbol("NavContext"),C=Symbol("NavContext");function T(e){!function(e,t,n){if(!e)throw new Error(a(t,n))}("function"==typeof e.prototype.dispatchEvent,r.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[C](){if(!this[w]&&(this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{callback:e=>{this[w]=e}}})),!this[w]))throw new Error(a(r.MISSING_CONTEXT))}[N](e,t,n){_||(this[C](),h(this[w],e,t,n))}async[p](e,t){return _?null:(this[C](),f(this[w],e,t))}}}T.Navigate=N,T.GenerateUrl=p,T.NavContext=w;export{t as ContextInfo,v as CurrentPageReference,m as CurrentView,I as NavigationContext,T as NavigationMixin,u as generateContextualWireAdapter,f as generateUrl,l as getNavigationHelm,h as navigate,d as registerNavigationHelm};
|
|
2
2
|
//# sourceMappingURL=navigation.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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};
|
|
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 c(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 u(e,r){if(r){const{original:{page:{type:i="",attributes:s={},state:u={}}={}}={}}=r,l=t(e),f=n(e),d=a(l,r),p=c(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(u).forEach((t=>{const r=u[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))):[],[u]=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),...c(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 u||null}function d(e,t,n="",r=l,o){if(!n||e!==n&&0!==e?.search(new RegExp(`^${n}[/?#]`))||(e=e.replace(n,"")),o?.locale||r?.locale){const t=`/${o?.locale||r.locale}`;e!==t&&0!==e?.search(new RegExp(`^${t}[/?#]`))||(e=e.replace(t,""))}const i=f(e,t);let s;if(!i)return null;{const t=u(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,c=t===n,u=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 c&&u&&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,c={};return e.forEach((e=>{const[t]=Object.keys(r).filter((t=>i(r[t])===e));if(t)c[e]=s[t];else{const[t]=Object.keys(o).filter((t=>i(o[t])===e));t&&(c[e]=a[t])}})),c}function g(e,t,n="",a=l,c){const{params:u,original:{page:f={}}={},toPath:d,compiledQuery:p}=t,{attributes:g={},state:m={}}=f,E=d(h(u.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||{},c={};Object.keys(a).filter((e=>!o(s[e]))).forEach((e=>c[e]=a[e]));const u={};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){u[o]=n}})),{...c,...u}}(e,h(s(p),e,{attributeBindings:g,stateBindings:m}),t),b=r(y),R=c?.locale||a&&a.locale;return`${n}${R!==a.defaultLocale?`/${R}`:""}${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 Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}function R(e,t){return`${e.code}: ${b(e.message,t)}`}function I(e,t){const n={...e,message:b(e.message,t)};return e.address&&(n.address=b(e.address,t)),e.stack&&(n.stack=b(e.stack,t)),n}function v(e,t,n){if(!e)throw new Error(R(t,n))}const $={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:'Route definition with id "{0}" is missing a "uri" property.',level:y,address:"{0}"},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 with id "{0}" is missing a "page" binding.',level:y,address:"{0}"},INVALID_PAGE_BINDING:{code:`${E}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:y,address:"{0}"},INVALID_URI_SYNTAX:{code:`${E}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:y,address:"{0}"},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 O(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function N(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=`[^${O(t.delimiter||"/#?")}]+?`,i=[];let s=0,a=0,c="";const u=e=>{if(a<n.length&&n[a].type===e)return n[a++].value},l=e=>{const t=u(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=u("CHAR")||u("ESCAPED_CHAR");)t+=e;return t};for(;a<n.length;){const e=u("CHAR"),t=u("NAME"),n=u("PATTERN");if(t||n){let a=e||"";-1===r.indexOf(a)&&(c+=a,a=""),c&&(i.push(c),c=""),i.push({name:t||s++,prefix:a,suffix:"",pattern:n||o,modifier:u("MODIFIER")||""});continue}const a=e||u("ESCAPED_CHAR");if(a){c+=a;continue}c&&(i.push(c),c="");if(u("OPEN")){const e=f(),t=u("NAME")||"",n=u("PATTERN")||"",r=f();l("CLOSE"),i.push({name:t||(n?s++:""),pattern:t&&!n?o:n,prefix:e,suffix:r,modifier:u("MODIFIER")||""})}else l("END")}return i}function w(e,t){return function(e,t={}){const n=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 c=t?t[a.name]:void 0,u="?"===a.modifier||"*"===a.modifier,l="*"===a.modifier||"+"===a.modifier;if(Array.isArray(c)){if(!l)throw new TypeError(`Expected "${a.name}" to not repeat, but got an array`);if(0===c.length){if(u)continue;throw new TypeError(`Expected "${a.name}" to not be empty`)}for(let e=0;e<c.length;e++){const t=r(c[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 c||"number"==typeof c){const e=r(String(c),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(u)continue;const f=l?"an array":"a string";throw new TypeError(`Expected "${a.name}" to be ${f}`)}return n}}(_(e,t),t)}function x(e,t,n){return function(e,t,n={}){const{strict:r=!1,start:o=!0,end:i=!0,encode:s=e=>e}=n,a=`[${O(n.endsWith||"")}]|$`,c=`[${O(n.delimiter||"/#?")}]`;let u=o?"^":"";for(const n of e)if("string"==typeof n)u+=O(s(n));else{const e=O(s(n.prefix)),r=O(s(n.suffix));if(n.pattern)if(t&&t.push(n),e||r)if("+"===n.modifier||"*"===n.modifier){const t="*"===n.modifier?"?":"";u+=`(?:${e}((?:${n.pattern})(?:${r}${e}(?:${n.pattern}))*)${r})${t}`}else u+=`(?:${e}(${n.pattern})${r})${n.modifier}`;else u+=`(${n.pattern})${n.modifier}`;else u+=`(?:${e}${r})${n.modifier}`}if(i)r||(u+=`${c}?`),u+=n.endsWith?`(?=${a})`:"$";else{const t=e[e.length-1],n="string"==typeof t?c.indexOf(t[t.length-1])>-1:void 0===t;r||(u+=`(?:${c}(?=${a}))?`),n||(u+=`(?=${c}|${a})`)}return new RegExp(u,N(n))}(_(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(n))}(e,t,n):x(e,t,n)}const{INVALID_ROUTE_QUERY:T,MISSING_ROUTE_TEMPLATE:D,MISSING_PAGE_BINDING:U,INVALID_PAGE_BINDING:P,INVALID_URI_SYNTAX:C}=$;function S(e){const{routes:r,caseSensitive:a}=e;return r.map((e=>function(e,r=!1){const a=[],{id:c,uri:u,page:l}=e;v(!!u,I(D,[c])),v(function(e=""){const t=["*","(",")",";"].some((t=>e.indexOf(t)>=0));return!t}(u),I(C,[c])),v(!!l,I(U,[c]));const f=t(u),d=n(u),p=A(f,a,{sensitive:r,end:!1!==e.exact}),h=w(f,{encode:encodeURIComponent}),g=function(e){const t={};return Object.keys(e).forEach((n=>{const r=e[n];v(!o(n)||null===r,T),o(n)?t[n.substr(1)]={routeParamName:n}:r&&o(r)?t[n]={routeParamName:r}:t[n]={literalValue:null===r?null:r}})),t}(d),m=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 c=!0;return"string"==typeof i?c=t?i===a:i.toUpperCase()===(null==a?a:a.toUpperCase()):null===i&&(c=a===i),r=c?{...r,[o]:{value:a,routeParamName:s}}:null}),{}):null};return n}(g,r),E={original:e,regex:p,params:a,toPath:h,compiledQuery:g,queryMatcher:m};return v(function(e){const{original:{page:t}={},params:n,compiledQuery:r}=e,a=t?t.type:t,c=(t?t.attributes:t)||{},u=(t?t.state:t)||{};if("string"!=typeof a||"object"!=typeof c||"object"!=typeof u)return!1;const l=Object.values(n).map((({name:e})=>e)),f=s(r),d=[...l,...f],p=Object.values(c).filter(o).map(i),h=Object.values(u).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&&c&&u&&g&&m)}(E),I(P,[c])),E}(e,a)))}function j(){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 M{constructor(e){this.deprecatedConfig={},this.routeHandlerId=0,this.compiledRoutes=[],this.routeObservable=j(),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=S(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(R($.INVALID_ROUTE_HANDLER,[o.routeDefinition.id]));const i=new t(n);i&&i.update(o.route)})):r(R($.NO_ROUTE_MATCH,[JSON.stringify(e)]))}))}navigate(e,t){const n=this.matchRoute(e,t);if(!n)throw new Error(R($.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(R($.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 k(e={}){return new M(e)}export{k 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 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.renderMode="light",m.stylesheets=[],m.stylesheetToken="lwc-7bis3qj4jjc",m.legacyStylesheetToken="lwr-routerContainer_routerContainer",u&&m.stylesheets.push.apply(m.stylesheets,u),i(m);class I{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){E(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){E(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){E(e),this.infoMap.delete(e)}subscribeContext(e,t){E(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){E(e),this.getInfo(e).consumers.delete(t)}}const b="LWR",N=1;function w(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function _(e,t){const i={...e,message:w(e.message,t)};return e.address&&(i.address=w(e.address,t)),e.stack&&(i.stack=w(e.stack,t)),i}function R(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${w(e.message,t)}`}(t,i))}const x={INVALID_MIXIN_CMP:{code:`${b}4001`,message:"{0} must be an Element type",level:N},MISSING_CONTEXT:{code:`${b}4002`,message:"Could not find context to perform navigation action.",level:N},INVALID_CONTEXT:{code:`${b}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:N},MULTIPLE_ROOTS:{code:`${b}4004`,message:"Router connection failed. There can only be one root router.",level:N},MULTIPLE_CHILDREN:{code:`${b}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:N},MISSING_ROUTE:{code:`${b}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:N,address:"{0}"},MISSING_URL:{code:`${b}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:N,address:"{0}"},PRENAV_FAILED:{code:`${b}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${b}4009`,message:'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}}});const Y=o(z,{tmpl:f,sel:"lwr-router-container",apiVersion:62});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 h,logOperationStart as l}from"lwr/profiler";var u=[function(e,t,i){return"span.router-title"+(e?"["+e+"]":"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}];const p=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,v={key:0},g=[];function m(e,t,i,r){const{s:s,st:o}=e;return[s("",v,g,i),o(p,2)]}var f=t(m);function E(e){if(null==e)throw new TypeError("Provider must be defined.")}m.slots=[""],m.renderMode="light",m.stylesheets=[],m.stylesheetToken="lwc-7bis3qj4jjc",m.legacyStylesheetToken="lwr-routerContainer_routerContainer",u&&m.stylesheets.push.apply(m.stylesheets,u),i(m);class I{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){E(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){E(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){E(e),this.infoMap.delete(e)}subscribeContext(e,t){E(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){E(e),this.getInfo(e).consumers.delete(t)}}const b="LWR",N=1;function w(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function _(e,t){const i={...e,message:w(e.message,t)};return e.address&&(i.address=w(e.address,t)),e.stack&&(i.stack=w(e.stack,t)),i}function R(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${w(e.message,t)}`}(t,i))}const x={INVALID_MIXIN_CMP:{code:`${b}4001`,message:"{0} must be an Element type",level:N},MISSING_CONTEXT:{code:`${b}4002`,message:"Could not find context to perform navigation action.",level:N},INVALID_CONTEXT:{code:`${b}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:N},MULTIPLE_ROOTS:{code:`${b}4004`,message:"Router connection failed. There can only be one root router.",level:N},MULTIPLE_CHILDREN:{code:`${b}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:N},MISSING_ROUTE:{code:`${b}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:N,address:"{0}"},MISSING_URL:{code:`${b}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:N,address:"{0}"},PRENAV_FAILED:{code:`${b}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${b}4009`,message:'Route definition with id "{0}" is missing a "uri" property.',level:N,address:"{0}"},MISSING_ROUTE_CMP:{code:`${b}4016`,message:"Expected a route view component with a default export.",level:N},MISSING_DATA_CONTEXT:{code:`${b}4018`,message:"Could not find context to retrieve navigation data.",level:N},INVALID_ROUTE_QUERY:{code:`${b}4019`,message:"Invalid query param in route definition.",level:N},MISSING_PAGE_BINDING:{code:`${b}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:N,address:"{0}"},INVALID_PAGE_BINDING:{code:`${b}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:N,address:"{0}"},INVALID_URI_SYNTAX:{code:`${b}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:N,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${b}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:N,stack:"{2}"},VIEW_MISSING:{code:`${b}4024`,message:'Expected a view with name "{0}" in the viewset',level:N},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${b}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:N,stack:"{3}"},NO_ROUTE_MATCH:{code:`${b}4026`,message:"A routing match cannot be found for: {0}",level:N},INVALID_ROUTE_HANDLER:{code:`${b}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:N},DESTINATION_NOT_FOUND:{code:`${b}4028`,message:"Route handler returned 404: Not Found",level:N},DESTINATION_ERROR:{code:`${b}4029`,message:"Route handler returned error status {0}: {1}",level:N,stack:"{2}"},NO_INIT_URL:{code:`${b}4030`,message:'Cannot initialize a server router without a "url"',level:N}},C=new WeakMap;function T(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,i){e.setContext(t,i)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,i){e.subscribeContext(t,i)}static unsubscribeContext(t,i){e.unsubscribeContext(t,i)}}).contextSchema={value:"required"},t}const P=T(new I(void 0)),y=T(new I(void 0)),S=new I(void 0),O=class extends(T(S)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,o=s&&s.module||r;let n;if(o)try{const e=await o(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;n=s.specifier?_(x.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):_(x.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else n=_(x.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(n)}}};function $(){const e=[],t=t=>{"function"==typeof t&&e.push(t)};return{add:(e=[])=>{Array.isArray(e)?e.forEach((e=>t(e))):t(e)},compile:t=>0===e.length?Promise.resolve(!0):e.reduce(((e,i)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(i(t))))),Promise.resolve(!0)).then((e=>!1!==e)).catch((e=>{if(e instanceof Error)throw e;return!1})),empty:()=>0===e.length}}function A(e=""){return e=e||"",decodeURIComponent(e)}function M(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const L="undefined"!=typeof document,U=`universalcontainergetnavigationcontext${M()}`,D=r(y),k=L?r(O):void 0,F=r(P);function V(e,t,i,r){i&&r&&(r.setContext(t,e),i(t,{consumerConnectedCallback:r.subscribeContext.bind(r,t),consumerDisconnectedCallback:r.unsubscribeContext.bind(r,t)}))}function G(){let e,t,i=[];const r=r=>{i.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{i.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{i.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),i=[],e=void 0,t=void 0},subscribe:(s,o=!0)=>{(e=>{i.push(e)})(s),e&&o&&s.next(e),t&&r(t);const n=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(n)}}}}const W=`universalcontainernavigationevent${M()}`,j=`universalcontainerparentevent${M()}`;class H{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=$(),this.errorNavFilters=$(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:r}=t.detail;this.config.handleNavigation(r,i)?this.root&&!e?this.root.processError(_(x.MISSING_URL,[JSON.stringify(r)])):this.parent||this.process(e,i):t.stopPropagation()}},this._handleParentEvent=e=>{e.stopImmediatePropagation();const t=e;t&&t.detail&&"function"==typeof t.detail&&t.detail(this)},this.config={handleNavigation:e.handleNavigation||(()=>!0)},this.target=i||window,this.router=t,this.router.contextId=this.contextId,this.routeObservable=G()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,i){if(i)this.processError(i);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;h({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},y.setContext(this.target,e.route.pageReference),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),h({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(j,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:(e,t)=>this.generateUrl(e,t),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};C.set(i.id,i)}(this.contextId,e),V(this.contextId,this.target,F,P),V(void 0,this.target,D,y),V(void 0,this.target,k,O),this.router.subscribe((e=>{if(404===e.status)return void this.processError(_(x.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(_(x.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(l({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};O.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),L&&(this.target.addEventListener(W,this._handleNavigationEvent),this.target.addEventListener(j,this._handleParentEvent),this.target.addEventListener(U,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(W,this._handleNavigationEvent),this.target.removeEventListener(j,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{R(!this.child,x.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t,i,r){this.eventId=(new Date).getTime().toString(),l({id:c,specifier:this.eventId});try{this.parent||await this.preProcess(e,i)}catch(e){if(e.code)return this.processError(e),!1;throw e}const s=this.router.parseUrl(e);return s&&this.router.navigate(s,i),!0}preProcess(e,t){const i=this.router.parseUrl(e),r=i&&this.router.matchRoute(i,t);if(!r)return Promise.reject(_(x.MISSING_ROUTE,[e]));this.pendingRoute={url:e,...r};return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(_(x.PRENAV_FAILED,[e]))))}processError(e){l({id:d}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t,i){const r=this.filterNavigateOptions(i);let s=this.router.generateUrl(e,r);if(s){s=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(s)}this._sendEvent(W,{url:s,replace:t,address:e})}generateUrl(e,t){const i=this.filterNavigateOptions(t),r=this.router.generateUrl(e,i);if(!r)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${r}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){L&&this.target.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_stripUrlForChild(e){return this.pendingRoute&&0===e.indexOf(this.pendingRoute.pathMatch)?e.replace(this.pendingRoute.pathMatch,""):e}filterNavigateOptions(e){const t=!this.parent;return{...e,locale:t?e?.locale:void 0}}}function B(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",i=`${window.location.protocol}//${window.location.hostname}${t}`,r="/"===e.charAt(0)?"":"/";e=i+r+e}const t={},i=document.createElement("a");i.href=e;const r=i.search.substring(1);return r&&r.split("&").forEach((e=>{const[i,r=""]=e.split("=");t[A(i)]=A(r)})),{href:i.href,origin:`${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`,pathname:i.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),i=t.href.replace(/:\d+/,""),r=t.origin.replace(/:\d+/,"");return i.replace(r,"")}class X extends H{constructor(){super(...arguments),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(L&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&L&&this.catchBrowserUpdate(B(window.location.href))}disconnect(){super.disconnect(),L&&window.removeEventListener("popstate",this.onpopstate)}async process(e,t,i,r=!0){const s=await super.process(e,t,i,r);return s&&!this.historyDisabled&&r&&this.connected&&!this.parent&&(t?function(e,t){const i=t||{};window.history.replaceState(i,"",e)}(e):function(e,t){const i=t||{};window.history.pushState(i,"",e)}(e)),s}catchBrowserUpdate(e){this.process(e,!1,{},!1)}}let q=!1;class z extends n{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=L?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};L&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new H(t,i,e):new X(t,i,e),s={addPreNavigate:e=>(r.addPreNavigate(e),s),addPostNavigate:e=>(r.subscribe(e),s),addErrorNavigate:e=>(r.addErrorNavigate(e),s),connect:()=>{r.connect(),R(!q||!!r.parent,x.MULTIPLE_ROOTS),q=q||!r.parent,s.id=r.contextId},disconnect:()=>{q=q&&!!r.parent,r.disconnect()}};return s}(this,e,this.router),this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect())}preNavigate(e){const t=this._createEvent("prenavigate",e,!0);return this.dispatchEvent(t),!t.defaultPrevented}postNavigate(e){this.dispatchEvent(this._createEvent("postnavigate",e));const t=e.routeDefinition.metadata&&e.routeDefinition.metadata.title;t&&(this.currentTitle=t,document.title=t);const i=this.querySelector("span.router-title");i&&(i.innerHTML=this.currentTitle)}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const i=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(i),!i.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,i){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:i})}}z.renderMode="light",s(z,{publicProps:{router:{config:0},historyDisabled:{config:0}}});const Y=o(z,{tmpl:f,sel:"lwr-router-container",apiVersion:63});export{Y as default};
|
|
2
2
|
//# sourceMappingURL=routerContainer.js.map
|
|
@@ -92,8 +92,9 @@ var messages = {
|
|
|
92
92
|
},
|
|
93
93
|
MISSING_ROUTE_TEMPLATE: {
|
|
94
94
|
code: `${ERROR_CODE_PREFIX}4009`,
|
|
95
|
-
message: '
|
|
96
|
-
level: DiagnosticLevel.Error
|
|
95
|
+
message: 'Route definition with id "{0}" is missing a "uri" property.',
|
|
96
|
+
level: DiagnosticLevel.Error,
|
|
97
|
+
address: "{0}"
|
|
97
98
|
},
|
|
98
99
|
MISSING_ROUTE_CMP: {
|
|
99
100
|
code: `${ERROR_CODE_PREFIX}4016`,
|
|
@@ -112,18 +113,21 @@ var messages = {
|
|
|
112
113
|
},
|
|
113
114
|
MISSING_PAGE_BINDING: {
|
|
114
115
|
code: `${ERROR_CODE_PREFIX}4020`,
|
|
115
|
-
message:
|
|
116
|
-
level: DiagnosticLevel.Error
|
|
116
|
+
message: 'Route definition with id "{0}" is missing a "page" binding.',
|
|
117
|
+
level: DiagnosticLevel.Error,
|
|
118
|
+
address: "{0}"
|
|
117
119
|
},
|
|
118
120
|
INVALID_PAGE_BINDING: {
|
|
119
121
|
code: `${ERROR_CODE_PREFIX}4021`,
|
|
120
|
-
message: "
|
|
121
|
-
level: DiagnosticLevel.Error
|
|
122
|
+
message: 'Route definition with id "{0}" has an invalid "page" binding.',
|
|
123
|
+
level: DiagnosticLevel.Error,
|
|
124
|
+
address: "{0}"
|
|
122
125
|
},
|
|
123
126
|
INVALID_URI_SYNTAX: {
|
|
124
127
|
code: `${ERROR_CODE_PREFIX}4022`,
|
|
125
|
-
message: "
|
|
126
|
-
level: DiagnosticLevel.Error
|
|
128
|
+
message: 'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',
|
|
129
|
+
level: DiagnosticLevel.Error,
|
|
130
|
+
address: "{0}"
|
|
127
131
|
},
|
|
128
132
|
VIEW_IMPORT_FAILED: {
|
|
129
133
|
code: `${ERROR_CODE_PREFIX}4023`,
|
|
@@ -46,10 +46,10 @@ function parseRoutes(config) {
|
|
|
46
46
|
}
|
|
47
47
|
function parseUriRoute(def, caseSensitive = false) {
|
|
48
48
|
const params = [];
|
|
49
|
-
const {uri, page} = def;
|
|
50
|
-
(0, import_routerErrors.invariant)(!!uri, MISSING_ROUTE_TEMPLATE);
|
|
51
|
-
(0, import_routerErrors.invariant)(isValidUri(uri), INVALID_URI_SYNTAX);
|
|
52
|
-
(0, import_routerErrors.invariant)(!!page, MISSING_PAGE_BINDING);
|
|
49
|
+
const {id, uri, page} = def;
|
|
50
|
+
(0, import_routerErrors.invariant)(!!uri, (0, import_routerErrors.generateMessageObject)(MISSING_ROUTE_TEMPLATE, [id]));
|
|
51
|
+
(0, import_routerErrors.invariant)(isValidUri(uri), (0, import_routerErrors.generateMessageObject)(INVALID_URI_SYNTAX, [id]));
|
|
52
|
+
(0, import_routerErrors.invariant)(!!page, (0, import_routerErrors.generateMessageObject)(MISSING_PAGE_BINDING, [id]));
|
|
53
53
|
const path = (0, import_uriUtils.getPathFromUrl)(uri);
|
|
54
54
|
const query = (0, import_uriUtils.getQueryFromUrl)(uri);
|
|
55
55
|
const regex = (0, import_pathToRegexp.pathToRegexp)(path, params, {
|
|
@@ -60,7 +60,7 @@ function parseUriRoute(def, caseSensitive = false) {
|
|
|
60
60
|
const compiledQuery = compileQueryObject(query);
|
|
61
61
|
const queryMatcher = getQueryMatcher(compiledQuery, caseSensitive);
|
|
62
62
|
const compiledRoute = {original: def, regex, params, toPath, compiledQuery, queryMatcher};
|
|
63
|
-
(0, import_routerErrors.invariant)(isValidPageBinding(compiledRoute), INVALID_PAGE_BINDING);
|
|
63
|
+
(0, import_routerErrors.invariant)(isValidPageBinding(compiledRoute), (0, import_routerErrors.generateMessageObject)(INVALID_PAGE_BINDING, [id]));
|
|
64
64
|
return compiledRoute;
|
|
65
65
|
}
|
|
66
66
|
function isValidUri(uri = "") {
|
|
@@ -65,12 +65,12 @@ function getRouteDefinitionForUri(uri, routeDefs) {
|
|
|
65
65
|
return matched || null;
|
|
66
66
|
}
|
|
67
67
|
function matchRouteByUrl(url, routeDefs, basePath = "", i18n = DEFAULT_I18N_ROUTER_CONFIG, options) {
|
|
68
|
-
if (basePath && url?.
|
|
68
|
+
if (basePath && (url === basePath || url?.search(new RegExp(`^${basePath}[/?#]`)) === 0)) {
|
|
69
69
|
url = url.replace(basePath, "");
|
|
70
70
|
}
|
|
71
71
|
if (options?.locale || i18n?.locale) {
|
|
72
72
|
const localePath = `/${options?.locale || i18n.locale}`;
|
|
73
|
-
if (url?.
|
|
73
|
+
if (url === localePath || url?.search(new RegExp(`^${localePath}[/?#]`)) === 0) {
|
|
74
74
|
url = url.replace(localePath, "");
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -68,12 +68,7 @@ var ServerRouter = class {
|
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
url = this.getRelativeUrl(url);
|
|
71
|
-
|
|
72
|
-
if (!routingMatch) {
|
|
73
|
-
this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.MISSING_ROUTE, [url]));
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this.currentRoute = routingMatch;
|
|
71
|
+
this.currentRoute = this.router.matchRoute(url, {}) || void 0;
|
|
77
72
|
(0, import_navigation.registerNavigationHelm)(this.contextId, {
|
|
78
73
|
navigate: (address, replace, options) => this.navigate(address, replace, options),
|
|
79
74
|
generateUrl: (address, options) => this.generateUrl(address, options),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createContextProvider } from 'lwc';
|
|
2
2
|
import { hasDocument } from 'lwr/routerUtils';
|
|
3
3
|
import { CurrentPageReference, CurrentView, NavigationContext } from 'lwr/navigation';
|
|
4
|
-
// Creating a context with LWC requires eventing APIs, which are not available
|
|
4
|
+
// Creating a context with LWC requires eventing APIs, which are not available for LWC SSR
|
|
5
5
|
export const currentPageReferenceContextualizer = createContextProvider(CurrentPageReference);
|
|
6
6
|
export const currentViewContextualizer = hasDocument ? createContextProvider(CurrentView) : undefined;
|
|
7
7
|
export const navigationContextContextualizer = createContextProvider(NavigationContext);
|
|
@@ -79,8 +79,9 @@ export const messages = {
|
|
|
79
79
|
},
|
|
80
80
|
MISSING_ROUTE_TEMPLATE: {
|
|
81
81
|
code: `${ERROR_CODE_PREFIX}4009`,
|
|
82
|
-
message: '
|
|
82
|
+
message: 'Route definition with id "{0}" is missing a "uri" property.',
|
|
83
83
|
level: DiagnosticLevel.Error,
|
|
84
|
+
address: '{0}',
|
|
84
85
|
},
|
|
85
86
|
MISSING_ROUTE_CMP: {
|
|
86
87
|
code: `${ERROR_CODE_PREFIX}4016`,
|
|
@@ -99,18 +100,21 @@ export const messages = {
|
|
|
99
100
|
},
|
|
100
101
|
MISSING_PAGE_BINDING: {
|
|
101
102
|
code: `${ERROR_CODE_PREFIX}4020`,
|
|
102
|
-
message: 'Route definition
|
|
103
|
+
message: 'Route definition with id "{0}" is missing a "page" binding.',
|
|
103
104
|
level: DiagnosticLevel.Error,
|
|
105
|
+
address: '{0}',
|
|
104
106
|
},
|
|
105
107
|
INVALID_PAGE_BINDING: {
|
|
106
108
|
code: `${ERROR_CODE_PREFIX}4021`,
|
|
107
|
-
message: '
|
|
109
|
+
message: 'Route definition with id "{0}" has an invalid "page" binding.',
|
|
108
110
|
level: DiagnosticLevel.Error,
|
|
111
|
+
address: '{0}',
|
|
109
112
|
},
|
|
110
113
|
INVALID_URI_SYNTAX: {
|
|
111
114
|
code: `${ERROR_CODE_PREFIX}4022`,
|
|
112
|
-
message: '
|
|
115
|
+
message: 'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',
|
|
113
116
|
level: DiagnosticLevel.Error,
|
|
117
|
+
address: '{0}',
|
|
114
118
|
},
|
|
115
119
|
VIEW_IMPORT_FAILED: {
|
|
116
120
|
code: `${ERROR_CODE_PREFIX}4023`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { messages, invariant } from 'lwr/routerErrors';
|
|
1
|
+
import { generateMessageObject, messages, invariant } from 'lwr/routerErrors';
|
|
2
2
|
import { pathToRegexp, compile } from './pathToRegexp.js';
|
|
3
3
|
import { getQueryFromUrl, getPathFromUrl, isParam, getParamName, getQueryNames } from './uriUtils.js';
|
|
4
4
|
const { INVALID_ROUTE_QUERY, MISSING_ROUTE_TEMPLATE, MISSING_PAGE_BINDING, INVALID_PAGE_BINDING, INVALID_URI_SYNTAX, } = messages;
|
|
@@ -35,10 +35,10 @@ export function parseRoutes(config) {
|
|
|
35
35
|
*/
|
|
36
36
|
function parseUriRoute(def, caseSensitive = false) {
|
|
37
37
|
const params = [];
|
|
38
|
-
const { uri, page } = def;
|
|
39
|
-
invariant(!!uri, MISSING_ROUTE_TEMPLATE);
|
|
40
|
-
invariant(isValidUri(uri), INVALID_URI_SYNTAX);
|
|
41
|
-
invariant(!!page, MISSING_PAGE_BINDING);
|
|
38
|
+
const { id, uri, page } = def;
|
|
39
|
+
invariant(!!uri, generateMessageObject(MISSING_ROUTE_TEMPLATE, [id]));
|
|
40
|
+
invariant(isValidUri(uri), generateMessageObject(INVALID_URI_SYNTAX, [id]));
|
|
41
|
+
invariant(!!page, generateMessageObject(MISSING_PAGE_BINDING, [id]));
|
|
42
42
|
const path = getPathFromUrl(uri);
|
|
43
43
|
const query = getQueryFromUrl(uri);
|
|
44
44
|
const regex = pathToRegexp(path, params, {
|
|
@@ -50,7 +50,7 @@ function parseUriRoute(def, caseSensitive = false) {
|
|
|
50
50
|
const compiledQuery = compileQueryObject(query);
|
|
51
51
|
const queryMatcher = getQueryMatcher(compiledQuery, caseSensitive);
|
|
52
52
|
const compiledRoute = { original: def, regex, params, toPath, compiledQuery, queryMatcher };
|
|
53
|
-
invariant(isValidPageBinding(compiledRoute), INVALID_PAGE_BINDING);
|
|
53
|
+
invariant(isValidPageBinding(compiledRoute), generateMessageObject(INVALID_PAGE_BINDING, [id]));
|
|
54
54
|
return compiledRoute;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
@@ -80,13 +80,13 @@ function getRouteDefinitionForUri(uri, routeDefs) {
|
|
|
80
80
|
*/
|
|
81
81
|
export function matchRouteByUrl(url, routeDefs, basePath = '', i18n = DEFAULT_I18N_ROUTER_CONFIG, options) {
|
|
82
82
|
// Pass in the rest of the URL for matching, without the prefix.
|
|
83
|
-
if (basePath && url?.
|
|
83
|
+
if (basePath && (url === basePath || url?.search(new RegExp(`^${basePath}[/?#]`)) === 0)) {
|
|
84
84
|
url = url.replace(basePath, '');
|
|
85
85
|
}
|
|
86
86
|
// Remove the locale
|
|
87
87
|
if (options?.locale || i18n?.locale) {
|
|
88
88
|
const localePath = `/${options?.locale || i18n.locale}`;
|
|
89
|
-
if (url?.
|
|
89
|
+
if (url === localePath || url?.search(new RegExp(`^${localePath}[/?#]`)) === 0) {
|
|
90
90
|
url = url.replace(localePath, '');
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -58,13 +58,9 @@ export class ServerRouter {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
url = this.getRelativeUrl(url);
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.processError(generateMessageObject(messages.MISSING_ROUTE, [url]));
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
this.currentRoute = routingMatch;
|
|
61
|
+
// get an initial value for the current route
|
|
62
|
+
// it will be undefined if this is an invalid page (errorRoute)
|
|
63
|
+
this.currentRoute = this.router.matchRoute(url, {}) || undefined;
|
|
68
64
|
// set up the navigation context APIs
|
|
69
65
|
registerNavigationHelm(this.contextId, {
|
|
70
66
|
navigate: (address, replace, options) => this.navigate(address, replace, options),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createContextProvider } from 'lwc';
|
|
2
2
|
import { hasDocument } from 'lwr/routerUtils';
|
|
3
3
|
import { CurrentPageReference, CurrentView, NavigationContext } from 'lwr/navigation';
|
|
4
|
-
// Creating a context with LWC requires eventing APIs, which are not available
|
|
4
|
+
// Creating a context with LWC requires eventing APIs, which are not available for LWC SSR
|
|
5
5
|
export const currentPageReferenceContextualizer = createContextProvider(CurrentPageReference);
|
|
6
6
|
export const currentViewContextualizer = hasDocument ? createContextProvider(CurrentView) : undefined;
|
|
7
7
|
export const navigationContextContextualizer = createContextProvider(NavigationContext);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<LightningComponentBundle xmlns="
|
|
2
|
+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
|
|
3
3
|
<isExposed>true</isExposed>
|
|
4
4
|
<capabilities>
|
|
5
5
|
<capability>lightning__ServerRenderable</capability>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<LightningComponentBundle xmlns="
|
|
2
|
+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
|
|
3
3
|
<isExposed>true</isExposed>
|
|
4
4
|
<capabilities>
|
|
5
5
|
<capability>lightning__ServerRenderableWithHydration</capability>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<LightningComponentBundle xmlns="
|
|
2
|
+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
|
|
3
3
|
<isExposed>true</isExposed>
|
|
4
4
|
<capabilities>
|
|
5
5
|
<capability>lightning__ServerRenderable</capability>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<LightningComponentBundle xmlns="
|
|
2
|
+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
|
|
3
3
|
<isExposed>true</isExposed>
|
|
4
4
|
<capabilities>
|
|
5
5
|
<capability>lightning__ServerRenderableWithHydration</capability>
|
|
@@ -85,8 +85,9 @@ export const messages = {
|
|
|
85
85
|
},
|
|
86
86
|
MISSING_ROUTE_TEMPLATE: {
|
|
87
87
|
code: `${ERROR_CODE_PREFIX}4009`,
|
|
88
|
-
message: '
|
|
89
|
-
level: DiagnosticLevel.Error
|
|
88
|
+
message: 'Route definition with id "{0}" is missing a "uri" property.',
|
|
89
|
+
level: DiagnosticLevel.Error,
|
|
90
|
+
address: '{0}'
|
|
90
91
|
},
|
|
91
92
|
MISSING_ROUTE_CMP: {
|
|
92
93
|
code: `${ERROR_CODE_PREFIX}4016`,
|
|
@@ -105,18 +106,21 @@ export const messages = {
|
|
|
105
106
|
},
|
|
106
107
|
MISSING_PAGE_BINDING: {
|
|
107
108
|
code: `${ERROR_CODE_PREFIX}4020`,
|
|
108
|
-
message: 'Route definition
|
|
109
|
-
level: DiagnosticLevel.Error
|
|
109
|
+
message: 'Route definition with id "{0}" is missing a "page" binding.',
|
|
110
|
+
level: DiagnosticLevel.Error,
|
|
111
|
+
address: '{0}'
|
|
110
112
|
},
|
|
111
113
|
INVALID_PAGE_BINDING: {
|
|
112
114
|
code: `${ERROR_CODE_PREFIX}4021`,
|
|
113
|
-
message: '
|
|
114
|
-
level: DiagnosticLevel.Error
|
|
115
|
+
message: 'Route definition with id "{0}" has an invalid "page" binding.',
|
|
116
|
+
level: DiagnosticLevel.Error,
|
|
117
|
+
address: '{0}'
|
|
115
118
|
},
|
|
116
119
|
INVALID_URI_SYNTAX: {
|
|
117
120
|
code: `${ERROR_CODE_PREFIX}4022`,
|
|
118
|
-
message: '
|
|
119
|
-
level: DiagnosticLevel.Error
|
|
121
|
+
message: 'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',
|
|
122
|
+
level: DiagnosticLevel.Error,
|
|
123
|
+
address: '{0}'
|
|
120
124
|
},
|
|
121
125
|
VIEW_IMPORT_FAILED: {
|
|
122
126
|
code: `${ERROR_CODE_PREFIX}4023`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { messages, invariant } from 'lwr/routerErrors';
|
|
1
|
+
import { generateMessageObject, messages, invariant } from 'lwr/routerErrors';
|
|
2
2
|
import { pathToRegexp, compile } from './pathToRegexp.js';
|
|
3
3
|
import { getQueryFromUrl, getPathFromUrl, isParam, getParamName, getQueryNames } from './uriUtils.js';
|
|
4
4
|
const {
|
|
@@ -47,12 +47,13 @@ export function parseRoutes(config) {
|
|
|
47
47
|
function parseUriRoute(def, caseSensitive = false) {
|
|
48
48
|
const params = [];
|
|
49
49
|
const {
|
|
50
|
+
id,
|
|
50
51
|
uri,
|
|
51
52
|
page
|
|
52
53
|
} = def;
|
|
53
|
-
invariant(!!uri, MISSING_ROUTE_TEMPLATE);
|
|
54
|
-
invariant(isValidUri(uri), INVALID_URI_SYNTAX);
|
|
55
|
-
invariant(!!page, MISSING_PAGE_BINDING);
|
|
54
|
+
invariant(!!uri, generateMessageObject(MISSING_ROUTE_TEMPLATE, [id]));
|
|
55
|
+
invariant(isValidUri(uri), generateMessageObject(INVALID_URI_SYNTAX, [id]));
|
|
56
|
+
invariant(!!page, generateMessageObject(MISSING_PAGE_BINDING, [id]));
|
|
56
57
|
const path = getPathFromUrl(uri);
|
|
57
58
|
const query = getQueryFromUrl(uri);
|
|
58
59
|
const regex = pathToRegexp(path, params, {
|
|
@@ -73,7 +74,7 @@ function parseUriRoute(def, caseSensitive = false) {
|
|
|
73
74
|
compiledQuery,
|
|
74
75
|
queryMatcher
|
|
75
76
|
};
|
|
76
|
-
invariant(isValidPageBinding(compiledRoute), INVALID_PAGE_BINDING);
|
|
77
|
+
invariant(isValidPageBinding(compiledRoute), generateMessageObject(INVALID_PAGE_BINDING, [id]));
|
|
77
78
|
return compiledRoute;
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -91,13 +91,13 @@ function getRouteDefinitionForUri(uri, routeDefs) {
|
|
|
91
91
|
*/
|
|
92
92
|
export function matchRouteByUrl(url, routeDefs, basePath = '', i18n = DEFAULT_I18N_ROUTER_CONFIG, options) {
|
|
93
93
|
// Pass in the rest of the URL for matching, without the prefix.
|
|
94
|
-
if (basePath && url?.
|
|
94
|
+
if (basePath && (url === basePath || url?.search(new RegExp(`^${basePath}[/?#]`)) === 0)) {
|
|
95
95
|
url = url.replace(basePath, '');
|
|
96
96
|
}
|
|
97
97
|
// Remove the locale
|
|
98
98
|
if (options?.locale || i18n?.locale) {
|
|
99
99
|
const localePath = `/${options?.locale || i18n.locale}`;
|
|
100
|
-
if (url?.
|
|
100
|
+
if (url === localePath || url?.search(new RegExp(`^${localePath}[/?#]`)) === 0) {
|
|
101
101
|
url = url.replace(localePath, '');
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -65,13 +65,9 @@ export class ServerRouter {
|
|
|
65
65
|
}
|
|
66
66
|
url = this.getRelativeUrl(url);
|
|
67
67
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.processError(generateMessageObject(messages.MISSING_ROUTE, [url]));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
this.currentRoute = routingMatch;
|
|
68
|
+
// get an initial value for the current route
|
|
69
|
+
// it will be undefined if this is an invalid page (errorRoute)
|
|
70
|
+
this.currentRoute = this.router.matchRoute(url, {}) || undefined;
|
|
75
71
|
|
|
76
72
|
// set up the navigation context APIs
|
|
77
73
|
registerNavigationHelm(this.contextId, {
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.15.0
|
|
8
|
+
"version": "0.15.0",
|
|
9
9
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -53,18 +53,18 @@
|
|
|
53
53
|
"test:server": "jest --config ./jest.server.config.cjs"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@lwrjs/client-modules": "0.15.0
|
|
57
|
-
"@lwrjs/diagnostics": "0.15.0
|
|
58
|
-
"@lwrjs/shared-utils": "0.15.0
|
|
56
|
+
"@lwrjs/client-modules": "0.15.0",
|
|
57
|
+
"@lwrjs/diagnostics": "0.15.0",
|
|
58
|
+
"@lwrjs/shared-utils": "0.15.0",
|
|
59
59
|
"ajv": "6.12.6"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@lwc/jest-preset": "^16.1.0",
|
|
63
|
-
"@lwrjs/fs-watch": "0.15.0
|
|
63
|
+
"@lwrjs/fs-watch": "0.15.0",
|
|
64
64
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
65
65
|
"jest": "^26.6.3",
|
|
66
|
-
"memfs": "^4.
|
|
67
|
-
"rollup": "^2.
|
|
66
|
+
"memfs": "^4.13.0",
|
|
67
|
+
"rollup": "^2.79.2",
|
|
68
68
|
"ts-jest": "^26.5.6",
|
|
69
69
|
"typescript": "^4.9.5",
|
|
70
70
|
"utam": "3.2.1"
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"volta": {
|
|
100
100
|
"extends": "../../../package.json"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "ee374df435d5342f63e4da126a09461e761837f3"
|
|
103
103
|
}
|