@lwrjs/router 0.6.0-alpha.2 → 0.6.0-alpha.6

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 +1 @@
1
- import{registerDecorators as e}from"lwc";function t(e){if(null==e)throw new TypeError("Provider must be defined.")}class n{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,n){t(e);const o=this.getInfo(e);o.contextValue=n,o.consumers.forEach((e=>e.provide(n)))}getContext(e){t(e);const{contextValue:n}=this.getInfo(e);return void 0!==n?n:this.defaultValue}clearContext(e){t(e),this.infoMap.delete(e)}subscribeContext(e,n){t(e);const{consumers:o,contextValue:a}=this.getInfo(e);o.has(n)||(o.add(n),n.provide(a))}unsubscribeContext(e,n){t(e),this.getInfo(e).consumers.delete(n)}}e(n,{fields:["infoMap"]});const o=1;function a(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}function s(e,t){return`${e.code}: ${a(e.message,t)}`}function i(e,t){const n={...e,message:a(e.message,t)};return e.address&&(n.address=a(e.address,t)),n}const r={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:o},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:o},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:o},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:o},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:o},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:o,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:o,address:"{0}"},PRENAV_FAILED:{code:"LWR4008",message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:"LWR4009",message:'A route definition must contain a "uri" property.',level:o},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:o},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:o},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:o,url:""},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:o,url:""},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:o,url:""},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:o,url:""},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:o},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:o}},c=new WeakMap;function l(e){const t=c.get(e);if(!t||!t.value)throw new Error(s(r.MISSING_CONTEXT));return t.value}function d(e,t){const n={id:e,value:t,update:e=>{n.value=e}};return c.set(n.id,n),n}function u(e){var t,n;return n=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)}},t.contextSchema={value:"required"},n}const v=u(new n(void 0)),I=u(new n(void 0)),g=u(new n(void 0)),m=new n(void 0),f=class extends(u(m)){async update(e,t){if(t){const n=e&&e.viewName?e.viewName:"default",o=t.viewset[n],a=o&&o.module||o;let s;if(a)try{const e=await a(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){s=i(r.VIEW_IMPORT_FAILED,[n,e.message])}else s=i(r.VIEW_MISSING,[n]);t.onComplete&&t.onComplete(s)}}};function h(e,t,n){l(e).navigate(t,n)}function p(e,t){return l(e).generateUrl(t)}const N=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,E=Symbol("Navigate"),_=Symbol("GenerateUrl"),b=Symbol("NavContext"),L=Symbol("NavContext");function C(e){!function(e,t,n){if(!e)throw new Error(s(t,n))}("function"==typeof e.prototype.dispatchEvent,r.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[L](){if(!this[b]&&(this.dispatchEvent(new CustomEvent(N,{bubbles:!0,composed:!0,detail:{callback:e=>{this[b]=e}}})),!this[b]))throw new Error(s(r.MISSING_CONTEXT))}[E](e,t){this[L](),h(this[b],e,t)}async[_](e){return this[L](),p(this[b],e)}}}C.Navigate=E,C.GenerateUrl=_,C.NavContext=b;export{n as ContextInfo,I as CurrentPageReference,g as CurrentRoute,f as CurrentView,v as NavigationContext,C as NavigationMixin,u as generateContextualWireAdapter,p as generateUrl,l as getNavigationHelm,h as navigate,d as registerNavigationHelm};
1
+ import{registerDecorators as e}from"lwc";function t(e){if(null==e)throw new TypeError("Provider must be defined.")}class n{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,n){t(e);const o=this.getInfo(e);o.contextValue=n,o.consumers.forEach((e=>e.provide(n)))}getContext(e){t(e);const{contextValue:n}=this.getInfo(e);return void 0!==n?n:this.defaultValue}clearContext(e){t(e),this.infoMap.delete(e)}subscribeContext(e,n){t(e);const{consumers:o,contextValue:a}=this.getInfo(e);o.has(n)||(o.add(n),n.provide(a))}unsubscribeContext(e,n){t(e),this.getInfo(e).consumers.delete(n)}}e(n,{fields:["infoMap"]});const o=1;function a(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}function s(e,t){return`${e.code}: ${a(e.message,t)}`}function i(e,t){const n={...e,message:a(e.message,t)};return e.address&&(n.address=a(e.address,t)),e.stack&&(n.stack=a(e.stack,t)),n}const r={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:o},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:o},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:o},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:o},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:o},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:o,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:o,address:"{0}"},PRENAV_FAILED:{code:"LWR4008",message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:"LWR4009",message:'A route definition must contain a "uri" property.',level:o},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:o},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:o},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:o},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:o},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:o},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:o},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:o,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:o},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:o,stack:"{3}"}},c=new WeakMap;function l(e){const t=c.get(e);if(!t||!t.value)throw new Error(s(r.MISSING_CONTEXT));return t.value}function d(e,t){const n={id:e,value:t,update:e=>{n.value=e}};return c.set(n.id,n),n}function u(e){var t,n;return n=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)}},t.contextSchema={value:"required"},n}const I=u(new n(void 0)),v=u(new n(void 0)),g=u(new n(void 0)),m=new n(void 0),f=class extends(u(m)){async update(e,t){if(t){const n=e&&e.viewName?e.viewName:"default",o=t.viewset[n],a=o,s=a&&a.module||o;let c;if(s)try{const e=await s(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;c=a.specifier?i(r.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[a.specifier,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){l(e).navigate(t,n)}function E(e,t){return l(e).generateUrl(t)}const p=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,_=Symbol("Navigate"),N=Symbol("GenerateUrl"),R=Symbol("NavContext"),L=Symbol("NavContext");function w(e){!function(e,t,n){if(!e)throw new Error(s(t,n))}("function"==typeof e.prototype.dispatchEvent,r.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[L](){if(!this[R]&&(this.dispatchEvent(new CustomEvent(p,{bubbles:!0,composed:!0,detail:{callback:e=>{this[R]=e}}})),!this[R]))throw new Error(s(r.MISSING_CONTEXT))}[_](e,t){this[L](),h(this[R],e,t)}async[N](e){return this[L](),E(this[R],e)}}}w.Navigate=_,w.GenerateUrl=N,w.NavContext=R;export{n as ContextInfo,v as CurrentPageReference,g as CurrentRoute,f as CurrentView,I as NavigationContext,w as NavigationMixin,u as generateContextualWireAdapter,E as generateUrl,l as getNavigationHelm,h as navigate,d as registerNavigationHelm};
@@ -1 +1 @@
1
- import{registerDecorators as e}from"lwc";function t(e=""){return e=e||"",decodeURIComponent(e)}function n(e){"/"!==(e=e||"/").charAt(0)&&(e="/"+e);const t=e.match(/^[^#?]+/);if(null!==t){const e=t[0];return"/"===e?"/":e.replace(/\/$/,"")}return"/"}function r(e){const n=(e=e||"").indexOf("#");n>=0&&(e=e.substring(0,n));const r=e.indexOf("?"),o=r>=0?e.substr(r+1):null,i={};return o&&o.split("&").forEach((e=>{if(e.indexOf("=")>=0){const[n,r=""]=e.split("=");i[t(n)]=t(r)}else i[t(e)]=null})),i}function o(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 s(e){return!!e&&(!!i(e)&&e.substr(1))}function a(e){return Object.values(e).reduce(((e,{routeParamName:t})=>{const n=s(t);return n&&e.push(n),e}),[])}function u(e,n){const{regex:r,params:o}=n,i=r.exec(e);if(i){const[,...e]=i,n={};return o.forEach(((r,o)=>{const{name:i}=r,s=e[o];n[i]=s?t(s):s})),n}return null}function c(e,n){if(e&&n){const{queryMatcher:r}=n,o=r(e);if(o){const e={};return Object.keys(o).forEach((n=>{const r=o[n],{value:i,routeParamName:s}=r,a=s?s.substr(1):n;e[a]=i?t(i):i})),e}}return null}function l(e,t){if(t){const{original:{page:{type:o="",attributes:s={},state:a={}}={}}={}}=t,l=n(e),f=r(e),p=u(l,t),d=c(f,t);if(p&&d){const e={...p,...d},n={};Object.keys(s).forEach((t=>{const r=s[t];let o;if(r&&i(r)){const t=r.substr(1);o=e[t]}else o=r;n[t]=o}));const r={};Object.keys(a).forEach((t=>{const n=a[t];let o;if(n&&i(n)){const t=n.substr(1);o=e[t]}else o=n;r[t]=o}));const u=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,t);return{type:o,attributes:{...n},state:{...u,...r}}}}return null}function f(e,t){const o=n(e),i=r(e),s=t?t.filter((e=>e.regex.test(o))):[],[a]=s.filter((e=>{const{queryMatcher:t}=e;return t(i)&&function(e,t,n){const{original:{patterns:r=null}={}}=n||{};if(r){const o={...u(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 a||null}function p(e,t,n=""){n&&0===e.indexOf(n)&&(e=e.replace(n,""));const r=f(e,t);let o;if(!r)return null;{const t=l(e,r);if(t){return o={route:{id:r.original.id,attributes:{...t.attributes},state:{...t.state},pageReference:{type:t.type,attributes:{...t.attributes},state:{...t.state}}},routeDefinition:r},o}}return null}function d(e,t,n=""){const r=function(e,t){if(!e)return null;const{type:n,attributes:r={},state:o={}}=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(o).indexOf(e)>=0)),p=Object.keys(s).filter((e=>{const t=s[e];return!t||!i(t)})).every((e=>s[e]===r[e])),d=Object.keys(a).filter((e=>{const t=a[e];return null===t||!i(t)})).every((e=>a[e]===o[e]));return u&&c&&l&&p&&f&&d}));return e||null}return null}(e,t);return r?g(e,r,n):null}function h(e,t,n){const{attributeBindings:r,stateBindings:o}=n,{attributes:i,state:a}=t,u={};return e.forEach((e=>{const[t]=Object.keys(r).filter((t=>s(r[t])===e));if(t)u[e]=i[t];else{const[t]=Object.keys(o).filter((t=>s(o[t])===e));t&&(u[e]=a[t])}})),u}function g(e,t,n=""){const{params:r,original:{page:u={}}={},toPath:c,compiledQuery:l}=t,{attributes:f={},state:p={}}=u,d=c(h(r.filter((({name:e})=>"string"==typeof e)).map((({name:e})=>e)),e,{attributeBindings:f,stateBindings:p})),g=function(e,t,n){const{compiledQuery:r,original:{page:{state:o={}}}}=n,{state:a={}}=e||{},u={};Object.keys(a).filter((e=>!i(o[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 s(o)===e}));if(o){c[o]=n}})),{...u,...c}}(e,h(a(l),e,{attributeBindings:f,stateBindings:p}),t);return`${n}${d}${o(g)}`}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=1;function y(e,t){return`${e.code}: ${function(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}(e.message,t)}`}function b(e,t,n){if(!e)throw new Error(y(t,n))}const R={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:E},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:E},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:E},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:E},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:E},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:E,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:E,address:"{0}"},PRENAV_FAILED:{code:"LWR4008",message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:"LWR4009",message:'A route definition must contain a "uri" property.',level:E},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:E},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:E},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:E,url:""},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:E,url:""},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:E,url:""},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:E,url:""},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:E},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:E}};function v(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function I(e){return e&&e.sensitive?"":"i"}function x(e,t={}){const n=function(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];if("*"!==r&&"+"!==r&&"?"!==r)if("\\"!==r)if("{"!==r)if("}"!==r)if(":"!==r)if("("!==r)t.push({type:"CHAR",index:n,value:e[n++]});else{let r=1,o="",i=n+1;if("?"===e[i])throw new TypeError(`Pattern cannot start with "?" at ${i}`);for(;i<e.length;)if("\\"!==e[i]){if(")"===e[i]){if(r--,0===r){i++;break}}else if("("===e[i]&&(r++,"?"!==e[i+1]))throw new TypeError(`Capturing groups are not allowed at ${i}`);o+=e[i++]}else o+=e[i++]+e[i++];if(r)throw new TypeError(`Unbalanced pattern at ${n}`);if(!o)throw new TypeError(`Missing pattern at ${n}`);t.push({type:"PATTERN",index:n,value:o}),n=i}else{let r="",o=n+1;for(;o<e.length;){const t=e.charCodeAt(o);if(!(t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||95===t))break;r+=e[o++]}if(!r)throw new TypeError(`Missing parameter name at ${n}`);t.push({type:"NAME",index:n,value:r}),n=o}else t.push({type:"CLOSE",index:n,value:e[n++]});else t.push({type:"OPEN",index:n,value:e[n++]});else t.push({type:"ESCAPED_CHAR",index:n++,value:e[n++]});else t.push({type:"MODIFIER",index:n,value:e[n++]})}return t.push({type:"END",index:n,value:""}),t}(e),{prefixes:r="./"}=t,o=`[^${v(t.delimiter||"/#?")}]+?`,i=[];let s=0,a=0,u="";const c=e=>{if(a<n.length&&n[a].type===e)return n[a++].value},l=e=>{const t=c(e);if(void 0!==t)return t;const{type:r,index:o}=n[a];throw new TypeError(`Unexpected ${r} at ${o}, expected ${e}`)},f=()=>{let e,t="";for(;e=c("CHAR")||c("ESCAPED_CHAR");)t+=e;return t};for(;a<n.length;){const e=c("CHAR"),t=c("NAME"),n=c("PATTERN");if(t||n){let a=e||"";-1===r.indexOf(a)&&(u+=a,a=""),u&&(i.push(u),u=""),i.push({name:t||s++,prefix:a,suffix:"",pattern:n||o,modifier:c("MODIFIER")||""});continue}const a=e||c("ESCAPED_CHAR");if(a){u+=a;continue}u&&(i.push(u),u="");if(c("OPEN")){const e=f(),t=c("NAME")||"",n=c("PATTERN")||"",r=f();l("CLOSE"),i.push({name:t||(n?s++:""),pattern:t&&!n?o:n,prefix:e,suffix:r,modifier:c("MODIFIER")||""})}else l("END")}return i}function O(e,t){return function(e,t={}){const n=I(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}}(x(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=`[${v(n.endsWith||"")}]|$`,u=`[${v(n.delimiter||"/#?")}]`;let c=o?"^":"";for(const n of e)if("string"==typeof n)c+=v(s(n));else{const e=v(s(n.prefix)),r=v(s(n.suffix));if(n.pattern)if(t&&t.push(n),e||r)if("+"===n.modifier||"*"===n.modifier){const t="*"===n.modifier?"?":"";c+=`(?:${e}((?:${n.pattern})(?:${r}${e}(?:${n.pattern}))*)${r})${t}`}else c+=`(?:${e}(${n.pattern})${r})${n.modifier}`;else c+=`(${n.pattern})${n.modifier}`;else c+=`(?:${e}${r})${n.modifier}`}if(i)r||(c+=`${u}?`),c+=n.endsWith?`(?=${a})`:"$";else{const t=e[e.length-1],n="string"==typeof t?u.indexOf(t[t.length-1])>-1:void 0===t;r||(c+=`(?:${u}(?=${a}))?`),n||(c+=`(?=${u}|${a})`)}return new RegExp(c,I(n))}(x(e,n),t,n)}function w(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=>w(e,t,n).source));return new RegExp(`(?:${r.join("|")})`,I(n))}(e,t,n):$(e,t,n)}const{INVALID_ROUTE_QUERY:A,MISSING_ROUTE_TEMPLATE:N,MISSING_PAGE_BINDING:T,INVALID_PAGE_BINDING:_,INVALID_URI_SYNTAX:P}=R;function D(e){const{routes:t,caseSensitive:o}=e;return t.map((e=>function(e,t=!1){const o=[],{uri:u,page:c}=e;b(!!u,N),b(function(e=""){return!["*","+","(",")",";"].some((t=>e.indexOf(t)>=0))}(u),P),b(!!c,T);const l=n(u),f=r(u),p=w(l,o,{sensitive:t,end:!1!==e.exact}),d=O(l,{encode:encodeURIComponent}),h=function(e){const t={};return Object.keys(e).forEach((n=>{const r=e[n];b(!i(n)||null===r,A),i(n)?t[n.substr(1)]={routeParamName:n}:r&&i(r)?t[n]={routeParamName:r}:t[n]={literalValue:null===r?null:r}})),t}(f),g=function(e,t=!1){return 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}}(h,t),m={original:e,regex:p,params:o,toPath:d,compiledQuery:h,queryMatcher:g};return b(function(e){const{original:{page:t}={},params:n,compiledQuery:r}=e,o=t?t.type:t,u=(t?t.attributes:t)||{},c=(t?t.state:t)||{};if("string"!=typeof o||"object"!=typeof u||"object"!=typeof c)return!1;const l=Object.values(n).map((({name:e})=>e)),f=a(r),p=[...l,...f],d=Object.values(u).filter(i).map(s),h=Object.values(c).filter(i).map(s),g=p.every((e=>"string"==typeof e&&(d.indexOf(e)>=0||h.indexOf(e)>=0))),m=p.length===d.length+h.length;return!!(t&&o&&u&&c&&g&&m)}(m),_),m}(e,o)))}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),o.next&&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 U{constructor(e){this.deprecatedConfig={},this.routeHandlerId=0,this.compiledRoutes=[],this.routeObservable=C(),this.config={basePath:e.basePath||"",caseSensitive:Boolean(e.caseSensitive),routes:e.routes||[],generateUrl:e=>d(e,this.compiledRoutes,this.config.basePath),parseUrl:e=>function(e,t,n=""){const r=p(e,t,n);return r&&r.route&&r.route.pageReference?r.route.pageReference:null}(e,this.compiledRoutes,this.config.basePath)};const{DEPRECATED_getRouteFromUrl:t,DEPRECATED_getUrlFromRoute:n}=e;t&&(this.deprecatedConfig.DEPRECATED_getRouteFromUrl=t),n&&(this.deprecatedConfig.DEPRECATED_getUrlFromRoute=n),this.compiledRoutes=D(this.config)}generateUrl(e){const{DEPRECATED_getUrlFromRoute:t}=this.deprecatedConfig;return t?t(e,this.config.generateUrl.bind(this,e)):this.config.generateUrl(e)}parseUrl(e){const{DEPRECATED_getRouteFromUrl:t}=this.deprecatedConfig;return t?t(e,this.config.parseUrl.bind(this,e)):this.config.parseUrl(e)}matchRoute(e){const t="string"==typeof e?e:this.generateUrl(e);if(null===t)return null;const n=p(t,this.compiledRoutes,this.config.basePath),r=n&&g(n.route.pageReference,n.routeDefinition,this.config.basePath);return n&&r?{pathMatch:r,route:n.route,routeDefinition:n.routeDefinition.original}:null}navigate(e){const t=this.matchRoute(e);if(!t)throw new Error(y(R.MISSING_ROUTE,[JSON.stringify(e)]));this.pendingRoute={...t},this._mapView(this.pendingRoute)}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}async _mapView(e){const t=Math.random();this.routeHandlerId=t;const n=(await e.routeDefinition.handler()).default;if(!n)throw new Error("Route did not have a route handler");return this.routeHandler=new n((e=>{this._updateView(t,e)})),this.routeHandler&&this.routeHandler.update(e.route),!0}_updateView(e,t){if(!t||!t.viewset||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,viewset:n})}}function L(e={}){return new U(e)}e(U,{fields:["deprecatedConfig","routeHandlerId"]});export{L as createRouter};
1
+ import{registerDecorators as e}from"lwc";function t(e=""){return e=e||"",decodeURIComponent(e)}function n(e){"/"!==(e=e||"/").charAt(0)&&(e="/"+e);const t=e.match(/^[^#?]+/);if(null!==t){const e=t[0];return"/"===e?"/":e.replace(/\/$/,"")}return"/"}function r(e){const n=(e=e||"").indexOf("#");n>=0&&(e=e.substring(0,n));const r=e.indexOf("?"),o=r>=0?e.substr(r+1):null,i={};return o&&o.split("&").forEach((e=>{if(e.indexOf("=")>=0){const[n,r=""]=e.split("=");i[t(n)]=t(r)}else i[t(e)]=null})),i}function o(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 s(e){return!!e&&(!!i(e)&&e.substr(1))}function a(e){return Object.values(e).reduce(((e,{routeParamName:t})=>{const n=s(t);return n&&e.push(n),e}),[])}function u(e,n){const{regex:r,params:o}=n,i=r.exec(e);if(i){const[,...e]=i,n={};return o.forEach(((r,o)=>{const{name:i}=r,s=e[o];n[i]=s?t(s):s})),n}return null}function c(e,n){if(e&&n){const{queryMatcher:r}=n,o=r(e);if(o){const e={};return Object.keys(o).forEach((n=>{const r=o[n],{value:i,routeParamName:s}=r,a=s?s.substr(1):n;e[a]=i?t(i):i})),e}}return null}function l(e,t){if(t){const{original:{page:{type:o="",attributes:s={},state:a={}}={}}={}}=t,l=n(e),f=r(e),p=u(l,t),d=c(f,t);if(p&&d){const e={...p,...d},n={};Object.keys(s).forEach((t=>{const r=s[t];let o;if(r&&i(r)){const t=r.substr(1);o=e[t]}else o=r;n[t]=o}));const r={};Object.keys(a).forEach((t=>{const n=a[t];let o;if(n&&i(n)){const t=n.substr(1);o=e[t]}else o=n;r[t]=o}));const u=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,t);return{type:o,attributes:{...n},state:{...u,...r}}}}return null}function f(e,t){const o=n(e),i=r(e),s=t?t.filter((e=>e.regex.test(o))):[],[a]=s.filter((e=>{const{queryMatcher:t}=e;return t(i)&&function(e,t,n){const{original:{patterns:r=null}={}}=n||{};if(r){const o={...u(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 a||null}function p(e,t,n=""){n&&0===e.indexOf(n)&&(e=e.replace(n,""));const r=f(e,t);let o;if(!r)return null;{const t=l(e,r);if(t){return o={route:{id:r.original.id,attributes:{...t.attributes},state:{...t.state},pageReference:{type:t.type,attributes:{...t.attributes},state:{...t.state}}},routeDefinition:r},o}}return null}function d(e,t,n=""){const r=function(e,t){if(!e)return null;const{type:n,attributes:r={},state:o={}}=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(o).indexOf(e)>=0)),p=Object.keys(s).filter((e=>{const t=s[e];return!t||!i(t)})).every((e=>s[e]===r[e])),d=Object.keys(a).filter((e=>{const t=a[e];return null===t||!i(t)})).every((e=>a[e]===o[e]));return u&&c&&l&&p&&f&&d}));return e||null}return null}(e,t);return r?g(e,r,n):null}function h(e,t,n){const{attributeBindings:r,stateBindings:o}=n,{attributes:i,state:a}=t,u={};return e.forEach((e=>{const[t]=Object.keys(r).filter((t=>s(r[t])===e));if(t)u[e]=i[t];else{const[t]=Object.keys(o).filter((t=>s(o[t])===e));t&&(u[e]=a[t])}})),u}function g(e,t,n=""){const{params:r,original:{page:u={}}={},toPath:c,compiledQuery:l}=t,{attributes:f={},state:p={}}=u,d=c(h(r.filter((({name:e})=>"string"==typeof e)).map((({name:e})=>e)),e,{attributeBindings:f,stateBindings:p})),g=function(e,t,n){const{compiledQuery:r,original:{page:{state:o={}}}}=n,{state:a={}}=e||{},u={};Object.keys(a).filter((e=>!i(o[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 s(o)===e}));if(o){c[o]=n}})),{...u,...c}}(e,h(a(l),e,{attributeBindings:f,stateBindings:p}),t);return`${n}${d}${o(g)}`}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=1;function y(e,t){return`${e.code}: ${function(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}(e.message,t)}`}function b(e,t,n){if(!e)throw new Error(y(t,n))}const R={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:E},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:E},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:E},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:E},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:E},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:E,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:E,address:"{0}"},PRENAV_FAILED:{code:"LWR4008",message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:"LWR4009",message:'A route definition must contain a "uri" property.',level:E},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:E},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:E},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:E},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:E},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:E},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:E},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:E,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:E},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:E,stack:"{3}"}};function v(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function I(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=`[^${v(t.delimiter||"/#?")}]+?`,i=[];let s=0,a=0,u="";const c=e=>{if(a<n.length&&n[a].type===e)return n[a++].value},l=e=>{const t=c(e);if(void 0!==t)return t;const{type:r,index:o}=n[a];throw new TypeError(`Unexpected ${r} at ${o}, expected ${e}`)},f=()=>{let e,t="";for(;e=c("CHAR")||c("ESCAPED_CHAR");)t+=e;return t};for(;a<n.length;){const e=c("CHAR"),t=c("NAME"),n=c("PATTERN");if(t||n){let a=e||"";-1===r.indexOf(a)&&(u+=a,a=""),u&&(i.push(u),u=""),i.push({name:t||s++,prefix:a,suffix:"",pattern:n||o,modifier:c("MODIFIER")||""});continue}const a=e||c("ESCAPED_CHAR");if(a){u+=a;continue}u&&(i.push(u),u="");if(c("OPEN")){const e=f(),t=c("NAME")||"",n=c("PATTERN")||"",r=f();l("CLOSE"),i.push({name:t||(n?s++:""),pattern:t&&!n?o:n,prefix:e,suffix:r,modifier:c("MODIFIER")||""})}else l("END")}return i}function x(e,t){return function(e,t={}){const n=I(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 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=`[${v(n.endsWith||"")}]|$`,u=`[${v(n.delimiter||"/#?")}]`;let c=o?"^":"";for(const n of e)if("string"==typeof n)c+=v(s(n));else{const e=v(s(n.prefix)),r=v(s(n.suffix));if(n.pattern)if(t&&t.push(n),e||r)if("+"===n.modifier||"*"===n.modifier){const t="*"===n.modifier?"?":"";c+=`(?:${e}((?:${n.pattern})(?:${r}${e}(?:${n.pattern}))*)${r})${t}`}else c+=`(?:${e}(${n.pattern})${r})${n.modifier}`;else c+=`(${n.pattern})${n.modifier}`;else c+=`(?:${e}${r})${n.modifier}`}if(i)r||(c+=`${u}?`),c+=n.endsWith?`(?=${a})`:"$";else{const t=e[e.length-1],n="string"==typeof t?u.indexOf(t[t.length-1])>-1:void 0===t;r||(c+=`(?:${u}(?=${a}))?`),n||(c+=`(?=${u}|${a})`)}return new RegExp(c,I(n))}(O(e,n),t,n)}function $(e,t,n){return e instanceof RegExp?function(e,t){if(!t)return e;const n=e.source.match(/\((?!\?)/g);if(n)for(let e=0;e<n.length;e++)t.push({name:e,prefix:"",suffix:"",modifier:"",pattern:""});return e}(e,t):Array.isArray(e)?function(e,t,n){const r=e.map((e=>$(e,t,n).source));return new RegExp(`(?:${r.join("|")})`,I(n))}(e,t,n):w(e,t,n)}const{INVALID_ROUTE_QUERY:A,MISSING_ROUTE_TEMPLATE:N,MISSING_PAGE_BINDING:_,INVALID_PAGE_BINDING:T,INVALID_URI_SYNTAX:P}=R;function D(e){const{routes:t,caseSensitive:o}=e;return t.map((e=>function(e,t=!1){const o=[],{uri:u,page:c}=e;b(!!u,N),b(function(e=""){return!["*","+","(",")",";"].some((t=>e.indexOf(t)>=0))}(u),P),b(!!c,_);const l=n(u),f=r(u),p=$(l,o,{sensitive:t,end:!1!==e.exact}),d=x(l,{encode:encodeURIComponent}),h=function(e){const t={};return Object.keys(e).forEach((n=>{const r=e[n];b(!i(n)||null===r,A),i(n)?t[n.substr(1)]={routeParamName:n}:r&&i(r)?t[n]={routeParamName:r}:t[n]={literalValue:null===r?null:r}})),t}(f),g=function(e,t=!1){return 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}}(h,t),m={original:e,regex:p,params:o,toPath:d,compiledQuery:h,queryMatcher:g};return b(function(e){const{original:{page:t}={},params:n,compiledQuery:r}=e,o=t?t.type:t,u=(t?t.attributes:t)||{},c=(t?t.state:t)||{};if("string"!=typeof o||"object"!=typeof u||"object"!=typeof c)return!1;const l=Object.values(n).map((({name:e})=>e)),f=a(r),p=[...l,...f],d=Object.values(u).filter(i).map(s),h=Object.values(c).filter(i).map(s),g=p.every((e=>"string"==typeof e&&(d.indexOf(e)>=0||h.indexOf(e)>=0))),m=p.length===d.length+h.length;return!!(t&&o&&u&&c&&g&&m)}(m),T),m}(e,o)))}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 L{constructor(e){this.deprecatedConfig={},this.routeHandlerId=0,this.compiledRoutes=[],this.routeObservable=C(),this.config={basePath:e.basePath||"",caseSensitive:Boolean(e.caseSensitive),routes:e.routes||[],generateUrl:e=>d(e,this.compiledRoutes,this.config.basePath),parseUrl:e=>function(e,t,n=""){const r=p(e,t,n);return r&&r.route&&r.route.pageReference?r.route.pageReference:null}(e,this.compiledRoutes,this.config.basePath)};const{DEPRECATED_getRouteFromUrl:t,DEPRECATED_getUrlFromRoute:n}=e;t&&(this.deprecatedConfig.DEPRECATED_getRouteFromUrl=t),n&&(this.deprecatedConfig.DEPRECATED_getUrlFromRoute=n),this.compiledRoutes=D(this.config)}generateUrl(e){const{DEPRECATED_getUrlFromRoute:t}=this.deprecatedConfig;return t?t(e,this.config.generateUrl.bind(this,e)):this.config.generateUrl(e)}parseUrl(e){const{DEPRECATED_getRouteFromUrl:t}=this.deprecatedConfig;return t?t(e,this.config.parseUrl.bind(this,e)):this.config.parseUrl(e)}matchRoute(e){const t="string"==typeof e?e:this.generateUrl(e);if(null===t)return null;const n=p(t,this.compiledRoutes,this.config.basePath),r=n&&g(n.route.pageReference,n.routeDefinition,this.config.basePath);return n&&r?{pathMatch:r,route:n.route,routeDefinition:n.routeDefinition.original}:null}navigate(e){const t=this.matchRoute(e);if(!t)throw new Error(y(R.MISSING_ROUTE,[JSON.stringify(e)]));this.pendingRoute={...t},this._mapView(this.pendingRoute)}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}async _mapView(e){const t=Math.random();this.routeHandlerId=t;const n=(await e.routeDefinition.handler()).default;if(!n)throw new Error("Route did not have a route handler");return this.routeHandler=new n((e=>{this._updateView(t,e)})),this.routeHandler&&this.routeHandler.update(e.route),!0}_updateView(e,t){if(!t||!t.viewset||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,viewset:n})}}function U(e={}){return new L(e)}e(L,{fields:["deprecatedConfig","routeHandlerId"]});export{U as createRouter};
@@ -1 +1 @@
1
- import{registerTemplate as e,registerDecorators as t,createContextProvider as i,registerComponent as r,LightningElement as n}from"lwc";function s(e,t,i,r){const{s:n}=e;return[n("",{key:0},[],i)]}var o=e(s);function a(e){if(null==e)throw new TypeError("Provider must be defined.")}s.slots=[""],s.stylesheets=[],s.stylesheetToken="lwr-routerContainer_routerContainer";class c{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){a(e);const i=this.getInfo(e);i.contextValue=t,i.consumers.forEach((e=>e.provide(t)))}getContext(e){a(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){a(e),this.infoMap.delete(e)}subscribeContext(e,t){a(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){a(e),this.getInfo(e).consumers.delete(t)}}t(c,{fields:["infoMap"]});const d=1;function h(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function l(e,t){const i={...e,message:h(e.message,t)};return e.address&&(i.address=h(e.address,t)),i}function u(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${h(e.message,t)}`}(t,i))}const p={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:d},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:d},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:d},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:d},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:d},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:d,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:d,address:"{0}"},PRENAV_FAILED:{code:"LWR4008",message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:"LWR4009",message:'A route definition must contain a "uri" property.',level:d},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:d},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:d},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:d,url:""},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:d,url:""},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:d,url:""},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:d,url:""},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:d},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:d}},v=new WeakMap;function g(e){var t,i;return i=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)}},t.contextSchema={value:"required"},i}const m=g(new c(void 0)),f=g(new c(void 0)),b=g(new c(void 0)),E=new c(void 0),I=class extends(g(E)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],n=r&&r.module||r;let s;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){s=l(p.VIEW_IMPORT_FAILED,[i,e.message])}else s=l(p.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(s)}}};function N(){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 R(e=""){return e=e||"",decodeURIComponent(e)}function w(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const _=`universalcontainergetnavigationcontext${w()}`,x=i(b),C=i(f),L=i(I),P=i(m);function y(e,t,i,r){r.setContext(t,e),i(t,{consumerConnectedCallback:r.subscribeContext.bind(r,t),consumerDisconnectedCallback:r.unsubscribeContext.bind(r,t)})}function M(){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:(n,s=!0)=>{(e=>{i.push(e)})(n),n.next&&e&&s&&n.next(e),t&&r(t);const o=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(o)}}}}const U=`universalcontainernavigationevent${w()}`,S=`universalcontainerparentevent${w()}`;class A{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=N(),this.errorNavFilters=N(),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(l(p.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.routeObservable=M()}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;this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},f.setContext(this.target,e.route.pageReference),b.setContext(this.target,this.committedRoute.route),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(S,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:e=>this.generateUrl(e),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};v.set(i.id,i)}(this.contextId,e),y(this.contextId,this.target,P,m),y(void 0,this.target,C,f),y(void 0,this.target,x,b),y(void 0,this.target,L,I),this.router.subscribe((e=>{const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};I.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),this.target.addEventListener(U,this._handleNavigationEvent),this.target.addEventListener(S,this._handleParentEvent),this.target.addEventListener(_,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)})),this.connected=!0}disconnect(){this.target.removeEventListener(U,this._handleNavigationEvent),this.target.removeEventListener(S,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((()=>{u(!this.child,p.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t){try{this.parent||await this.preProcess(e)}catch(e){if(e.code)return this.processError(e),!1;throw e}const i=this.router.parseUrl(e);return i&&this.router.navigate(i),!0}preProcess(e){const t=this.router.parseUrl(e),i=t&&this.router.matchRoute(t);if(!i)return Promise.reject(l(p.MISSING_ROUTE,[e]));this.pendingRoute={url:e,...i};return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(l(p.PRENAV_FAILED,[e]))))}processError(e){this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t){let i=this.router.generateUrl(e);if(i){i=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(i)}this._sendEvent(U,{url:i,replace:t,address:e})}generateUrl(e){const t=this.router.generateUrl(e);if(!t)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${t}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){this.target.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_stripUrlForChild(e){return this.pendingRoute&&0===e.indexOf(this.pendingRoute.pathMatch)?e.replace(this.pendingRoute.pathMatch,""):e}}function T(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[R(i)]=R(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,"")}t(A,{fields:["pendingRoute","committedRoute","contextId","connected","preNavFilters","errorNavFilters","_handleNavigationEvent","_handleParentEvent"]});class W extends A{constructor(...e){super(...e),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){this.parent||this.catchBrowserUpdate(T(document.location.href))}disconnect(){super.disconnect(),window.removeEventListener("popstate",this.onpopstate)}async process(e,t,i=!0){const r=await super.process(e);return r&&!this.historyDisabled&&i&&this.connected&&!this.parent&&(t?function(e,t){const i=t||{};window.history.replaceState(i,"",e)}(e):function(e,t){const i=t||{};window.history.pushState(i,"",e)}(e)),r}catchBrowserUpdate(e){this.process(e,!1,!1)}}t(W,{fields:["historyDisabled"]});let D=!1;class O extends n{constructor(...e){super(...e),this.router=void 0,this.historyDisabled=!1}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new A(t,i,e):new W(t,i,e),n={addPreNavigate:e=>(r.addPreNavigate(e),n),addPostNavigate:e=>(r.subscribe(e),n),addErrorNavigate:e=>(r.addErrorNavigate(e),n),connect:()=>{r.connect(),u(!D||!!r.parent,p.MULTIPLE_ROOTS),D=D||!r.parent,n.id=r.contextId},disconnect:()=>{D=D&&!!r.parent,r.disconnect()}};return n}(this,e,this.router),this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect())}preNavigate(e){const t=this._createEvent("prenavigate",e,!0);return this.dispatchEvent(t),!t.defaultPrevented}postNavigate(e){this.dispatchEvent(this._createEvent("postnavigate",e))}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})}}t(O,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var F=r(O,{tmpl:o});export default F;
1
+ import{registerTemplate as e,registerDecorators as t,createContextProvider as i,registerComponent as r,LightningElement as s}from"lwc";function n(e,t,i,r){const{s:s}=e;return[s("",{key:0},[],i)]}var o=e(n);function a(e){if(null==e)throw new TypeError("Provider must be defined.")}n.slots=[""],n.stylesheets=[],n.stylesheetToken="lwr-routerContainer_routerContainer";class c{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){a(e);const i=this.getInfo(e);i.contextValue=t,i.consumers.forEach((e=>e.provide(t)))}getContext(e){a(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){a(e),this.infoMap.delete(e)}subscribeContext(e,t){a(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){a(e),this.getInfo(e).consumers.delete(t)}}t(c,{fields:["infoMap"]});const d=1;function h(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function l(e,t){const i={...e,message:h(e.message,t)};return e.address&&(i.address=h(e.address,t)),e.stack&&(i.stack=h(e.stack,t)),i}function u(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${h(e.message,t)}`}(t,i))}const p={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:d},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:d},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:d},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:d},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:d},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:d,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:d,address:"{0}"},PRENAV_FAILED:{code:"LWR4008",message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:"LWR4009",message:'A route definition must contain a "uri" property.',level:d},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:d},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:d},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:d},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:d},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:d},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:d},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:d,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:d},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:d,stack:"{3}"}},v=new WeakMap;function g(e){var t,i;return i=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)}},t.contextSchema={value:"required"},i}const m=g(new c(void 0)),f=g(new c(void 0)),E=g(new c(void 0)),b=new c(void 0),I=class extends(g(b)){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?l(p.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):l(p.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else o=l(p.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(o)}}};function R(){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 w(e=""){return e=e||"",decodeURIComponent(e)}function N(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const _=`universalcontainergetnavigationcontext${N()}`,C=i(E),x=i(f),L=i(I),P=i(m);function y(e,t,i,r){r.setContext(t,e),i(t,{consumerConnectedCallback:r.subscribeContext.bind(r,t),consumerDisconnectedCallback:r.unsubscribeContext.bind(r,t)})}function M(){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 S=`universalcontainernavigationevent${N()}`,A=`universalcontainerparentevent${N()}`;class T{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=R(),this.errorNavFilters=R(),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(l(p.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.routeObservable=M()}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;this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},f.setContext(this.target,e.route.pageReference),E.setContext(this.target,this.committedRoute.route),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(A,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:e=>this.generateUrl(e),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};v.set(i.id,i)}(this.contextId,e),y(this.contextId,this.target,P,m),y(void 0,this.target,x,f),y(void 0,this.target,C,E),y(void 0,this.target,L,I),this.router.subscribe((e=>{const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};I.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),this.target.addEventListener(S,this._handleNavigationEvent),this.target.addEventListener(A,this._handleParentEvent),this.target.addEventListener(_,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)})),this.connected=!0}disconnect(){this.target.removeEventListener(S,this._handleNavigationEvent),this.target.removeEventListener(A,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((()=>{u(!this.child,p.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t){try{this.parent||await this.preProcess(e)}catch(e){if(e.code)return this.processError(e),!1;throw e}const i=this.router.parseUrl(e);return i&&this.router.navigate(i),!0}preProcess(e){const t=this.router.parseUrl(e),i=t&&this.router.matchRoute(t);if(!i)return Promise.reject(l(p.MISSING_ROUTE,[e]));this.pendingRoute={url:e,...i};return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(l(p.PRENAV_FAILED,[e]))))}processError(e){this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t){let i=this.router.generateUrl(e);if(i){i=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(i)}this._sendEvent(S,{url:i,replace:t,address:e})}generateUrl(e){const t=this.router.generateUrl(e);if(!t)return null;return`${this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||""}${t}`}subscribe(e,t){return this.routeObservable.subscribe({next:e,error:()=>{},complete:()=>{}},Boolean(t))}_sendEvent(e,t){this.target.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_stripUrlForChild(e){return this.pendingRoute&&0===e.indexOf(this.pendingRoute.pathMatch)?e.replace(this.pendingRoute.pathMatch,""):e}}function U(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[w(i)]=w(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,"")}t(T,{fields:["pendingRoute","committedRoute","contextId","connected","preNavFilters","errorNavFilters","_handleNavigationEvent","_handleParentEvent"]});class W extends T{constructor(...e){super(...e),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){this.parent||this.catchBrowserUpdate(U(document.location.href))}disconnect(){super.disconnect(),window.removeEventListener("popstate",this.onpopstate)}async process(e,t,i=!0){const r=await super.process(e);return r&&!this.historyDisabled&&i&&this.connected&&!this.parent&&(t?function(e,t){const i=t||{};window.history.replaceState(i,"",e)}(e):function(e,t){const i=t||{};window.history.pushState(i,"",e)}(e)),r}catchBrowserUpdate(e){this.process(e,!1,!1)}}t(W,{fields:["historyDisabled"]});let D=!1;class O extends s{constructor(...e){super(...e),this.router=void 0,this.historyDisabled=!1}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new T(t,i,e):new W(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(),u(!D||!!r.parent,p.MULTIPLE_ROOTS),D=D||!r.parent,s.id=r.contextId},disconnect:()=>{D=D&&!!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))}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})}}t(O,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var k=r(O,{tmpl:o});export default k;
@@ -4,6 +4,6 @@ declare type PageReferenceContext = PageReference | undefined;
4
4
  * Services @wire(CurrentPageReference) requests.
5
5
  * Hooks up to an Observable from the current navigation context.
6
6
  */
7
- export declare const CurrentPageReference: import("../contextUtils/contextUtils").ContextualWireAdapter<PageReferenceContext, unknown, PageReferenceContext>;
7
+ export declare const CurrentPageReference: import("lwr/contextUtils").ContextualWireAdapter<PageReferenceContext, unknown, PageReferenceContext>;
8
8
  export {};
9
9
  //# sourceMappingURL=currentPageReference.d.ts.map
@@ -4,6 +4,6 @@ declare type RouteContext = RouteInstance | undefined;
4
4
  * Services @wire(CurrentRoute) requests.
5
5
  * Hooks up to an Observable from the current navigation context.
6
6
  */
7
- export declare const CurrentRoute: import("../contextUtils/contextUtils").ContextualWireAdapter<RouteContext, unknown, RouteContext>;
7
+ export declare const CurrentRoute: import("lwr/contextUtils").ContextualWireAdapter<RouteContext, unknown, RouteContext>;
8
8
  export {};
9
9
  //# sourceMappingURL=currentRoute.d.ts.map
@@ -16,8 +16,10 @@ export const CurrentView = class CurrentView extends generateContextualWireAdapt
16
16
  async update(config, context) {
17
17
  if (context) {
18
18
  const viewName = config && config.viewName ? config.viewName : 'default';
19
- const viewEntry = context.viewset[viewName];
20
- const viewImporter = viewEntry && viewEntry.module || viewEntry;
19
+ const viewEntry = context.viewset[viewName]; // either ViewInfo or an importer function
20
+
21
+ const viewInfo = viewEntry;
22
+ const viewImporter = viewInfo && viewInfo.module || viewEntry;
21
23
  let importError;
22
24
 
23
25
  if (viewImporter) {
@@ -32,7 +34,13 @@ export const CurrentView = class CurrentView extends generateContextualWireAdapt
32
34
  throw new Error('error occurred with view import');
33
35
  }
34
36
  } catch (e) {
35
- importError = generateMessageObject(messages.VIEW_IMPORT_FAILED, [viewName, e.message]);
37
+ const error = e;
38
+
39
+ if (viewInfo.specifier) {
40
+ importError = generateMessageObject(messages.VIEW_IMPORT_FAILED_WITH_SPECIFIER, [viewInfo.specifier, viewName, error.message, error.stack || '']);
41
+ } else {
42
+ importError = generateMessageObject(messages.VIEW_IMPORT_FAILED, [viewName, error.message, error.stack || '']);
43
+ }
36
44
  }
37
45
  } else {
38
46
  importError = generateMessageObject(messages.VIEW_MISSING, [viewName]);
@@ -52,8 +52,8 @@ export declare class DomRouterImpl implements DomRouter {
52
52
  connected: boolean;
53
53
  parent?: DomRouter;
54
54
  child?: DomRouter;
55
- preNavFilters: import("../routerUtils/filterUtils").FilterChain<RouteChange>;
56
- errorNavFilters: import("../routerUtils/filterUtils").FilterChain<MessageObject>;
55
+ preNavFilters: import("lwr/routerUtils").FilterChain<RouteChange>;
56
+ errorNavFilters: import("lwr/routerUtils").FilterChain<MessageObject>;
57
57
  /**
58
58
  * Create and configure the Router.
59
59
  *
@@ -1,5 +1,5 @@
1
1
  export declare type ContextId = () => void;
2
2
  declare type NavigationContextType = ContextId | undefined;
3
- export declare const NavigationContext: import("../contextUtils/contextUtils").ContextualWireAdapter<NavigationContextType, unknown, NavigationContextType>;
3
+ export declare const NavigationContext: import("lwr/contextUtils").ContextualWireAdapter<NavigationContextType, unknown, NavigationContextType>;
4
4
  export {};
5
5
  //# sourceMappingURL=navigationContext.d.ts.map
@@ -55,7 +55,7 @@ export function createObservable() {
55
55
  const subscribe = (obs, replay = true) => {
56
56
  addObserver(obs); // Push the current value and error, if they exist.
57
57
 
58
- if (obs.next && currentValue && replay) {
58
+ if (currentValue && replay) {
59
59
  obs.next(currentValue);
60
60
  }
61
61
 
@@ -32,6 +32,10 @@ export function generateMessageObject(info, args) {
32
32
  messageObject.address = replaceArgs(info.address, args);
33
33
  }
34
34
 
35
+ if (info.stack) {
36
+ messageObject.stack = replaceArgs(info.stack, args);
37
+ }
38
+
35
39
  return messageObject;
36
40
  }
37
41
  export function invariant(condition, errorInfo, args) {
@@ -101,35 +105,38 @@ export const messages = {
101
105
  INVALID_ROUTE_QUERY: {
102
106
  code: `${ERROR_CODE_PREFIX}4019`,
103
107
  message: 'Invalid query param in route definition.',
104
- level: DiagnosticLevel.Error,
105
- url: ''
108
+ level: DiagnosticLevel.Error
106
109
  },
107
110
  MISSING_PAGE_BINDING: {
108
111
  code: `${ERROR_CODE_PREFIX}4020`,
109
112
  message: 'Route definition must provide page binding',
110
- level: DiagnosticLevel.Error,
111
- url: ''
113
+ level: DiagnosticLevel.Error
112
114
  },
113
115
  INVALID_PAGE_BINDING: {
114
116
  code: `${ERROR_CODE_PREFIX}4021`,
115
117
  message: 'Invalid page binding in route definition',
116
- level: DiagnosticLevel.Error,
117
- url: ''
118
+ level: DiagnosticLevel.Error
118
119
  },
119
120
  INVALID_URI_SYNTAX: {
120
121
  code: `${ERROR_CODE_PREFIX}4022`,
121
122
  message: 'Invalid uri syntax. URI cannot contain *, +, (, ), ',
122
- level: DiagnosticLevel.Error,
123
- url: ''
123
+ level: DiagnosticLevel.Error
124
124
  },
125
125
  VIEW_IMPORT_FAILED: {
126
126
  code: `${ERROR_CODE_PREFIX}4023`,
127
127
  message: 'Error importing view with name "{0}", failure was: {1}',
128
- level: DiagnosticLevel.Error
128
+ level: DiagnosticLevel.Error,
129
+ stack: '{2}'
129
130
  },
130
131
  VIEW_MISSING: {
131
132
  code: `${ERROR_CODE_PREFIX}4024`,
132
133
  message: 'Expected a view with name "{0}" in the viewset',
133
134
  level: DiagnosticLevel.Error
135
+ },
136
+ VIEW_IMPORT_FAILED_WITH_SPECIFIER: {
137
+ code: `${ERROR_CODE_PREFIX}4025`,
138
+ message: 'Error importing module "{0}" from view with name "{1}", failure was: {2}',
139
+ level: DiagnosticLevel.Error,
140
+ stack: '{3}'
134
141
  }
135
142
  };
@@ -80,7 +80,9 @@ function lexer(str) {
80
80
  const code = str.charCodeAt(j);
81
81
 
82
82
  if ( // `0-9`
83
- code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || // `_`
83
+ code >= 48 && code <= 57 || // `A-Z`
84
+ code >= 65 && code <= 90 || // `a-z`
85
+ code >= 97 && code <= 122 || // `_`
84
86
  code === 95) {
85
87
  name += str[j++];
86
88
  continue;
@@ -116,6 +116,7 @@ export interface MessageObject {
116
116
  code: string | number;
117
117
  message: string;
118
118
  level: number;
119
+ stack?: string;
119
120
  url?: string;
120
121
  address?: string;
121
122
  }
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.6.0-alpha.2",
9
- "homepage": "https://lwr.dev/",
8
+ "version": "0.6.0-alpha.6",
9
+ "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/salesforce/lwr.git",
@@ -40,5 +40,5 @@
40
40
  "engines": {
41
41
  "node": ">=14.15.4 <17"
42
42
  },
43
- "gitHead": "5b0f761312e566fdaeec26ac3dbb704f8421b1a9"
43
+ "gitHead": "5d624e196dd46787399e6a269479508abe236081"
44
44
  }