@lwrjs/router 0.6.4 → 0.7.0-alpha.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.
- package/build/bundle/prod/lwr/navigation/navigation.js +1 -1
- package/build/bundle/prod/lwr/router/router.js +1 -1
- package/build/bundle/prod/lwr/routerContainer/routerContainer.js +1 -1
- package/build/cjs/modules/lwr/contextProvider/contextProvider.cjs +45 -0
- package/build/cjs/modules/lwr/contextUtils/contextInfo.cjs +58 -0
- package/build/cjs/modules/lwr/contextUtils/contextUtils.cjs +66 -0
- package/build/cjs/modules/lwr/contextUtils/navigationApiStore.cjs +49 -0
- package/build/cjs/modules/lwr/currentPageReference/currentPageReference.cjs +31 -0
- package/build/cjs/modules/lwr/currentRoute/currentRoute.cjs +31 -0
- package/build/cjs/modules/lwr/currentView/currentView.cjs +74 -0
- package/build/cjs/modules/lwr/domRouter/domRouter.cjs +271 -0
- package/build/cjs/modules/lwr/domRouterUtils/domRouterUtils.cjs +32 -0
- package/build/cjs/modules/lwr/domRouterUtils/historyUtils.cjs +21 -0
- package/build/cjs/modules/lwr/domRouterUtils/types.cjs +5 -0
- package/build/cjs/modules/lwr/domRouterUtils/uriUtils.cjs +66 -0
- package/build/cjs/modules/lwr/historyRouter/historyRouter.cjs +70 -0
- package/build/cjs/modules/lwr/navigation/navigation.cjs +45 -0
- package/build/cjs/modules/lwr/navigation/navigationApi.cjs +38 -0
- package/build/cjs/modules/lwr/navigation/navigationMixin.cjs +70 -0
- package/build/cjs/modules/lwr/navigationContext/navigationContext.cjs +31 -0
- package/build/cjs/modules/lwr/navigationMixinHacks/navigationMixinHacks.cjs +30 -0
- package/build/cjs/modules/lwr/observable/observable.cjs +58 -0
- package/build/cjs/modules/lwr/outlet/outlet.cjs +89 -0
- package/build/cjs/modules/lwr/router/router.cjs +150 -0
- package/build/cjs/modules/lwr/routerBridge/routerBridge.cjs +84 -0
- package/build/cjs/modules/lwr/routerContainer/routerContainer.cjs +99 -0
- package/build/cjs/modules/lwr/routerContainer/utils.cjs +60 -0
- package/build/cjs/modules/lwr/routerErrors/routerErrors.cjs +155 -0
- package/build/cjs/modules/lwr/routerUtils/filterUtils.cjs +50 -0
- package/build/cjs/modules/lwr/routerUtils/parseUtils.cjs +142 -0
- package/build/cjs/modules/lwr/routerUtils/pathToRegexp.cjs +340 -0
- package/build/cjs/modules/lwr/routerUtils/routeDefUtils.cjs +164 -0
- package/build/cjs/modules/lwr/routerUtils/routeUtils.cjs +179 -0
- package/build/cjs/modules/lwr/routerUtils/routerUtils.cjs +55 -0
- package/build/cjs/modules/lwr/routerUtils/typeUtils.cjs +74 -0
- package/build/cjs/modules/lwr/routerUtils/types.cjs +5 -0
- package/build/cjs/modules/lwr/routerUtils/uriUtils.cjs +85 -0
- package/build/cjs/services/index.cjs +121 -0
- package/build/cjs/services/module-provider/index.cjs +133 -0
- package/build/cjs/services/module-provider/utils.cjs +104 -0
- package/build/modules/lwr/domRouter/domRouter.d.ts +1 -0
- package/build/modules/lwr/domRouter/domRouter.js +37 -4
- package/build/modules/lwr/routerUtils/types.d.ts +1 -1
- package/build/services/index.d.ts +27 -0
- package/build/services/index.js +103 -0
- package/build/services/module-provider/index.d.ts +22 -0
- package/build/services/module-provider/index.js +126 -0
- package/build/services/module-provider/utils.d.ts +26 -0
- package/build/services/module-provider/utils.js +109 -0
- package/package.json +47 -11
- package/index.js +0 -1
- package/lwc.config.json +0 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
import{registerDecorators as e}from"lwc";function t(e){if(null==e)throw new TypeError("Provider must be defined.")}class
|
|
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:r}=this.getInfo(e);o.has(n)||(o.add(n),n.provide(r))}unsubscribeContext(e,n){t(e),this.getInfo(e).consumers.delete(n)}}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}e(n,{fields:["infoMap"]});const i=1;function s(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,n)=>t[n])):e}function c(e,t){return`${e.code}: ${s(e.message,t)}`}function l(e,t){const n=r(r({},e),{},{message:s(e.message,t)});return e.address&&(n.address=s(e.address,t)),e.stack&&(n.stack=s(e.stack,t)),n}const u={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:i},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:i},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:i},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:i},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:i},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:i,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:i,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:i},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:i},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:i},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:i},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:i},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:i},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:i},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:i,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:i},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:i,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:i},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:i}},d=new WeakMap;function v(e){const t=d.get(e);if(!t||!t.value)throw new Error(c(u.MISSING_CONTEXT));return t.value}function I(e,t){const n={id:e,value:t,update:e=>{n.value=e}};return d.set(n.id,n),n}function g(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,n){e.setContext(t,n)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,n){e.subscribeContext(t,n)}static unsubscribeContext(t,n){e.unsubscribeContext(t,n)}}).contextSchema={value:"required"},t}const f=g(new n(void 0)),m=g(new n(void 0)),p=g(new n(void 0)),h=new n(void 0),b=class extends(g(h)){async update(e,t){if(t){const n=e&&e.viewName?e.viewName:"default",o=t.viewset[n],r=o,a=r&&r.module||o;let i;if(a)try{const e=await a(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;i=r.specifier?l(u.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[r.specifier,n,t.message,t.stack||""]):l(u.VIEW_IMPORT_FAILED,[n,t.message,t.stack||""])}else i=l(u.VIEW_MISSING,[n]);t.onComplete&&t.onComplete(i)}}};function E(e,t,n){v(e).navigate(t,n)}function _(e,t){return v(e).generateUrl(t)}const R=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,w=Symbol("Navigate"),L=Symbol("GenerateUrl"),N=Symbol("NavContext"),C=Symbol("NavContext");function O(e){!function(e,t,n){if(!e)throw new Error(c(t,n))}("function"==typeof e.prototype.dispatchEvent,u.INVALID_MIXIN_CMP,[e.toString()]);return class extends e{[C](){if(!this[N]&&(this.dispatchEvent(new CustomEvent(R,{bubbles:!0,composed:!0,detail:{callback:e=>{this[N]=e}}})),!this[N]))throw new Error(c(u.MISSING_CONTEXT))}[w](e,t){this[C](),E(this[N],e,t)}async[L](e){return this[C](),_(this[N],e)}}}O.Navigate=w,O.GenerateUrl=L,O.NavContext=N;export{n as ContextInfo,m as CurrentPageReference,p as CurrentRoute,b as CurrentView,f as NavigationContext,O as NavigationMixin,g as generateContextualWireAdapter,_ as generateUrl,v as getNavigationHelm,E as navigate,I 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),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
|
+
import{registerDecorators as e}from"lwc";function t(e=""){return e=e||"",decodeURIComponent(e)}function r(e){"/"!==(e=e||"/").charAt(0)&&(e="/"+e);const t=e.match(/^[^#?]+/);if(null!==t){const e=t[0];return"/"===e?"/":e.replace(/\/$/,"")}return"/"}function n(e){const r=(e=e||"").indexOf("#");r>=0&&(e=e.substring(0,r));const n=e.indexOf("?"),o=n>=0?e.substr(n+1):null,i={};return o&&o.split("&").forEach((e=>{if(e.indexOf("=")>=0){const[r,n=""]=e.split("=");i[t(r)]=t(n)}else i[t(e)]=null})),i}function o(e={}){const t=Object.keys(e);return t.length?`?${t.map((t=>{const r=e[t];return null===r?t:`${t}=${function(e=""){return e=e||"",encodeURIComponent(e)}(r)}`})).join("&")}`:""}function i(e){return!!(e&&e.length>1)&&e.startsWith(":")}function s(e){return!!e&&(!!i(e)&&e.substr(1))}function c(e){return Object.values(e).reduce(((e,{routeParamName:t})=>{const r=s(t);return r&&e.push(r),e}),[])}function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){l(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function f(e,r){const{regex:n,params:o}=r,i=n.exec(e);if(i){const[,...e]=i,r={};return o.forEach(((n,o)=>{const{name:i}=n,s=e[o];r[i]=s?t(s):s})),r}return null}function p(e,r){if(e&&r){const{queryMatcher:n}=r,o=n(e);if(o){const e={};return Object.keys(o).forEach((r=>{const n=o[r],{value:i,routeParamName:s}=n,c=s?s.substr(1):r;e[c]=i?t(i):i})),e}}return null}function d(e,t){if(t){const{original:{page:{type:o="",attributes:s={},state:c={}}={}}={}}=t,u=r(e),l=n(e),d=f(u,t),g=p(l,t);if(d&&g){const e=a(a({},d),g),r={};Object.keys(s).forEach((t=>{const n=s[t];let o;if(n&&i(n)){const t=n.substr(1);o=e[t]}else o=n;r[t]=o}));const n={};Object.keys(c).forEach((t=>{const r=c[t];let o;if(r&&i(r)){const t=r.substr(1);o=e[t]}else o=r;n[t]=o}));const u=function(e,t){const{compiledQuery:r}=t,n=Object.keys(r).filter((e=>{const{literalValue:t}=r[e];return!t})),o={};return Object.keys(e).forEach((t=>{const r=e[t];n.indexOf(t)<0&&(o[t]=r)})),o}(l,t);return{type:o,attributes:a({},r),state:a(a({},u),n)}}}return null}function g(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?g(Object(r),!0).forEach((function(t){b(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function y(e,t){const o=r(e),i=n(e),s=t?t.filter((e=>e.regex.test(o))):[],[c]=s.filter((e=>{const{queryMatcher:t}=e;return t(i)&&function(e,t,r){const{original:{patterns:n=null}={}}=r||{};if(n){const o=f(e,r),i=p(t,r),s=h(h({},o),i);return Object.keys(n).every((e=>{const t=n[e],r=new RegExp(t),o=s[e]||"";return r.test(o)}))}return!0}(o,i,e)}));return c||null}function m(e,t,r=""){r&&0===e.indexOf(r)&&(e=e.replace(r,""));const n=y(e,t);let o;if(!n)return null;{const t=d(e,n);if(t){return o={route:{id:n.original.id,attributes:h({},t.attributes),state:h({},t.state),pageReference:{type:t.type,attributes:h({},t.attributes),state:h({},t.state)}},routeDefinition:n},o}}return null}function O(e,t,r=""){const n=function(e,t){if(!e)return null;const{type:r,attributes:n={},state:o={}}=e;if(r){const[e]=t.filter((e=>{const{original:{page:{type:t=null,attributes:s={},state:c={}}={}}}=e,u=t===r,a=Object.keys(s).every((e=>Object.keys(n).indexOf(e)>=0)),l=Object.keys(s).length===Object.keys(n).length,f=Object.keys(c).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]===n[e])),d=Object.keys(c).filter((e=>{const t=c[e];return null===t||!i(t)})).every((e=>c[e]===o[e]));return u&&a&&l&&p&&f&&d}));return e||null}return null}(e,t);return n?v(e,n,r):null}function E(e,t,r){const{attributeBindings:n,stateBindings:o}=r,{attributes:i,state:c}=t,u={};return e.forEach((e=>{const[t]=Object.keys(n).filter((t=>s(n[t])===e));if(t)u[e]=i[t];else{const[t]=Object.keys(o).filter((t=>s(o[t])===e));t&&(u[e]=c[t])}})),u}function v(e,t,r=""){const{params:n,original:{page:u={}}={},toPath:a,compiledQuery:l}=t,{attributes:f={},state:p={}}=u,d=a(E(n.filter((({name:e})=>"string"==typeof e)).map((({name:e})=>e)),e,{attributeBindings:f,stateBindings:p})),g=function(e,t,r){const{compiledQuery:n,original:{page:{state:o={}}}}=r,{state:c={}}=e||{},u={};Object.keys(c).filter((e=>!i(o[e]))).forEach((e=>u[e]=c[e]));const a={};return Object.keys(t).forEach((e=>{const r=t[e],[o]=Object.keys(n).filter((t=>{const r=n[t],{routeParamName:o}=r;return s(o)===e}));if(o){a[o]=r}})),h(h({},u),a)}(e,E(c(l),e,{attributeBindings:f,stateBindings:p}),t);return`${r}${d}${o(g)}`}function R(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((r=>{if(function(e,t){return t in e}(e,r)){const n=e[r];n&&"object"==typeof n&&R(n,t-1)}}))}catch(e){}return e}const w=1;function I(e,t){return`${e.code}: ${function(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,r)=>t[r])):e}(e.message,t)}`}function j(e,t,r){if(!e)throw new Error(I(t,r))}const P={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:w},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:w},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:w},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:w},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:w},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:w,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:w,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:w},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:w},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:w},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:w},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:w},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:w},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:w},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:w,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:w},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:w,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:w},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:w}};function D(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function x(e){return e&&e.sensitive?"":"i"}function A(e,t={}){const r=function(e){const t=[];let r=0;for(;r<e.length;){const n=e[r];if("*"!==n&&"+"!==n&&"?"!==n)if("\\"!==n)if("{"!==n)if("}"!==n)if(":"!==n)if("("!==n)t.push({type:"CHAR",index:r,value:e[r++]});else{let n=1,o="",i=r+1;if("?"===e[i])throw new TypeError(`Pattern cannot start with "?" at ${i}`);for(;i<e.length;)if("\\"!==e[i]){if(")"===e[i]){if(n--,0===n){i++;break}}else if("("===e[i]&&(n++,"?"!==e[i+1]))throw new TypeError(`Capturing groups are not allowed at ${i}`);o+=e[i++]}else o+=e[i++]+e[i++];if(n)throw new TypeError(`Unbalanced pattern at ${r}`);if(!o)throw new TypeError(`Missing pattern at ${r}`);t.push({type:"PATTERN",index:r,value:o}),r=i}else{let n="",o=r+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;n+=e[o++]}if(!n)throw new TypeError(`Missing parameter name at ${r}`);t.push({type:"NAME",index:r,value:n}),r=o}else t.push({type:"CLOSE",index:r,value:e[r++]});else t.push({type:"OPEN",index:r,value:e[r++]});else t.push({type:"ESCAPED_CHAR",index:r++,value:e[r++]});else t.push({type:"MODIFIER",index:r,value:e[r++]})}return t.push({type:"END",index:r,value:""}),t}(e),{prefixes:n="./"}=t,o=`[^${D(t.delimiter||"/#?")}]+?`,i=[];let s=0,c=0,u="";const a=e=>{if(c<r.length&&r[c].type===e)return r[c++].value},l=e=>{const t=a(e);if(void 0!==t)return t;const{type:n,index:o}=r[c];throw new TypeError(`Unexpected ${n} at ${o}, expected ${e}`)},f=()=>{let e,t="";for(;e=a("CHAR")||a("ESCAPED_CHAR");)t+=e;return t};for(;c<r.length;){const e=a("CHAR"),t=a("NAME"),r=a("PATTERN");if(t||r){let c=e||"";-1===n.indexOf(c)&&(u+=c,c=""),u&&(i.push(u),u=""),i.push({name:t||s++,prefix:c,suffix:"",pattern:r||o,modifier:a("MODIFIER")||""});continue}const c=e||a("ESCAPED_CHAR");if(c){u+=c;continue}u&&(i.push(u),u="");if(a("OPEN")){const e=f(),t=a("NAME")||"",r=a("PATTERN")||"",n=f();l("CLOSE"),i.push({name:t||(r?s++:""),pattern:t&&!r?o:r,prefix:e,suffix:n,modifier:a("MODIFIER")||""})}else l("END")}return i}function _(e,t){return function(e,t={}){const r=x(t),{encode:n=(e=>e),validate:o=!0}=t,i=e.map((e=>{if("object"==typeof e)return new RegExp(`^(?:${e.pattern})$`,r)}));return t=>{let r="";for(let s=0;s<e.length;s++){const c=e[s];if("string"==typeof c){r+=c;continue}const u=t?t[c.name]:void 0,a="?"===c.modifier||"*"===c.modifier,l="*"===c.modifier||"+"===c.modifier;if(Array.isArray(u)){if(!l)throw new TypeError(`Expected "${c.name}" to not repeat, but got an array`);if(0===u.length){if(a)continue;throw new TypeError(`Expected "${c.name}" to not be empty`)}for(let e=0;e<u.length;e++){const t=n(u[e],c);if(o&&!i[s].test(t))throw new TypeError(`Expected all "${c.name}" to match "${c.pattern}", but got "${t}"`);r+=c.prefix+t+c.suffix}continue}if("string"==typeof u||"number"==typeof u){const e=n(String(u),c);if(o&&!i[s].test(e))throw new TypeError(`Expected "${c.name}" to match "${c.pattern}", but got "${e}"`);r+=c.prefix+e+c.suffix;continue}if(a)continue;const f=l?"an array":"a string";throw new TypeError(`Expected "${c.name}" to be ${f}`)}return r}}(A(e,t),t)}function N(e,t,r){return function(e,t,r={}){const{strict:n=!1,start:o=!0,end:i=!0,encode:s=(e=>e)}=r,c=`[${D(r.endsWith||"")}]|$`,u=`[${D(r.delimiter||"/#?")}]`;let a=o?"^":"";for(const r of e)if("string"==typeof r)a+=D(s(r));else{const e=D(s(r.prefix)),n=D(s(r.suffix));if(r.pattern)if(t&&t.push(r),e||n)if("+"===r.modifier||"*"===r.modifier){const t="*"===r.modifier?"?":"";a+=`(?:${e}((?:${r.pattern})(?:${n}${e}(?:${r.pattern}))*)${n})${t}`}else a+=`(?:${e}(${r.pattern})${n})${r.modifier}`;else a+=`(${r.pattern})${r.modifier}`;else a+=`(?:${e}${n})${r.modifier}`}if(i)n||(a+=`${u}?`),a+=r.endsWith?`(?=${c})`:"$";else{const t=e[e.length-1],r="string"==typeof t?u.indexOf(t[t.length-1])>-1:void 0===t;n||(a+=`(?:${u}(?=${c}))?`),r||(a+=`(?=${u}|${c})`)}return new RegExp(a,x(r))}(A(e,r),t,r)}function T(e,t,r){return e instanceof RegExp?function(e,t){if(!t)return e;const r=e.source.match(/\((?!\?)/g);if(r)for(let e=0;e<r.length;e++)t.push({name:e,prefix:"",suffix:"",modifier:"",pattern:""});return e}(e,t):Array.isArray(e)?function(e,t,r){const n=e.map((e=>T(e,t,r).source));return new RegExp(`(?:${n.join("|")})`,x(r))}(e,t,r):N(e,t,r)}function $(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function L(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?$(Object(r),!0).forEach((function(t){S(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):$(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function S(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const{INVALID_ROUTE_QUERY:U,MISSING_ROUTE_TEMPLATE:C,MISSING_PAGE_BINDING:M,INVALID_PAGE_BINDING:k,INVALID_URI_SYNTAX:W}=P;function V(e){const{routes:t,caseSensitive:o}=e;return t.map((e=>function(e,t=!1){const o=[],{uri:u,page:a}=e;j(!!u,C),j(function(e=""){return!["*","+","(",")",";"].some((t=>e.indexOf(t)>=0))}(u),W),j(!!a,M);const l=r(u),f=n(u),p=T(l,o,{sensitive:t,end:!1!==e.exact}),d=_(l,{encode:encodeURIComponent}),g=function(e){const t={};return Object.keys(e).forEach((r=>{const n=e[r];j(!i(r)||null===n,U),i(r)?t[r.substr(1)]={routeParamName:r}:n&&i(n)?t[r]={routeParamName:n}:t[r]={literalValue:null===n?null:n}})),t}(f),h=function(e,t=!1){return r=>{const n=Object.keys(r),o=Object.keys(e);return o.every((e=>n.indexOf(e)>=0))?o.reduce(((n,o)=>{if(null===n)return null;const{literalValue:i,routeParamName:s}=e[o],c=r[o];let u=!0;return"string"==typeof i?u=t?i===c:i.toUpperCase()===(null==c?c:c.toUpperCase()):null===i&&(u=c===i),n=u?L(L({},n),{},{[o]:{value:c,routeParamName:s}}):null}),{}):null}}(g,t),b={original:e,regex:p,params:o,toPath:d,compiledQuery:g,queryMatcher:h};return j(function(e){const{original:{page:t}={},params:r,compiledQuery:n}=e,o=t?t.type:t,u=(t?t.attributes:t)||{},a=(t?t.state:t)||{};if("string"!=typeof o||"object"!=typeof u||"object"!=typeof a)return!1;const l=Object.values(r).map((({name:e})=>e)),f=c(n),p=[...l,...f],d=Object.values(u).filter(i).map(s),g=Object.values(a).filter(i).map(s),h=p.every((e=>"string"==typeof e&&(d.indexOf(e)>=0||g.indexOf(e)>=0))),b=p.length===d.length+g.length;return!!(t&&o&&u&&a&&h&&b)}(b),k),b}(e,o)))}function H(){let e,t,r=[];const n=n=>{r.filter((e=>null!==e)).forEach((e=>e.error&&e.error(n))),e=void 0,t=n};return{next:n=>{r.filter((e=>null!==e)).forEach((e=>e.next&&e.next(n))),e=n,t=void 0},error:n,complete:()=>{r.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),r=[],e=void 0,t=void 0},subscribe:(o,i=!0)=>{(e=>{r.push(e)})(o),e&&i&&o.next(e),t&&n(t);const s=r.length-1;return{unsubscribe:()=>(e=>{r=[...r.slice(0,e),...r.slice(e+1)]})(s)}}}}function G(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function F(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?G(Object(r),!0).forEach((function(t){B(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):G(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function B(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class Q{constructor(e){this.deprecatedConfig={},this.routeHandlerId=0,this.compiledRoutes=[],this.routeObservable=H(),this.config={basePath:e.basePath||"",caseSensitive:Boolean(e.caseSensitive),routes:e.routes||[],generateUrl:e=>O(e,this.compiledRoutes,this.config.basePath),parseUrl:e=>function(e,t,r=""){const n=m(e,t,r);return n&&n.route&&n.route.pageReference?n.route.pageReference:null}(e,this.compiledRoutes,this.config.basePath)};const{DEPRECATED_getRouteFromUrl:t,DEPRECATED_getUrlFromRoute:r}=e;t&&(this.deprecatedConfig.DEPRECATED_getRouteFromUrl=t),r&&(this.deprecatedConfig.DEPRECATED_getUrlFromRoute=r),this.compiledRoutes=V(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 r=m(t,this.compiledRoutes,this.config.basePath),n=r&&v(r.route.pageReference,r.routeDefinition,this.config.basePath);return r&&n?{pathMatch:n,route:r.route,routeDefinition:r.routeDefinition.original}:null}async resolveView(e){return new Promise(((t,r)=>{const n=this.matchRoute(e);return n?n.routeDefinition.handler().then((e=>{const o=e.default;if(!o)return r(I(P.INVALID_ROUTE_HANDLER,[n.routeDefinition.id]));const i=new o(t);i&&i.update(n.route)})):r(I(P.NO_ROUTE_MATCH,[JSON.stringify(e)]))}))}navigate(e){const t=this.matchRoute(e);if(!t)throw new Error(I(P.MISSING_ROUTE,[JSON.stringify(e)]));this.pendingRoute=F({},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 r=(await e.routeDefinition.handler()).default;if(!r)throw new Error(I(P.INVALID_ROUTE_HANDLER,[e.routeDefinition.id]));return this.routeHandler=new r((e=>{this._updateView(t,e)})),this.routeHandler&&this.routeHandler.update(e.route),!0}_updateView(e,t){if(!t||!t.viewset||e!==this.routeHandlerId)return;if(!this.pendingRoute)throw new Error("Trying to commit route state without a route");const r=R(t.viewset);this.routeObservable.next(F(F({},this.pendingRoute),{},{viewset:r}))}}function X(e={}){return new Q(e)}e(Q,{fields:["deprecatedConfig","routeHandlerId"]});export{X as createRouter};
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
import{registerTemplate as e,registerDecorators as t,createContextProvider as r,registerComponent as i,LightningElement as n}from"lwc";import{ROUTER_VIEW as o,ROUTER_NAV as s,ROUTER_ERROR as a}from"lwr/metrics";import{logOperationEnd as c,logOperationStart as d}from"lwr/profiler";var l=[function(e,t,r){return"span"+(e?"["+e+"]":"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}];const h={key:0},u=[],p={attrs:{"aria-live":"polite","aria-atomic":"true"},context:{lwc:{dom:"manual"}},key:1};function v(e,t,r,i){const{s:n,h:o}=e;return[n("",h,u,r),o("span",p)]}var g=e(v);function m(e){if(null==e)throw new TypeError("Provider must be defined.")}v.slots=[""],v.stylesheets=[],l&&v.stylesheets.push.apply(v.stylesheets,l),l&&(v.stylesheetToken="lwr-routerContainer_routerContainer");class f{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){m(e);const r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(t)))}getContext(e){m(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){m(e),this.infoMap.delete(e)}subscribeContext(e,t){m(e);const{consumers:r,contextValue:i}=this.getInfo(e);r.has(t)||(r.add(t),t.provide(i))}unsubscribeContext(e,t){m(e),this.getInfo(e).consumers.delete(t)}}function b(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?b(Object(r),!0).forEach((function(t){w(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):b(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function w(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}t(f,{fields:["infoMap"]});const I=1;function R(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,r)=>t[r])):e}function N(e,t){const r=E(E({},e),{},{message:R(e.message,t)});return e.address&&(r.address=R(e.address,t)),e.stack&&(r.stack=R(e.stack,t)),r}function _(e,t,r){if(!e)throw new Error(function(e,t){return`${e.code}: ${R(e.message,t)}`}(t,r))}const y={INVALID_MIXIN_CMP:{code:"LWR4001",message:"{0} must be an Element type",level:I},MISSING_CONTEXT:{code:"LWR4002",message:"Could not find context to perform navigation action.",level:I},INVALID_CONTEXT:{code:"LWR4003",message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:I},MULTIPLE_ROOTS:{code:"LWR4004",message:"Router connection failed. There can only be one root router.",level:I},MULTIPLE_CHILDREN:{code:"LWR4005",message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:I},MISSING_ROUTE:{code:"LWR4006",message:'A route cannot be created to navigate to URL "{0}"',level:I,address:"{0}"},MISSING_URL:{code:"LWR4007",message:'A URL cannot be created to navigate to route "{0}"',level:I,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:I},MISSING_ROUTE_CMP:{code:"LWR4016",message:"Expected a route view component with a default export.",level:I},MISSING_DATA_CONTEXT:{code:"LWR4018",message:"Could not find context to retrieve navigation data.",level:I},INVALID_ROUTE_QUERY:{code:"LWR4019",message:"Invalid query param in route definition.",level:I},MISSING_PAGE_BINDING:{code:"LWR4020",message:"Route definition must provide page binding",level:I},INVALID_PAGE_BINDING:{code:"LWR4021",message:"Invalid page binding in route definition",level:I},INVALID_URI_SYNTAX:{code:"LWR4022",message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:I},VIEW_IMPORT_FAILED:{code:"LWR4023",message:'Error importing view with name "{0}", failure was: {1}',level:I,stack:"{2}"},VIEW_MISSING:{code:"LWR4024",message:'Expected a view with name "{0}" in the viewset',level:I},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:"LWR4025",message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:I,stack:"{3}"},NO_ROUTE_MATCH:{code:"LWR4026",message:"A routing match cannot be found for: {0}",level:I},INVALID_ROUTE_HANDLER:{code:"LWR4027",message:'Route definition "{0}" does not have a valid route handler module',level:I}},P=new WeakMap;function O(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,r){e.setContext(t,r)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,r){e.subscribeContext(t,r)}static unsubscribeContext(t,r){e.unsubscribeContext(t,r)}}).contextSchema={value:"required"},t}const x=O(new f(void 0)),L=O(new f(void 0)),C=O(new f(void 0)),T=new f(void 0),D=class extends(O(T)){async update(e,t){if(t){const r=e&&e.viewName?e.viewName:"default",i=t.viewset[r],n=i,o=n&&n.module||i;let s;if(o)try{const e=await o(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;s=n.specifier?N(y.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[n.specifier,r,t.message,t.stack||""]):N(y.VIEW_IMPORT_FAILED,[r,t.message,t.stack||""])}else s=N(y.VIEW_MISSING,[r]);t.onComplete&&t.onComplete(s)}}};function S(){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,r)=>e.then((e=>!1===e?Promise.reject():Promise.resolve(r(t))))),Promise.resolve(!0)).then((e=>!1!==e)).catch((e=>{if(e instanceof Error)throw e;return!1})),empty:()=>0===e.length}}function M(e=""){return e=e||"",decodeURIComponent(e)}function A(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const U=`universalcontainergetnavigationcontext${A()}`,W=r(C),j=r(L),k=r(D),F=r(x);function V(e,t,r,i){i.setContext(t,e),r(t,{consumerConnectedCallback:i.subscribeContext.bind(i,t),consumerDisconnectedCallback:i.unsubscribeContext.bind(i,t)})}function G(){let e,t,r=[];const i=i=>{r.filter((e=>null!==e)).forEach((e=>e.error&&e.error(i))),e=void 0,t=i};return{next:i=>{r.filter((e=>null!==e)).forEach((e=>e.next&&e.next(i))),e=i,t=void 0},error:i,complete:()=>{r.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),r=[],e=void 0,t=void 0},subscribe:(n,o=!0)=>{(e=>{r.push(e)})(n),e&&o&&n.next(e),t&&i(t);const s=r.length-1;return{unsubscribe:()=>(e=>{r=[...r.slice(0,e),...r.slice(e+1)]})(s)}}}}function $(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function H(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?$(Object(r),!0).forEach((function(t){B(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):$(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function B(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const X=`universalcontainernavigationevent${A()}`,q=`universalcontainerparentevent${A()}`;class Y{constructor(e,t,r){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=S(),this.errorNavFilters=S(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:r,address:i}=t.detail;this.config.handleNavigation(i,r)?this.root&&!e?this.root.processError(N(y.MISSING_URL,[JSON.stringify(i)])):this.parent||this.process(e,r):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=r||window,this.router=t,this.routeObservable=G()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,r){if(r)this.processError(r);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;c({id:o,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||H(H({},e),{},{url:t}),this.committedRoute=H(H({},this.pendingRoute),e),L.setContext(this.target,e.route.pageReference),C.setContext(this.target,this.committedRoute.route),this.routeObservable.next(H(H({},this.committedRoute),{},{viewset:e.viewset})),c({id:s,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(q,(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 r={id:e,value:t,update:e=>{r.value=e}};P.set(r.id,r)}(this.contextId,e),V(this.contextId,this.target,F,x),V(void 0,this.target,j,L),V(void 0,this.target,W,C),V(void 0,this.target,k,D),this.router.subscribe((e=>{const t=e.route.pageReference||{},r=this.router.generateUrl(t)||"";if(d({id:o,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,r)};D.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,r)}),!0),this.target.addEventListener(X,this._handleNavigationEvent),this.target.addEventListener(q,this._handleParentEvent),this.target.addEventListener(U,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)})),this.connected=!0}disconnect(){this.target.removeEventListener(X,this._handleNavigationEvent),this.target.removeEventListener(q,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((()=>{_(!this.child,y.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t){this.eventId=(new Date).getTime().toString(),d({id:s,specifier:this.eventId});try{this.parent||await this.preProcess(e)}catch(e){if(e.code)return this.processError(e),!1;throw e}const r=this.router.parseUrl(e);return r&&this.router.navigate(r),!0}preProcess(e){const t=this.router.parseUrl(e),r=t&&this.router.matchRoute(t);if(!r)return Promise.reject(N(y.MISSING_ROUTE,[e]));this.pendingRoute=H({url:e},r);return(this.preNavFilters.empty()?Promise.resolve(!0):this.preNavFilters.compile({current:this.committedRoute||void 0,next:this.pendingRoute})).then((t=>t&&this.child?this.child.preProcess(this._stripUrlForChild(e)):t)).then((t=>t||Promise.reject(N(y.PRENAV_FAILED,[e]))))}processError(e){d({id:a}),this.errorNavFilters.compile(e),this.child&&this.child.processError(e)}navigate(e,t){let r=this.router.generateUrl(e);if(r){r=(this.parent&&this.parent.committedRoute&&this.parent.committedRoute.pathMatch||"").concat(r)}this._sendEvent(X,{url:r,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 z(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",r=`${window.location.protocol}//${window.location.hostname}${t}`,i="/"===e.charAt(0)?"":"/";e=r+i+e}const t={},r=document.createElement("a");r.href=e;const i=r.search.substring(1);return i&&i.split("&").forEach((e=>{const[r,i=""]=e.split("=");t[M(r)]=M(i)})),{href:r.href,origin:`${r.protocol}//${r.hostname}${r.port?`:${r.port}`:""}`,pathname:r.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),r=t.href.replace(/:\d+/,""),i=t.origin.replace(/:\d+/,"");return r.replace(i,"")}t(Y,{fields:["pendingRoute","committedRoute","contextId","connected","preNavFilters","errorNavFilters","_handleNavigationEvent","_handleParentEvent"]});class J extends Y{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(z(document.location.href))}disconnect(){super.disconnect(),window.removeEventListener("popstate",this.onpopstate)}async process(e,t,r=!0){const i=await super.process(e);return i&&!this.historyDisabled&&r&&this.connected&&!this.parent&&(t?function(e,t){const r=t||{};window.history.replaceState(r,"",e)}(e):function(e,t){const r=t||{};window.history.pushState(r,"",e)}(e)),i}catchBrowserUpdate(e){this.process(e,!1,!1)}}t(J,{fields:["historyDisabled"]});let Q=!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={},r){const i=t.historyDisabled?new Y(t,r,e):new J(t,r,e),n={addPreNavigate:e=>(i.addPreNavigate(e),n),addPostNavigate:e=>(i.subscribe(e),n),addErrorNavigate:e=>(i.addErrorNavigate(e),n),connect:()=>{i.connect(),_(!Q||!!i.parent,y.MULTIPLE_ROOTS),Q=Q||!i.parent,n.id=i.contextId},disconnect:()=>{Q=Q&&!!i.parent,i.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 r=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(r),!r.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,r){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:r})}}t(K,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var Z=i(K,{tmpl:g});export default Z;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/router/src/modules/lwr/contextProvider/contextProvider.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
currentPageReferenceContextualizer: () => currentPageReferenceContextualizer,
|
|
28
|
+
currentRouteContextualizer: () => currentRouteContextualizer,
|
|
29
|
+
currentViewContextualizer: () => currentViewContextualizer,
|
|
30
|
+
navigationContextContextualizer: () => navigationContextContextualizer,
|
|
31
|
+
provideContext: () => provideContext
|
|
32
|
+
});
|
|
33
|
+
var import_lwc = __toModule(require("lwc"));
|
|
34
|
+
var import_navigation = __toModule(require("lwr/navigation"));
|
|
35
|
+
var currentRouteContextualizer = (0, import_lwc.createContextProvider)(import_navigation.CurrentRoute);
|
|
36
|
+
var currentPageReferenceContextualizer = (0, import_lwc.createContextProvider)(import_navigation.CurrentPageReference);
|
|
37
|
+
var currentViewContextualizer = (0, import_lwc.createContextProvider)(import_navigation.CurrentView);
|
|
38
|
+
var navigationContextContextualizer = (0, import_lwc.createContextProvider)(import_navigation.NavigationContext);
|
|
39
|
+
function provideContext(contextValue, providerNode, contextualizer, contextualAdapter) {
|
|
40
|
+
contextualAdapter.setContext(providerNode, contextValue);
|
|
41
|
+
contextualizer(providerNode, {
|
|
42
|
+
consumerConnectedCallback: contextualAdapter.subscribeContext.bind(contextualAdapter, providerNode),
|
|
43
|
+
consumerDisconnectedCallback: contextualAdapter.unsubscribeContext.bind(contextualAdapter, providerNode)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/@lwrjs/router/src/modules/lwr/contextUtils/contextInfo.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
ContextInfo: () => ContextInfo
|
|
12
|
+
});
|
|
13
|
+
function validateProvider(obj) {
|
|
14
|
+
if (obj === void 0 || obj === null) {
|
|
15
|
+
throw new TypeError("Provider must be defined.");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var ContextInfo = class {
|
|
19
|
+
constructor(defaultValue) {
|
|
20
|
+
this.infoMap = new WeakMap();
|
|
21
|
+
this.defaultValue = defaultValue;
|
|
22
|
+
}
|
|
23
|
+
getInfo(targetProvider) {
|
|
24
|
+
let info = this.infoMap.get(targetProvider);
|
|
25
|
+
if (info === void 0) {
|
|
26
|
+
info = {consumers: new Set()};
|
|
27
|
+
this.infoMap.set(targetProvider, info);
|
|
28
|
+
}
|
|
29
|
+
return info;
|
|
30
|
+
}
|
|
31
|
+
setContext(targetProvider, contextValue) {
|
|
32
|
+
validateProvider(targetProvider);
|
|
33
|
+
const info = this.getInfo(targetProvider);
|
|
34
|
+
info.contextValue = contextValue;
|
|
35
|
+
info.consumers.forEach((consumer) => consumer.provide(contextValue));
|
|
36
|
+
}
|
|
37
|
+
getContext(targetProvider) {
|
|
38
|
+
validateProvider(targetProvider);
|
|
39
|
+
const {contextValue} = this.getInfo(targetProvider);
|
|
40
|
+
return contextValue !== void 0 ? contextValue : this.defaultValue;
|
|
41
|
+
}
|
|
42
|
+
clearContext(targetProvider) {
|
|
43
|
+
validateProvider(targetProvider);
|
|
44
|
+
this.infoMap.delete(targetProvider);
|
|
45
|
+
}
|
|
46
|
+
subscribeContext(targetProvider, consumer) {
|
|
47
|
+
validateProvider(targetProvider);
|
|
48
|
+
const {consumers, contextValue} = this.getInfo(targetProvider);
|
|
49
|
+
if (!consumers.has(consumer)) {
|
|
50
|
+
consumers.add(consumer);
|
|
51
|
+
consumer.provide(contextValue);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
unsubscribeContext(targetProvider, consumer) {
|
|
55
|
+
validateProvider(targetProvider);
|
|
56
|
+
this.getInfo(targetProvider).consumers.delete(consumer);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/router/src/modules/lwr/contextUtils/contextUtils.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
ContextInfo: () => import_contextInfo.ContextInfo,
|
|
28
|
+
generateContextualWireAdapter: () => generateContextualWireAdapter,
|
|
29
|
+
getNavigationHelm: () => import_navigationApiStore.getNavigationHelm,
|
|
30
|
+
registerNavigationHelm: () => import_navigationApiStore.registerNavigationHelm
|
|
31
|
+
});
|
|
32
|
+
var import_contextInfo = __toModule(require("./contextInfo"));
|
|
33
|
+
var import_navigationApiStore = __toModule(require("./navigationApiStore"));
|
|
34
|
+
function generateContextualWireAdapter(contextInstance) {
|
|
35
|
+
var _a;
|
|
36
|
+
const Adapter = (_a = class {
|
|
37
|
+
constructor(callback) {
|
|
38
|
+
this._callback = callback;
|
|
39
|
+
}
|
|
40
|
+
connect() {
|
|
41
|
+
}
|
|
42
|
+
disconnect() {
|
|
43
|
+
}
|
|
44
|
+
update(config, context) {
|
|
45
|
+
if (context) {
|
|
46
|
+
this._callback(context);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
static setContext(targetProvider, contextValue) {
|
|
50
|
+
contextInstance.setContext(targetProvider, contextValue);
|
|
51
|
+
}
|
|
52
|
+
static getContext(targetProvider) {
|
|
53
|
+
return contextInstance.getContext(targetProvider);
|
|
54
|
+
}
|
|
55
|
+
static clearContext(targetProvider) {
|
|
56
|
+
contextInstance.clearContext(targetProvider);
|
|
57
|
+
}
|
|
58
|
+
static subscribeContext(targetProvider, consumer) {
|
|
59
|
+
contextInstance.subscribeContext(targetProvider, consumer);
|
|
60
|
+
}
|
|
61
|
+
static unsubscribeContext(targetProvider, consumer) {
|
|
62
|
+
contextInstance.unsubscribeContext(targetProvider, consumer);
|
|
63
|
+
}
|
|
64
|
+
}, _a.contextSchema = {value: "required"}, _a);
|
|
65
|
+
return Adapter;
|
|
66
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/router/src/modules/lwr/contextUtils/navigationApiStore.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
getNavigationHelm: () => getNavigationHelm,
|
|
28
|
+
registerNavigationHelm: () => registerNavigationHelm
|
|
29
|
+
});
|
|
30
|
+
var import_routerErrors = __toModule(require("lwr/routerErrors"));
|
|
31
|
+
var CACHE = new WeakMap();
|
|
32
|
+
function getNavigationHelm(id) {
|
|
33
|
+
const metadata = CACHE.get(id);
|
|
34
|
+
if (!metadata || !metadata.value) {
|
|
35
|
+
throw new Error((0, import_routerErrors.generateMessage)(import_routerErrors.messages.MISSING_CONTEXT));
|
|
36
|
+
}
|
|
37
|
+
return metadata.value;
|
|
38
|
+
}
|
|
39
|
+
function registerNavigationHelm(contextId, contextValue) {
|
|
40
|
+
const metadata = {
|
|
41
|
+
id: contextId,
|
|
42
|
+
value: contextValue,
|
|
43
|
+
update: (newValue) => {
|
|
44
|
+
metadata.value = newValue;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
CACHE.set(metadata.id, metadata);
|
|
48
|
+
return metadata;
|
|
49
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/router/src/modules/lwr/currentPageReference/currentPageReference.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
CurrentPageReference: () => CurrentPageReference
|
|
28
|
+
});
|
|
29
|
+
var import_contextUtils = __toModule(require("lwr/contextUtils"));
|
|
30
|
+
var CURRENT_PAGE_REFERENCE_CONTEXT = new import_contextUtils.ContextInfo(void 0);
|
|
31
|
+
var CurrentPageReference = (0, import_contextUtils.generateContextualWireAdapter)(CURRENT_PAGE_REFERENCE_CONTEXT);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/router/src/modules/lwr/currentRoute/currentRoute.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
CurrentRoute: () => CurrentRoute
|
|
28
|
+
});
|
|
29
|
+
var import_contextUtils = __toModule(require("lwr/contextUtils"));
|
|
30
|
+
var CURRENT_ROUTE_CONTEXT = new import_contextUtils.ContextInfo(void 0);
|
|
31
|
+
var CurrentRoute = (0, import_contextUtils.generateContextualWireAdapter)(CURRENT_ROUTE_CONTEXT);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/router/src/modules/lwr/currentView/currentView.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
CurrentView: () => CurrentView
|
|
28
|
+
});
|
|
29
|
+
var import_contextUtils = __toModule(require("lwr/contextUtils"));
|
|
30
|
+
var import_routerErrors = __toModule(require("lwr/routerErrors"));
|
|
31
|
+
var CURRENT_VIEW_CONTEXT = new import_contextUtils.ContextInfo(void 0);
|
|
32
|
+
var CurrentView = class CurrentView2 extends (0, import_contextUtils.generateContextualWireAdapter)(CURRENT_VIEW_CONTEXT) {
|
|
33
|
+
async update(config, context) {
|
|
34
|
+
if (context) {
|
|
35
|
+
const viewName = config && config.viewName ? config.viewName : "default";
|
|
36
|
+
const viewEntry = context.viewset[viewName];
|
|
37
|
+
const viewInfo = viewEntry;
|
|
38
|
+
const viewImporter = viewInfo && viewInfo.module || viewEntry;
|
|
39
|
+
let importError;
|
|
40
|
+
if (viewImporter) {
|
|
41
|
+
try {
|
|
42
|
+
const viewModule = await viewImporter();
|
|
43
|
+
const newViewCtor = viewModule && viewModule.default;
|
|
44
|
+
if (newViewCtor && newViewCtor.constructor !== void 0) {
|
|
45
|
+
this._callback(newViewCtor);
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error("error occurred with view import");
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
const error = e;
|
|
51
|
+
if (viewInfo.specifier) {
|
|
52
|
+
importError = (0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.VIEW_IMPORT_FAILED_WITH_SPECIFIER, [
|
|
53
|
+
viewInfo.specifier,
|
|
54
|
+
viewName,
|
|
55
|
+
error.message,
|
|
56
|
+
error.stack || ""
|
|
57
|
+
]);
|
|
58
|
+
} else {
|
|
59
|
+
importError = (0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.VIEW_IMPORT_FAILED, [
|
|
60
|
+
viewName,
|
|
61
|
+
error.message,
|
|
62
|
+
error.stack || ""
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
importError = (0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.VIEW_MISSING, [viewName]);
|
|
68
|
+
}
|
|
69
|
+
if (context.onComplete) {
|
|
70
|
+
context.onComplete(importError);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|