@lwrjs/router 0.19.0 → 0.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- function e(e=""){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 A(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 w(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 x(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=>x(e,t,n).source));return new RegExp(`(?:${r.join("|")})`,N(n))}(e,t,n):w(e,t,n)}const{INVALID_ROUTE_QUERY:T,MISSING_ROUTE_TEMPLATE:U,MISSING_PAGE_BINDING:D,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(U,[c])),v(function(e=""){const t=["*","(",")",";"].some((t=>e.indexOf(t)>=0));return!t}(u),I(C,[c])),v(!!l,I(D,[c]));const f=t(u),d=n(u),p=x(f,a,{sensitive:r,end:!1!==e.exact}),h=A(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{generateUrlFilter:t,DEPRECATED_getRouteFromUrl:n,DEPRECATED_getUrlFromRoute:r}=e;t&&(this.config.generateUrlFilter=t),n&&(this.deprecatedConfig.DEPRECATED_getRouteFromUrl=n),r&&(this.deprecatedConfig.DEPRECATED_getUrlFromRoute=r),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)}generateUrlAsync(e,t){const{generateUrlFilter:n}=this.config;return n?n(e,this.config.generateUrl,t):Promise.resolve(this.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};
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("?"),i=r>=0?t.substr(r+1):null,o={};return i&&i.split("&").forEach((t=>{if(t.indexOf("=")>=0){const[n,r=""]=t.split("=");o[e(n)]=e(r)}else o[e(t)]=null})),o}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 i(e){return!!(e&&e.length>1)&&e.startsWith(":")}function o(e){return!!e&&(!!i(e)&&e.substr(1))}function s(e){return Object.values(e).reduce(((e,{routeParamName:t})=>{const n=o(t);return n&&e.push(n),e}),[])}function a(t,n){const{regex:r,params:i}=n,o=r.exec(t);if(o){const[,...t]=o,n={};return i.forEach(((r,i)=>{const{name:o}=r,s=t[i];n[o]=s?e(s):s})),n}return null}function c(t,n){if(t&&n){const{queryMatcher:r}=n,i=r(t);if(i){const t={};return Object.keys(i).forEach((n=>{const r=i[n],{value:o,routeParamName:s}=r,a=s?s.substr(1):n;t[a]=o?e(o):o})),t}}return null}function u(e,r){if(r){const{original:{page:{type:o="",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 o;if(r&&i(r)){const t=r.substr(1);o=e[t]}else o=r;t[n]=o}));const n={};Object.keys(u).forEach((t=>{const r=u[t];let o;if(r&&i(r)){const t=r.substr(1);o=e[t]}else o=r;n[t]=o}));const a=function(e,t){const{compiledQuery:n}=t,r=Object.keys(n).filter((e=>{const{literalValue:t}=n[e];return!t})),i={};return Object.keys(e).forEach((t=>{const n=e[t];r.indexOf(t)<0&&(i[t]=n)})),i}(f,r);return{type:o,attributes:{...t},state:{...a,...n}}}}return null}const l={locale:"en-US",defaultLocale:"en-US"};function f(e,r){const i=t(e),o=n(e),s=r?r.filter((e=>e.regex.test(i))):[],[u]=s.filter((e=>{const{queryMatcher:t}=e;return t(o)&&function(e,t,n){const{original:{patterns:r=null}={}}=n||{};if(r){const i={...a(e,n),...c(t,n)};return Object.keys(r).every((e=>{const t=r[e],n=new RegExp(t),o=i[e]||"";return n.test(o)}))}return!0}(i,o,e)}));return u||null}function d(e,t,n="",r=l,i){if(!n||e!==n&&0!==e?.search(new RegExp(`^${n}[/?#]`))||(e=e.replace(n,"")),i?.locale||r?.locale){const t=`/${i?.locale||r.locale}`;e!==t&&0!==e?.search(new RegExp(`^${t}[/?#]`))||(e=e.replace(t,""))}const o=f(e,t);let s;if(!o)return null;{const t=u(e,o);if(t){return s={route:{id:o.original.id,attributes:{...t.attributes},state:{...t.state},pageReference:{type:t.type,attributes:{...t.attributes},state:{...t.state}}},routeDefinition:o},s}}return null}function p(e,t,n="",r=l,o){const s=function(e,t){if(!e)return null;const{type:n,attributes:r={},state:o={}}=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(o).indexOf(e)>=0)),d=Object.keys(s).filter((e=>{const t=s[e];return!t||!i(t)})).every((e=>s[e]===r[e])),p=Object.keys(a).filter((e=>{const t=a[e];return null===t||!i(t)})).every((e=>a[e]===o[e]));return c&&u&&l&&d&&f&&p}));return e||null}return null}(e,t);return s?g(e,s,n,r,o):null}function h(e,t,n){const{attributeBindings:r,stateBindings:i}=n,{attributes:s,state:a}=t,c={};return e.forEach((e=>{const[t]=Object.keys(r).filter((t=>o(r[t])===e));if(t)c[e]=s[t];else{const[t]=Object.keys(i).filter((t=>o(i[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=>!i(s[e]))).forEach((e=>c[e]=a[e]));const u={};return Object.keys(t).forEach((e=>{const n=t[e],[i]=Object.keys(r).filter((t=>{const n=r[t],{routeParamName:i}=n;return o(i)===e}));if(i){u[i]=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,i="",o=n+1;if("?"===e[o])throw new TypeError(`Pattern cannot start with "?" at ${o}`);for(;o<e.length;)if("\\"!==e[o]){if(")"===e[o]){if(r--,0===r){o++;break}}else if("("===e[o]&&(r++,"?"!==e[o+1]))throw new TypeError(`Capturing groups are not allowed at ${o}`);i+=e[o++]}else i+=e[o++]+e[o++];if(r)throw new TypeError(`Unbalanced pattern at ${n}`);if(!i)throw new TypeError(`Missing pattern at ${n}`);t.push({type:"PATTERN",index:n,value:i}),n=o}else{let r="",i=n+1;for(;i<e.length;){const t=e.charCodeAt(i);if(!(t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||95===t))break;r+=e[i++]}if(!r)throw new TypeError(`Missing parameter name at ${n}`);t.push({type:"NAME",index:n,value:r}),n=i}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,i=`[^${O(t.delimiter||"/#?")}]+?`,o=[];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:i}=n[a];throw new TypeError(`Unexpected ${r} at ${i}, 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&&(o.push(c),c=""),o.push({name:t||s++,prefix:a,suffix:"",pattern:n||i,modifier:u("MODIFIER")||""});continue}const a=e||u("ESCAPED_CHAR");if(a){c+=a;continue}c&&(o.push(c),c="");if(u("OPEN")){const e=f(),t=u("NAME")||"",n=u("PATTERN")||"",r=f();l("CLOSE"),o.push({name:t||(n?s++:""),pattern:t&&!n?i:n,prefix:e,suffix:r,modifier:u("MODIFIER")||""})}else l("END")}return o}function A(e,t){return function(e,t={}){const n=N(t),{encode:r=e=>e,validate:i=!0}=t,o=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(i&&!o[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(i&&!o[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 w(e,t,n){return function(e,t,n={}){const{strict:r=!1,start:i=!0,end:o=!0,encode:s=e=>e}=n,a=`[${O(n.endsWith||"")}]|$`,c=`[${O(n.delimiter||"/#?")}]`;let u=i?"^":"";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(o)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 x(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=>x(e,t,n).source));return new RegExp(`(?:${r.join("|")})`,N(n))}(e,t,n):w(e,t,n)}const{INVALID_ROUTE_QUERY:T,MISSING_ROUTE_TEMPLATE:U,MISSING_PAGE_BINDING:D,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(U,[c])),v(function(e=""){const t=["*","(",")",";"].some((t=>e.indexOf(t)>=0));return!t}(u),I(C,[c])),v(!!l,I(D,[c]));const f=t(u),d=n(u),p=x(f,a,{sensitive:r,end:!1!==e.exact}),h=A(f,{encode:encodeURIComponent}),g=function(e){const t={};return Object.keys(e).forEach((n=>{const r=e[n];v(!i(n)||null===r,T),i(n)?t[n.substr(1)]={routeParamName:n}:r&&i(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),i=Object.keys(e);return i.every((e=>r.indexOf(e)>=0))?i.reduce(((r,i)=>{if(null===r)return null;const{literalValue:o,routeParamName:s}=e[i],a=n[i];let c=!0;return"string"==typeof o?c=t?o===a:o.toUpperCase()===(null==a?a:a.toUpperCase()):null===o&&(c=a===o),r=c?{...r,[i]:{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(i).map(o),h=Object.values(u).filter(i).map(o),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:(i,o=!0)=>{(e=>{n.push(e)})(i),e&&o&&i.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.basePath=e.basePath||"",this.config={basePath:this.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 i=d(e,t,n,r);return i&&i.route&&i.route.pageReference?i.route.pageReference:null}(e,this.compiledRoutes,this.config.basePath,this.config.i18n)};const{generateUrlFilter:t,DEPRECATED_getRouteFromUrl:n,DEPRECATED_getUrlFromRoute:r}=e;t&&(this.config.generateUrlFilter=t),n&&(this.deprecatedConfig.DEPRECATED_getRouteFromUrl=n),r&&(this.deprecatedConfig.DEPRECATED_getUrlFromRoute=r),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)}generateUrlAsync(e,t){const{generateUrlFilter:n}=this.config;return n?n(e,this.config.generateUrl,t):Promise.resolve(this.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),i=r&&g(r.route.pageReference,r.routeDefinition,this.config.basePath,this.config.i18n,t);return r&&i?{pathMatch:i,route:r.route,routeDefinition:r.routeDefinition.original}:null}async resolveView(e,t){return new Promise(((n,r)=>{const i=this.matchRoute(e,t);return i?i.routeDefinition.handler?.().then((e=>{const t=e.default;if(!t)return r(R($.INVALID_ROUTE_HANDLER,[i.routeDefinition.id]));const o=new t(n);o&&o.update(i.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 n,LightningElement as o}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as h,logOperationStart as l}from"lwr/profiler";function u(e,t,i){return"span.router-title"+(e?"."+e:"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}u.$scoped$=!0;var p=[u];const v=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,g={key:0},m=[],f={ref:"title"};function E(e,t,i,r){const{s:s,sp:n,st:o}=e;return[s("",g,m,i),o(v,2,[n(0,f,null)])]}var I=t(E);function b(e){if(null==e)throw new TypeError("Provider must be defined.")}E.slots=[""],E.renderMode="light",E.hasRefs=!0,E.stylesheets=[],E.stylesheetToken="lwc-7bis3qj4jjc",E.legacyStylesheetToken="lwr-routerContainer_routerContainer",p&&E.stylesheets.push.apply(E.stylesheets,p),i(E);class w{constructor(e){this.infoMap=new WeakMap,this.defaultValue=void 0,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){b(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){b(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){b(e),this.infoMap.delete(e)}subscribeContext(e,t){b(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){b(e),this.getInfo(e).consumers.delete(t)}}const N="LWR",_=1;function R(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function x(e,t){const i={...e,message:R(e.message,t)};return e.address&&(i.address=R(e.address,t)),e.stack&&(i.stack=R(e.stack,t)),i}function C(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${R(e.message,t)}`}(t,i))}const T={INVALID_MIXIN_CMP:{code:`${N}4001`,message:"{0} must be an Element type",level:_},MISSING_CONTEXT:{code:`${N}4002`,message:"Could not find context to perform navigation action.",level:_},INVALID_CONTEXT:{code:`${N}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:_},MULTIPLE_ROOTS:{code:`${N}4004`,message:"Router connection failed. There can only be one root router.",level:_},MULTIPLE_CHILDREN:{code:`${N}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:_},MISSING_ROUTE:{code:`${N}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:_,address:"{0}"},MISSING_URL:{code:`${N}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:_,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:_,address:"{0}"},MISSING_ROUTE_CMP:{code:`${N}4016`,message:"Expected a route view component with a default export.",level:_},MISSING_DATA_CONTEXT:{code:`${N}4018`,message:"Could not find context to retrieve navigation data.",level:_},INVALID_ROUTE_QUERY:{code:`${N}4019`,message:"Invalid query param in route definition.",level:_},MISSING_PAGE_BINDING:{code:`${N}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:_,address:"{0}"},INVALID_PAGE_BINDING:{code:`${N}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:_,address:"{0}"},INVALID_URI_SYNTAX:{code:`${N}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:_,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${N}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:_,stack:"{2}"},VIEW_MISSING:{code:`${N}4024`,message:'Expected a view with name "{0}" in the viewset',level:_},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${N}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:_,stack:"{3}"},NO_ROUTE_MATCH:{code:`${N}4026`,message:"A routing match cannot be found for: {0}",level:_},INVALID_ROUTE_HANDLER:{code:`${N}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:_},DESTINATION_NOT_FOUND:{code:`${N}4028`,message:"Route handler returned 404: Not Found",level:_},DESTINATION_ERROR:{code:`${N}4029`,message:"Route handler returned error status {0}: {1}",level:_,stack:"{2}"},NO_INIT_URL:{code:`${N}4030`,message:'Cannot initialize a server router without a "url"',level:_}},y=new WeakMap;function P(e){var t;return(t=class{constructor(e){this._callback=void 0,this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,i){e.setContext(t,i)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,i){e.subscribeContext(t,i)}static unsubscribeContext(t,i){e.unsubscribeContext(t,i)}}).contextSchema={value:"required"},t}const U=P(new w(void 0)),$=P(new w(void 0)),A=new w(void 0),O=class extends(P(A)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,n=s&&s.module||r;let o;if(n)try{const e=await n(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;o=s.specifier?x(T.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):x(T.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else o=x(T.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(o)}}};function M(){const e=[],t=t=>{"function"==typeof t&&e.push(t)};return{add:(e=[])=>{Array.isArray(e)?e.forEach((e=>t(e))):t(e)},compile:t=>0===e.length?Promise.resolve(!0):e.reduce(((e,i)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(i(t))))),Promise.resolve(!0)).then((e=>!1!==e)).catch((e=>{if(e instanceof Error)throw e;return!1})),empty:()=>0===e.length}}function S(e=""){return e=e||"",decodeURIComponent(e)}function L(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const D="undefined"!=typeof document,k=`universalcontainergetnavigationcontext${L()}`,F=r($),V=D?r(O):void 0,G=r(U);function W(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 j(){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,n=!0)=>{(e=>{i.push(e)})(s),e&&n&&s.next(e),t&&r(t);const o=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(o)}}}}const H=`universalcontainernavigationevent${L()}`,B=`universalcontainerparentevent${L()}`;class X{constructor(e,t,i){this.config=void 0,this.target=void 0,this.router=void 0,this.pendingRoute=null,this.committedRoute=null,this.routeObservable=void 0,this.eventId=void 0,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.parent=void 0,this.child=void 0,this.preNavFilters=M(),this.errorNavFilters=M(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:r}=t.detail;this.config.handleNavigation(r,i)?this.root&&!e?this.root.processError(x(T.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=j()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,i){if(i)this.processError(i);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;h({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},$.setContext(this.target,e.route.pageReference),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),h({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(B,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:(e,t)=>this.generateUrl(e,t),generateUrlAsync:(e,t)=>this.generateUrlAsync(e,t),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};y.set(i.id,i)}(this.contextId,e),W(this.contextId,this.target,G,U),W(void 0,this.target,F,$),W(void 0,this.target,V,O),this.router.subscribe((e=>{if(404===e.status)return void this.processError(x(T.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(x(T.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(l({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};O.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),D&&(this.target.addEventListener(H,this._handleNavigationEvent),this.target.addEventListener(B,this._handleParentEvent),this.target.addEventListener(k,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(H,this._handleNavigationEvent),this.target.removeEventListener(B,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{C(!this.child,T.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t,i,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(T.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(T.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(H,{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}`}async generateUrlAsync(e,t){const i=this.filterNavigateOptions(t),r=await this.router.generateUrlAsync(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){D&&this.target.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_stripUrlForChild(e){return this.pendingRoute&&0===e.indexOf(this.pendingRoute.pathMatch)?e.replace(this.pendingRoute.pathMatch,""):e}filterNavigateOptions(e){const t=!this.parent;return{...e,locale:t?e?.locale:void 0}}}function q(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",i=`${window.location.protocol}//${window.location.hostname}${t}`,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[S(i)]=S(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 z extends X{constructor(...e){super(...e),this.historyDisabled=!1,this.currentUrl=""}connect(){super.connect(),this.historyDisabled||(D&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){if(!this.parent&&D){const e=function(e){const t=e.indexOf("#");return-1!==t?e.substring(0,t):e}(q(window.location.href));e!==this.currentUrl&&this.catchBrowserUpdate(e)}}disconnect(){super.disconnect(),D&&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),this.currentUrl=e),s}catchBrowserUpdate(e){this.process(e,!1,{},!1)}}s(z,{fields:["historyDisabled","currentUrl"]});let Y=!1;class J extends o{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=D?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};D&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new X(t,i,e):new z(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(),C(!Y||!!r.parent,T.MULTIPLE_ROOTS),Y=Y||!r.parent,s.id=r.contextId},disconnect:()=>{Y=Y&&!!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.replace(/[<>&"']/g,(e=>{switch(e){case"<":return"&lt;";case">":return"&gt;";case"&":return"&amp;";case'"':return"&quot;";case"'":return"&#39;";default:return e}})),document.title=this.currentTitle);const i=this.refs?.title;i&&(i.innerHTML=this.currentTitle,setTimeout((()=>{i.innerHTML=""}),500))}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const i=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(i),!i.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,i){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:i})}}J.renderMode="light",s(J,{publicProps:{router:{config:0},historyDisabled:{config:0}}});const Q=n(J,{tmpl:I,sel:"lwr-router-container",apiVersion:63});export{Q as default};
1
+ import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as r,registerDecorators as s,registerComponent as n,LightningElement as o}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as h,logOperationStart as l}from"lwr/profiler";function u(e,t,i){return"span.router-title"+(e?"."+e:"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}u.$scoped$=!0;var p=[u];const v=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,g={key:0},m=[],f={ref:"title"};function E(e,t,i,r){const{s:s,sp:n,st:o}=e;return[s("",g,m,i),o(v,2,[n(0,f,null)])]}var I=t(E);function b(e){if(null==e)throw new TypeError("Provider must be defined.")}E.slots=[""],E.renderMode="light",E.hasRefs=!0,E.stylesheets=[],E.stylesheetToken="lwc-7bis3qj4jjc",E.legacyStylesheetToken="lwr-routerContainer_routerContainer",p&&E.stylesheets.push.apply(E.stylesheets,p),i(E);class w{constructor(e){this.infoMap=new WeakMap,this.defaultValue=void 0,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){b(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){b(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){b(e),this.infoMap.delete(e)}subscribeContext(e,t){b(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){b(e),this.getInfo(e).consumers.delete(t)}}const N="LWR",_=1;function R(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function x(e,t){const i={...e,message:R(e.message,t)};return e.address&&(i.address=R(e.address,t)),e.stack&&(i.stack=R(e.stack,t)),i}function C(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${R(e.message,t)}`}(t,i))}const T={INVALID_MIXIN_CMP:{code:`${N}4001`,message:"{0} must be an Element type",level:_},MISSING_CONTEXT:{code:`${N}4002`,message:"Could not find context to perform navigation action.",level:_},INVALID_CONTEXT:{code:`${N}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:_},MULTIPLE_ROOTS:{code:`${N}4004`,message:"Router connection failed. There can only be one root router.",level:_},MULTIPLE_CHILDREN:{code:`${N}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:_},MISSING_ROUTE:{code:`${N}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:_,address:"{0}"},MISSING_URL:{code:`${N}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:_,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:_,address:"{0}"},MISSING_ROUTE_CMP:{code:`${N}4016`,message:"Expected a route view component with a default export.",level:_},MISSING_DATA_CONTEXT:{code:`${N}4018`,message:"Could not find context to retrieve navigation data.",level:_},INVALID_ROUTE_QUERY:{code:`${N}4019`,message:"Invalid query param in route definition.",level:_},MISSING_PAGE_BINDING:{code:`${N}4020`,message:'Route definition with id "{0}" is missing a "page" binding.',level:_,address:"{0}"},INVALID_PAGE_BINDING:{code:`${N}4021`,message:'Route definition with id "{0}" has an invalid "page" binding.',level:_,address:"{0}"},INVALID_URI_SYNTAX:{code:`${N}4022`,message:'Route definition with id "{0}" has invalid "uri" syntax. URI cannot contain *, +, (, ), ',level:_,address:"{0}"},VIEW_IMPORT_FAILED:{code:`${N}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:_,stack:"{2}"},VIEW_MISSING:{code:`${N}4024`,message:'Expected a view with name "{0}" in the viewset',level:_},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${N}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:_,stack:"{3}"},NO_ROUTE_MATCH:{code:`${N}4026`,message:"A routing match cannot be found for: {0}",level:_},INVALID_ROUTE_HANDLER:{code:`${N}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:_},DESTINATION_NOT_FOUND:{code:`${N}4028`,message:"Route handler returned 404: Not Found",level:_},DESTINATION_ERROR:{code:`${N}4029`,message:"Route handler returned error status {0}: {1}",level:_,stack:"{2}"},NO_INIT_URL:{code:`${N}4030`,message:'Cannot initialize a server router without a "url"',level:_}},y=new WeakMap;function P(e){var t;return(t=class{constructor(e){this._callback=void 0,this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,i){e.setContext(t,i)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,i){e.subscribeContext(t,i)}static unsubscribeContext(t,i){e.unsubscribeContext(t,i)}}).contextSchema={value:"required"},t}const U=P(new w(void 0)),$=P(new w(void 0)),A=new w(void 0),O=class extends(P(A)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,n=s&&s.module||r;let o;if(n)try{const e=await n(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;o=s.specifier?x(T.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):x(T.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else o=x(T.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(o)}}};function M(){const e=[],t=t=>{"function"==typeof t&&e.push(t)};return{add:(e=[])=>{Array.isArray(e)?e.forEach((e=>t(e))):t(e)},compile:t=>0===e.length?Promise.resolve(!0):e.reduce(((e,i)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(i(t))))),Promise.resolve(!0)).then((e=>!1!==e)).catch((e=>{if(e instanceof Error)throw e;return!1})),empty:()=>0===e.length}}function S(e=""){return e=e||"",decodeURIComponent(e)}function L(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const D="undefined"!=typeof document,k=`universalcontainergetnavigationcontext${L()}`,F=r($),V=D?r(O):void 0,G=r(U);function W(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 j(){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,n=!0)=>{(e=>{i.push(e)})(s),e&&n&&s.next(e),t&&r(t);const o=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(o)}}}}const H=`universalcontainernavigationevent${L()}`,B=`universalcontainerparentevent${L()}`;class X{constructor(e,t,i){this.config=void 0,this.target=void 0,this.router=void 0,this.pendingRoute=null,this.committedRoute=null,this.routeObservable=void 0,this.eventId=void 0,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.parent=void 0,this.child=void 0,this.preNavFilters=M(),this.errorNavFilters=M(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:r}=t.detail;this.config.handleNavigation(r,i)?this.root&&!e?this.root.processError(x(T.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=j()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,i){if(i)this.processError(i);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;h({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},$.setContext(this.target,e.route.pageReference),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),h({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(B,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:(e,t)=>this.generateUrl(e,t),generateUrlAsync:(e,t)=>this.generateUrlAsync(e,t),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};y.set(i.id,i)}(this.contextId,e),W(this.contextId,this.target,G,U),W(void 0,this.target,F,$),W(void 0,this.target,V,O),this.router.subscribe((e=>{if(404===e.status)return void this.processError(x(T.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(x(T.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(l({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};O.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),D&&(this.target.addEventListener(H,this._handleNavigationEvent),this.target.addEventListener(B,this._handleParentEvent),this.target.addEventListener(k,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(H,this._handleNavigationEvent),this.target.removeEventListener(B,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{C(!this.child,T.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t,i,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(T.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(T.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(H,{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}`}async generateUrlAsync(e,t){const i=this.filterNavigateOptions(t),r=await this.router.generateUrlAsync(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){D&&this.target.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_stripUrlForChild(e){return this.pendingRoute&&0===e.indexOf(this.pendingRoute.pathMatch)?e.replace(this.pendingRoute.pathMatch,""):e}filterNavigateOptions(e){const t=!this.parent;return{...e,locale:t?e?.locale:void 0}}}function q(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",i=`${window.location.protocol}//${window.location.hostname}${t}`,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[S(i)]=S(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 z extends X{constructor(...e){super(...e),this.historyDisabled=!1,this.currentUrl=""}connect(){super.connect(),this.historyDisabled||(D&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){if(!this.parent&&D){const e=q(window.location.href),t=this.router.basePath.includes("#")?e:function(e){const t=e.indexOf("#");return-1!==t?e.substring(0,t):e}(e);t!==this.currentUrl&&this.catchBrowserUpdate(t)}}disconnect(){super.disconnect(),D&&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),this.currentUrl=e),s}catchBrowserUpdate(e){this.process(e,!1,{},!1)}}s(z,{fields:["historyDisabled","currentUrl"]});let Y=!1;class J extends o{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=D?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};D&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new X(t,i,e):new z(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(),C(!Y||!!r.parent,T.MULTIPLE_ROOTS),Y=Y||!r.parent,s.id=r.contextId},disconnect:()=>{Y=Y&&!!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.replace(/[<>&"']/g,(e=>{switch(e){case"<":return"&lt;";case">":return"&gt;";case"&":return"&amp;";case'"':return"&quot;";case"'":return"&#39;";default:return e}})),document.title=this.currentTitle);const i=this.refs?.title;i&&(i.innerHTML=this.currentTitle,setTimeout((()=>{i.innerHTML=""}),500))}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const i=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(i),!i.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,i){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:i})}}J.renderMode="light",s(J,{publicProps:{router:{config:0},historyDisabled:{config:0}}});const Q=n(J,{tmpl:I,sel:"lwr-router-container",apiVersion:63});export{Q as default};
2
2
  //# sourceMappingURL=routerContainer.js.map
@@ -45,9 +45,10 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
45
45
  }
46
46
  onpopstate() {
47
47
  if (!this.parent && import_routerUtils.hasDocument) {
48
- const relativeUrl = (0, import_domRouterUtils.removeFragment)((0, import_domRouterUtils.getRelativeUrl)(window.location.href));
49
- if (relativeUrl !== this.currentUrl) {
50
- this.catchBrowserUpdate(relativeUrl);
48
+ const relativeUrl = (0, import_domRouterUtils.getRelativeUrl)(window.location.href);
49
+ const hashlessUrl = this.router.basePath.includes("#") ? relativeUrl : (0, import_domRouterUtils.removeFragment)(relativeUrl);
50
+ if (hashlessUrl !== this.currentUrl) {
51
+ this.catchBrowserUpdate(hashlessUrl);
51
52
  }
52
53
  }
53
54
  }
@@ -35,8 +35,9 @@ var RouterImpl = class {
35
35
  this.routeHandlerId = 0;
36
36
  this.compiledRoutes = [];
37
37
  this.routeObservable = (0, import_observable.createObservable)();
38
+ this.basePath = config.basePath || "";
38
39
  this.config = {
39
- basePath: config.basePath || "",
40
+ basePath: this.basePath,
40
41
  i18n: config.i18n || import_routerUtils.DEFAULT_I18N_ROUTER_CONFIG,
41
42
  caseSensitive: Boolean(config.caseSensitive),
42
43
  routes: config.routes || [],
@@ -29,10 +29,14 @@ export class HistoryRouter extends DomRouterImpl {
29
29
  onpopstate() {
30
30
  // Only the root should update the url since it has the full context
31
31
  if (!this.parent && hasDocument) {
32
- // Remove fragment identifier from URL, we never want to navigate for fragment changes
33
- const relativeUrl = removeFragment(getRelativeUrl(window.location.href));
34
- if (relativeUrl !== this.currentUrl) {
35
- this.catchBrowserUpdate(relativeUrl);
32
+ // Remove fragment identifier from URL to prevent navigation for fragment changes
33
+ // Exception: hashes in a basePath allow for deep linking of URLs not supported on the server
34
+ const relativeUrl = getRelativeUrl(window.location.href);
35
+ const hashlessUrl = this.router.basePath.includes('#')
36
+ ? relativeUrl
37
+ : removeFragment(relativeUrl);
38
+ if (hashlessUrl !== this.currentUrl) {
39
+ this.catchBrowserUpdate(hashlessUrl);
36
40
  }
37
41
  }
38
42
  }
@@ -9,6 +9,7 @@ import { generateMessage, messages } from 'lwr/routerErrors';
9
9
  import { createObservable } from 'lwr/observable';
10
10
  class RouterImpl {
11
11
  config;
12
+ basePath;
12
13
  deprecatedConfig = {};
13
14
  compiledRoutes;
14
15
  // The in-flight route state to be committed once the view mapping is handled
@@ -24,8 +25,9 @@ class RouterImpl {
24
25
  constructor(config) {
25
26
  this.compiledRoutes = [];
26
27
  this.routeObservable = createObservable();
28
+ this.basePath = config.basePath || '';
27
29
  this.config = {
28
- basePath: config.basePath || '',
30
+ basePath: this.basePath,
29
31
  i18n: config.i18n || DEFAULT_I18N_ROUTER_CONFIG,
30
32
  caseSensitive: Boolean(config.caseSensitive),
31
33
  routes: config.routes || [],
@@ -22,7 +22,9 @@ export type ViewMapper<TAddress> = {
22
22
  resolveView(address: TAddress): Promise<RouteDestination>;
23
23
  contextId?: ContextId;
24
24
  };
25
- export type Router<TAddress = string> = ViewMapper<TAddress> & UrlMapper<TAddress> & RouteMatcher<TAddress>;
25
+ export type Router<TAddress = string> = ViewMapper<TAddress> & UrlMapper<TAddress> & RouteMatcher<TAddress> & {
26
+ basePath: string;
27
+ };
26
28
  export type GenerateUrlFilter<TAddress> = (route: TAddress, defaultImpl: UrlMapper<TAddress>['generateUrl'], options?: NavigateOptions) => Promise<string | null>;
27
29
  export type DEPRECATED_getRouteFromUrl<TAddress> = (url: string, defaultImpl: UrlMapper<TAddress>['parseUrl']) => TAddress | null;
28
30
  export type DEPRECATED_getUrlFromRoute<TAddress> = (route: TAddress, defaultImpl: UrlMapper<TAddress>['generateUrl'], options?: NavigateOptions) => string | null;
@@ -33,10 +33,12 @@ export class HistoryRouter extends DomRouterImpl {
33
33
  onpopstate() {
34
34
  // Only the root should update the url since it has the full context
35
35
  if (!this.parent && hasDocument) {
36
- // Remove fragment identifier from URL, we never want to navigate for fragment changes
37
- const relativeUrl = removeFragment(getRelativeUrl(window.location.href));
38
- if (relativeUrl !== this.currentUrl) {
39
- this.catchBrowserUpdate(relativeUrl);
36
+ // Remove fragment identifier from URL to prevent navigation for fragment changes
37
+ // Exception: hashes in a basePath allow for deep linking of URLs not supported on the server
38
+ const relativeUrl = getRelativeUrl(window.location.href);
39
+ const hashlessUrl = this.router.basePath.includes('#') ? relativeUrl : removeFragment(relativeUrl);
40
+ if (hashlessUrl !== this.currentUrl) {
41
+ this.catchBrowserUpdate(hashlessUrl);
40
42
  }
41
43
  }
42
44
  }
@@ -23,8 +23,9 @@ class RouterImpl {
23
23
  constructor(config) {
24
24
  this.compiledRoutes = [];
25
25
  this.routeObservable = createObservable();
26
+ this.basePath = config.basePath || '';
26
27
  this.config = {
27
- basePath: config.basePath || '',
28
+ basePath: this.basePath,
28
29
  i18n: config.i18n || DEFAULT_I18N_ROUTER_CONFIG,
29
30
  caseSensitive: Boolean(config.caseSensitive),
30
31
  routes: config.routes || [],
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.19.0",
8
+ "version": "0.19.2",
9
9
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
10
10
  "repository": {
11
11
  "type": "git",
@@ -53,14 +53,14 @@
53
53
  "test:server": "jest --config ./jest.server.config.cjs"
54
54
  },
55
55
  "dependencies": {
56
- "@lwrjs/client-modules": "0.19.0",
57
- "@lwrjs/diagnostics": "0.19.0",
58
- "@lwrjs/shared-utils": "0.19.0",
56
+ "@lwrjs/client-modules": "0.19.2",
57
+ "@lwrjs/diagnostics": "0.19.2",
58
+ "@lwrjs/shared-utils": "0.19.2",
59
59
  "ajv": "6.12.6"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@lwc/jest-preset": "^18.1.2",
63
- "@lwrjs/fs-watch": "0.19.0",
63
+ "@lwrjs/fs-watch": "0.19.2",
64
64
  "@rollup/plugin-typescript": "^11.1.6",
65
65
  "jest": "29.7.0",
66
66
  "memfs": "^4.13.0",
@@ -100,5 +100,5 @@
100
100
  "volta": {
101
101
  "extends": "../../../package.json"
102
102
  },
103
- "gitHead": "78578bcbf94d64439a250ea19048e492c8f45061"
103
+ "gitHead": "2f44f011c2e66056c5961d6fbfd6d4a8d08d99cb"
104
104
  }