@lwrjs/router 0.6.0-alpha.9 → 0.6.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 +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)),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
+ import{registerDecorators as e}from"lwc";function t(e){if(null==e)throw new TypeError("Provider must be defined.")}class o{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,o){t(e);const n=this.getInfo(e);n.contextValue=o,n.consumers.forEach((e=>e.provide(o)))}getContext(e){t(e);const{contextValue:o}=this.getInfo(e);return void 0!==o?o:this.defaultValue}clearContext(e){t(e),this.infoMap.delete(e)}subscribeContext(e,o){t(e);const{consumers:n,contextValue:a}=this.getInfo(e);n.has(o)||(n.add(o),o.provide(a))}unsubscribeContext(e,o){t(e),this.getInfo(e).consumers.delete(o)}}e(o,{fields:["infoMap"]});const n=1;function a(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,o)=>t[o])):e}function s(e,t){return`${e.code}: ${a(e.message,t)}`}function i(e,t){const o={...e,message:a(e.message,t)};return e.address&&(o.address=a(e.address,t)),e.stack&&(o.stack=a(e.stack,t)),o}const r={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:n},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:n},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:n},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:n},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:n},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:n,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:n,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:n},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:n},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:n},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:n},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:n},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:n},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:n},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:n,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:n},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:n,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:n},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:n}},c=new WeakMap;function l(e){const t=c.get(e);if(!t||!t.value)throw new Error(s(r.MISSING_CONTEXT));return t.value}function d(e,t){const o={id:e,value:t,update:e=>{o.value=e}};return c.set(o.id,o),o}function u(e){var t,o;return o=t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,o){e.setContext(t,o)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,o){e.subscribeContext(t,o)}static unsubscribeContext(t,o){e.unsubscribeContext(t,o)}},t.contextSchema={value:"required"},o}const I=u(new o(void 0)),v=u(new o(void 0)),g=u(new o(void 0)),m=new o(void 0),f=class extends(u(m)){async update(e,t){if(t){const o=e&&e.viewName?e.viewName:"default",n=t.viewset[o],a=n,s=a&&a.module||n;let c;if(s)try{const e=await s(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;c=a.specifier?i(r.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[a.specifier,o,t.message,t.stack||""]):i(r.VIEW_IMPORT_FAILED,[o,t.message,t.stack||""])}else c=i(r.VIEW_MISSING,[o]);t.onComplete&&t.onComplete(c)}}};function h(e,t,o){l(e).navigate(t,o)}function E(e,t){return l(e).generateUrl(t)}const _=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,R=Symbol("Navigate"),p=Symbol("GenerateUrl"),L=Symbol("NavContext"),N=Symbol("NavContext");function C(e){!function(e,t,o){if(!e)throw new Error(s(t,o))}("function"==typeof e.prototype.dispatchEvent,r.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[N](){if(!this[L]&&(this.dispatchEvent(new CustomEvent(_,{bubbles:!0,composed:!0,detail:{callback:e=>{this[L]=e}}})),!this[L]))throw new Error(s(r.MISSING_CONTEXT))}[R](e,t){this[N](),h(this[L],e,t)}async[p](e){return this[N](),E(this[L],e)}}}C.Navigate=R,C.GenerateUrl=p,C.NavContext=L;export{o as ContextInfo,v as CurrentPageReference,g as CurrentRoute,f as CurrentView,I as NavigationContext,C 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},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
+ 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),d=u(l,t),p=c(f,t);if(d&&p){const e={...d,...p},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 d(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 p(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)),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 u&&c&&l&&d&&f&&p}));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:d={}}=u,p=c(h(r.filter((({name:e})=>"string"==typeof e)).map((({name:e})=>e)),e,{attributeBindings:f,stateBindings:d})),g=function(e,t,n){const{compiledQuery:r,original:{page:{state: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:d}),t);return`${n}${p}${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 R(e,t,n){if(!e)throw new Error(y(t,n))}const b={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}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:E},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:E}};function I(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function v(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=`[^${I(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=v(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 A(e,t,n){return function(e,t,n={}){const{strict:r=!1,start:o=!0,end:i=!0,encode:s=(e=>e)}=n,a=`[${I(n.endsWith||"")}]|$`,u=`[${I(n.delimiter||"/#?")}]`;let c=o?"^":"";for(const n of e)if("string"==typeof n)c+=I(s(n));else{const e=I(s(n.prefix)),r=I(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,v(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("|")})`,v(n))}(e,t,n):A(e,t,n)}const{INVALID_ROUTE_QUERY:N,MISSING_ROUTE_TEMPLATE:w,MISSING_PAGE_BINDING:T,INVALID_PAGE_BINDING:$,INVALID_URI_SYNTAX:D}=b;function L(e){const{routes:t,caseSensitive:o}=e;return t.map((e=>function(e,t=!1){const o=[],{uri:u,page:c}=e;R(!!u,w),R(function(e=""){return!["*","+","(",")",";"].some((t=>e.indexOf(t)>=0))}(u),D),R(!!c,T);const l=n(u),f=r(u),d=_(l,o,{sensitive:t,end:!1!==e.exact}),p=x(l,{encode:encodeURIComponent}),h=function(e){const t={};return Object.keys(e).forEach((n=>{const r=e[n];R(!i(n)||null===r,N),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:d,params:o,toPath:p,compiledQuery:h,queryMatcher:g};return R(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),d=[...l,...f],p=Object.values(u).filter(i).map(s),h=Object.values(c).filter(i).map(s),g=d.every((e=>"string"==typeof e&&(p.indexOf(e)>=0||h.indexOf(e)>=0))),m=d.length===p.length+h.length;return!!(t&&o&&u&&c&&g&&m)}(m),$),m}(e,o)))}function P(){let e,t,n=[];const r=r=>{n.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{n.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{n.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),n=[],e=void 0,t=void 0},subscribe:(o,i=!0)=>{(e=>{n.push(e)})(o),e&&i&&o.next(e),t&&r(t);const s=n.length-1;return{unsubscribe:()=>(e=>{n=[...n.slice(0,e),...n.slice(e+1)]})(s)}}}}class U{constructor(e){this.deprecatedConfig={},this.routeHandlerId=0,this.compiledRoutes=[],this.routeObservable=P(),this.config={basePath:e.basePath||"",caseSensitive:Boolean(e.caseSensitive),routes:e.routes||[],generateUrl:e=>p(e,this.compiledRoutes,this.config.basePath),parseUrl:e=>function(e,t,n=""){const r=d(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=L(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=d(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}async resolveView(e){return new Promise(((t,n)=>{const r=this.matchRoute(e);return r?r.routeDefinition.handler().then((e=>{const o=e.default;if(!o)return n(y(b.INVALID_ROUTE_HANDLER,[r.routeDefinition.id]));const i=new o(t);i&&i.update(r.route)})):n(y(b.NO_ROUTE_MATCH,[JSON.stringify(e)]))}))}navigate(e){const t=this.matchRoute(e);if(!t)throw new Error(y(b.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(y(b.INVALID_ROUTE_HANDLER,[e.routeDefinition.id]));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 C(e={}){return new U(e)}e(U,{fields:["deprecatedConfig","routeHandlerId"]});export{C as createRouter};
@@ -1 +1 @@
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;
1
+ import{registerTemplate as e,registerDecorators as t,createContextProvider as i,registerComponent as r,LightningElement as n}from"lwc";var s=[function(e,t){return["span",t?"["+t+"]":""," {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;}"].join("")}];function o(e,t,i,r){const{s:n,h:s}=e;return[n("",{key:0},[],i),s("span",{attrs:{"aria-live":"polite","aria-atomic":"true"},context:{lwc:{dom:"manual"}},key:1},[])]}var a=e(o);function c(e){if(null==e)throw new TypeError("Provider must be defined.")}o.slots=[""],o.stylesheets=[],s&&o.stylesheets.push.apply(o.stylesheets,s),o.stylesheetToken="lwr-routerContainer_routerContainer";class d{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){c(e);const i=this.getInfo(e);i.contextValue=t,i.consumers.forEach((e=>e.provide(t)))}getContext(e){c(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){c(e),this.infoMap.delete(e)}subscribeContext(e,t){c(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){c(e),this.getInfo(e).consumers.delete(t)}}t(d,{fields:["infoMap"]});const h=1;function l(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function u(e,t){const i={...e,message:l(e.message,t)};return e.address&&(i.address=l(e.address,t)),e.stack&&(i.stack=l(e.stack,t)),i}function p(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${l(e.message,t)}`}(t,i))}const v={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:h},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:h},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:h},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:h},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:h},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:h,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:h,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:h},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:h},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:h},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:h},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:h},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:h},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:h},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:h,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:h},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:h,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:h},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:h}},g=new WeakMap;function m(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 f=m(new d(void 0)),E=m(new d(void 0)),b=m(new d(void 0)),I=new d(void 0),R=class extends(m(I)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],n=r,s=n&&n.module||r;let o;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;o=n.specifier?u(v.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[n.specifier,i,t.message,t.stack||""]):u(v.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else o=u(v.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(o)}}};function w(){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 N(e=""){return e=e||"",decodeURIComponent(e)}function _(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const x=`universalcontainergetnavigationcontext${_()}`,L=i(b),C=i(E),P=i(R),y=i(f);function T(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),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 A=`universalcontainernavigationevent${_()}`,S=`universalcontainerparentevent${_()}`;class U{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=w(),this.errorNavFilters=w(),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(u(v.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},E.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}};g.set(i.id,i)}(this.contextId,e),T(this.contextId,this.target,y,f),T(void 0,this.target,C,E),T(void 0,this.target,L,b),T(void 0,this.target,P,R),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)};R.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),this.target.addEventListener(A,this._handleNavigationEvent),this.target.addEventListener(S,this._handleParentEvent),this.target.addEventListener(x,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)})),this.connected=!0}disconnect(){this.target.removeEventListener(A,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((()=>{p(!this.child,v.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(u(v.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(u(v.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(A,{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 W(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[N(i)]=N(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(U,{fields:["pendingRoute","committedRoute","contextId","connected","preNavFilters","errorNavFilters","_handleNavigationEvent","_handleParentEvent"]});class D extends U{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(W(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(D,{fields:["historyDisabled"]});let O=!1;class k extends n{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=document.title}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new U(t,i,e):new D(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(),p(!O||!!r.parent,v.MULTIPLE_ROOTS),O=O||!r.parent,n.id=r.contextId},disconnect:()=>{O=O&&!!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));const t=e.routeDefinition.metadata&&e.routeDefinition.metadata.title;t&&(this.currentTitle=t,document.title=t),this.template.querySelector("span").innerHTML=this.currentTitle}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const 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(k,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var F=r(k,{tmpl:a});export default F;
@@ -4,7 +4,7 @@
4
4
  <slot name="error"></slot>
5
5
  </template>
6
6
  </div>
7
- <div role="region" aria-live="polite" tabindex="-1">
7
+ <div role="region" tabindex="-1">
8
8
  <lwr-dynamic lwc:dynamic={viewCtor}></lwr-dynamic>
9
9
  </div>
10
10
  </template>
@@ -9,10 +9,7 @@ export default class Outlet extends LightningElement {
9
9
  viewName = 'default';
10
10
  viewCtor = undefined;
11
11
  previousViewCtor = undefined;
12
- hasError = false; // Get a reference to the navigation context.
13
- // TODO: Wire decorator arguments after wire reform don't match
14
- // Github issue -> https://github.com/salesforce/lwc/issues/2026
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ hasError = false; // Get a reference to the current view
16
13
 
17
14
  @wire(CurrentView, {
18
15
  viewName: '$viewName'
@@ -106,6 +106,42 @@ class RouterImpl {
106
106
  routeDefinition: match.routeDefinition.original
107
107
  };
108
108
  }
109
+ /**
110
+ * Given an address, return the associated viewset by calling the route handler.
111
+ *
112
+ * @param address - The address to match to a viewset
113
+ */
114
+
115
+
116
+ async resolveView(address) {
117
+ return new Promise((resolve, reject) => {
118
+ // get the RoutingMatch: { pathMatch, route, routeDefinition }
119
+ const routingMatch = this.matchRoute(address);
120
+
121
+ if (!routingMatch) {
122
+ return reject(generateMessage(messages.NO_ROUTE_MATCH, [JSON.stringify(address)]));
123
+ } // retrieve the route handler and use it to get the RouteDestination
124
+ // handler ~= import('my/handlerModule');
125
+
126
+
127
+ return routingMatch.routeDefinition.handler().then(handlerModule => {
128
+ // the route handler class is the module's default export
129
+ const routeHandlerClass = handlerModule.default;
130
+
131
+ if (!routeHandlerClass) {
132
+ return reject(generateMessage(messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id]));
133
+ } // instantiate an instance of the route handler class
134
+ // and pass in resolve() as the RouteHandlerCallback
135
+
136
+
137
+ const routeHandler = new routeHandlerClass(resolve); // update() will invoke the resolve callback with the matching RouteDestination/viewset
138
+
139
+ if (routeHandler) {
140
+ routeHandler.update(routingMatch.route);
141
+ }
142
+ });
143
+ });
144
+ }
109
145
  /**
110
146
  * Process the given URL by matching it to an existing route and looking up
111
147
  * the associated view
@@ -163,7 +199,7 @@ class RouterImpl {
163
199
  const routeHandlerClass = handlerModule.default;
164
200
 
165
201
  if (!routeHandlerClass) {
166
- throw new Error('Route did not have a route handler');
202
+ throw new Error(generateMessage(messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id]));
167
203
  }
168
204
 
169
205
  this.routeHandler = new routeHandlerClass(routeDestination => {
@@ -0,0 +1,12 @@
1
+ span {
2
+ position: absolute;
3
+ margin: -1px;
4
+ border: 0;
5
+ padding: 0;
6
+ width: 1px;
7
+ height: 1px;
8
+ overflow: hidden;
9
+ clip: rect(0 0 0 0);
10
+ text-transform: none;
11
+ white-space: nowrap;
12
+ }
@@ -13,37 +13,25 @@ export default class RouterContainer extends LightningElement {
13
13
  routerApi?: RouterApi;
14
14
  router?: Router<PageReference>;
15
15
  historyDisabled: boolean;
16
+ currentTitle: string;
17
+ constructor();
16
18
  /**
17
19
  * Create a router attached to this component.
18
20
  */
19
21
  connectedCallback(): void;
20
22
  /**
21
23
  * The preNavigate hook surfaced as a cancelable CustomEvent.
22
- * @param {object} - routeChange, the current and proposed routes
23
- * {
24
- * `current`: The navigation information `{ route, data }` for the current state, route may be `null`
25
- * `next`: The navigation information that will load next (if not stopped)
26
- * }
24
+ * @param {RouteChange} - the current and proposed route information
27
25
  */
28
26
  preNavigate(routeChange: RouteChange): boolean;
29
27
  /**
30
28
  * The postNavigate hook surfaced as a CustomEvent.
31
- * @param {object} - routingResult, the resulting route/view of the navigation
32
- * {
33
- * `current`: The navigation information `{ route, data }` for the current state
34
- * `previous`: The navigation information that just unloaded, route may be `null`
35
- * }
29
+ * @param {RoutingResult} - the resulting navigation information
36
30
  */
37
31
  postNavigate(routingResult: RoutingResult): void;
38
32
  /**
39
33
  * The errorNavigate hook surfaced as a CustomEvent.
40
- * @param {object} - error, the error encountered while navigating (if applicable)
41
- * {
42
- * `code`: an integer error code
43
- * `message`: a string error message
44
- * `level`: 'Error'
45
- * `url`: an optional URL where more information on the error can be found
46
- * }
34
+ * @param {MessageObject} - error, the error encountered while navigating (if applicable)
47
35
  */
48
36
  errorNavigate(error: MessageObject): boolean;
49
37
  /**
@@ -1,3 +1,4 @@
1
1
  <template>
2
2
  <slot></slot>
3
+ <span lwc:dom="manual" aria-live="polite" aria-atomic="true"></span>
3
4
  </template>
@@ -16,10 +16,16 @@ export default class RouterContainer extends LightningElement {
16
16
  router;
17
17
  @api
18
18
  historyDisabled = false;
19
+
20
+ constructor() {
21
+ super();
22
+ this.currentTitle = document.title;
23
+ }
19
24
  /**
20
25
  * Create a router attached to this component.
21
26
  */
22
27
 
28
+
23
29
  connectedCallback() {
24
30
  const config = {
25
31
  historyDisabled: this.historyDisabled,
@@ -38,11 +44,7 @@ export default class RouterContainer extends LightningElement {
38
44
  }
39
45
  /**
40
46
  * The preNavigate hook surfaced as a cancelable CustomEvent.
41
- * @param {object} - routeChange, the current and proposed routes
42
- * {
43
- * `current`: The navigation information `{ route, data }` for the current state, route may be `null`
44
- * `next`: The navigation information that will load next (if not stopped)
45
- * }
47
+ * @param {RouteChange} - the current and proposed route information
46
48
  */
47
49
 
48
50
 
@@ -54,26 +56,28 @@ export default class RouterContainer extends LightningElement {
54
56
  }
55
57
  /**
56
58
  * The postNavigate hook surfaced as a CustomEvent.
57
- * @param {object} - routingResult, the resulting route/view of the navigation
58
- * {
59
- * `current`: The navigation information `{ route, data }` for the current state
60
- * `previous`: The navigation information that just unloaded, route may be `null`
61
- * }
59
+ * @param {RoutingResult} - the resulting navigation information
62
60
  */
63
61
 
64
62
 
65
63
  postNavigate(routingResult) {
66
- this.dispatchEvent(this._createEvent('postnavigate', routingResult));
64
+ this.dispatchEvent(this._createEvent('postnavigate', routingResult)); // If the current route definition metadata contains a title, set it as the document title
65
+
66
+ const title = routingResult.routeDefinition.metadata && routingResult.routeDefinition.metadata.title;
67
+
68
+ if (title) {
69
+ this.currentTitle = title;
70
+ document.title = title;
71
+ } // Update the inner HTML of the aria-live region for screen readers
72
+ // This DOM node must be touched for every route change
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+
75
+
76
+ this.template.querySelector('span').innerHTML = this.currentTitle;
67
77
  }
68
78
  /**
69
79
  * The errorNavigate hook surfaced as a CustomEvent.
70
- * @param {object} - error, the error encountered while navigating (if applicable)
71
- * {
72
- * `code`: an integer error code
73
- * `message`: a string error message
74
- * `level`: 'Error'
75
- * `url`: an optional URL where more information on the error can be found
76
- * }
80
+ * @param {MessageObject} - error, the error encountered while navigating (if applicable)
77
81
  */
78
82
 
79
83
 
@@ -138,5 +138,15 @@ export const messages = {
138
138
  message: 'Error importing module "{0}" from view with name "{1}", failure was: {2}',
139
139
  level: DiagnosticLevel.Error,
140
140
  stack: '{3}'
141
+ },
142
+ NO_ROUTE_MATCH: {
143
+ code: `${ERROR_CODE_PREFIX}4026`,
144
+ message: 'A routing match cannot be found for: {0}',
145
+ level: DiagnosticLevel.Error
146
+ },
147
+ INVALID_ROUTE_HANDLER: {
148
+ code: `${ERROR_CODE_PREFIX}4027`,
149
+ message: 'Route definition "{0}" does not have a valid route handler module',
150
+ level: DiagnosticLevel.Error
141
151
  }
142
152
  };
@@ -15,6 +15,7 @@ export declare type RouteMatcher<TAddress> = {
15
15
  export declare type ViewMapper<TAddress> = {
16
16
  navigate(address: TAddress): void;
17
17
  subscribe(callback: RouteCallback, replay?: boolean): Unsubscriber;
18
+ resolveView(address: TAddress): Promise<RouteDestination>;
18
19
  };
19
20
  export declare type Router<TAddress = string> = ViewMapper<TAddress> & UrlMapper<TAddress> & RouteMatcher<TAddress>;
20
21
  export interface DEPRECATED_getRouteFromUrl {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.6.0-alpha.9",
8
+ "version": "0.6.2",
9
9
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
10
10
  "repository": {
11
11
  "type": "git",
@@ -40,5 +40,5 @@
40
40
  "engines": {
41
41
  "node": ">=14.15.4 <17"
42
42
  },
43
- "gitHead": "9cb371a5d01ef345660138a48fe0b3f0119d0799"
43
+ "gitHead": "ef85bdc48adde58b7c648561d67acbb408bbe189"
44
44
  }