@lwrjs/router 0.11.0-alpha.8 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bundle/prod/lwr/navigation/navigation.js +1 -1
- package/build/bundle/prod/lwr/router/router.js +1 -1
- package/build/bundle/prod/lwr/routerContainer/routerContainer.js +1 -1
- package/build/cjs/modules/lwr/contextProvider/contextProvider.cjs +2 -2
- package/build/cjs/modules/lwr/historyRouter/historyRouter.cjs +1 -1
- package/build/cjs/modules/lwr/router/router.cjs +3 -3
- package/build/cjs/modules/lwr/routerContainer/routerContainer.cjs +1 -1
- package/build/cjs/modules/lwr/routerErrors/routerErrors.cjs +5 -0
- package/build/cjs/modules/lwr/serverRouter/serverRouter.cjs +121 -0
- package/build/cjs/services/module-provider/utils.cjs +2 -1
- package/build/es/modules/lwr/contextProvider/contextProvider.d.ts +9 -6
- package/build/es/modules/lwr/contextProvider/contextProvider.js +3 -7
- package/build/es/modules/lwr/contextUtils/contextInfo.d.ts +4 -4
- package/build/es/modules/lwr/contextUtils/contextUtils.d.ts +5 -3
- package/build/es/modules/lwr/currentView/currentView.d.ts +2 -3
- package/build/es/modules/lwr/historyRouter/historyRouter.js +1 -1
- package/build/es/modules/lwr/router/router.js +3 -3
- package/build/es/modules/lwr/routerContainer/routerContainer.js +1 -1
- package/build/es/modules/lwr/routerErrors/routerErrors.js +5 -0
- package/build/es/modules/lwr/routerUtils/types.d.ts +1 -1
- package/build/es/modules/lwr/serverRouter/serverRouter.d.ts +59 -0
- package/build/es/modules/lwr/serverRouter/serverRouter.js +135 -0
- package/build/es/services/module-provider/utils.js +2 -1
- package/build/modules/lwr/contextProvider/contextProvider.js +3 -3
- package/build/modules/lwr/contextUtils/contextUtils.js +8 -1
- package/build/modules/lwr/historyRouter/historyRouter.js +1 -1
- package/build/modules/lwr/router/router.js +3 -3
- package/build/modules/lwr/routerContainer/routerContainer.js +1 -1
- package/build/modules/lwr/routerErrors/routerErrors.js +5 -0
- package/build/modules/lwr/serverRouter/serverRouter.js +149 -0
- package/package.json +11 -8
- package/build/bundle/prod/lwr/navigation/es/modules/lwr/currentView/currentView.d.ts +0 -28
- package/build/bundle/prod/lwr/router/es/modules/lwr/currentView/currentView.d.ts +0 -28
- package/build/bundle/prod/lwr/routerContainer/es/modules/lwr/currentView/currentView.d.ts +0 -28
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e){if(null==e)throw new TypeError("Provider must be defined.")}class t{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(t,
|
|
1
|
+
function e(e){if(null==e)throw new TypeError("Provider must be defined.")}class t{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(t,o){e(t);const n=o,a=this.getInfo(t);a.contextValue=o,a.consumers.forEach((e=>e.provide(n))),0===a.consumers.size&&n?.onComplete&&n.onComplete()}getContext(t){e(t);const{contextValue:o}=this.getInfo(t);return void 0!==o?o:this.defaultValue}clearContext(t){e(t),this.infoMap.delete(t)}subscribeContext(t,o){e(t);const{consumers:n,contextValue:a}=this.getInfo(t);n.has(o)||(n.add(o),o.provide(a))}unsubscribeContext(t,o){e(t),this.getInfo(t).consumers.delete(o)}}const o="LWR",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:`${o}4001`,message:"{0} must be an Element type",level:n},MISSING_CONTEXT:{code:`${o}4002`,message:"Could not find context to perform navigation action.",level:n},INVALID_CONTEXT:{code:`${o}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:n},MULTIPLE_ROOTS:{code:`${o}4004`,message:"Router connection failed. There can only be one root router.",level:n},MULTIPLE_CHILDREN:{code:`${o}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:n},MISSING_ROUTE:{code:`${o}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:n,address:"{0}"},MISSING_URL:{code:`${o}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:n,address:"{0}"},PRENAV_FAILED:{code:`${o}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${o}4009`,message:'A route definition must contain a "uri" property.',level:n},MISSING_ROUTE_CMP:{code:`${o}4016`,message:"Expected a route view component with a default export.",level:n},MISSING_DATA_CONTEXT:{code:`${o}4018`,message:"Could not find context to retrieve navigation data.",level:n},INVALID_ROUTE_QUERY:{code:`${o}4019`,message:"Invalid query param in route definition.",level:n},MISSING_PAGE_BINDING:{code:`${o}4020`,message:"Route definition must provide page binding",level:n},INVALID_PAGE_BINDING:{code:`${o}4021`,message:"Invalid page binding in route definition",level:n},INVALID_URI_SYNTAX:{code:`${o}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:n},VIEW_IMPORT_FAILED:{code:`${o}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:n,stack:"{2}"},VIEW_MISSING:{code:`${o}4024`,message:'Expected a view with name "{0}" in the viewset',level:n},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${o}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:n,stack:"{3}"},NO_ROUTE_MATCH:{code:`${o}4026`,message:"A routing match cannot be found for: {0}",level:n},INVALID_ROUTE_HANDLER:{code:`${o}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:n},DESTINATION_NOT_FOUND:{code:`${o}4028`,message:"Route handler returned 404: Not Found",level:n},DESTINATION_ERROR:{code:`${o}4029`,message:"Route handler returned error status {0}: {1}",level:n,stack:"{2}"},NO_INIT_URL:{code:`${o}4030`,message:'Cannot initialize a server router without a "url"',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;return(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)}}).contextSchema={value:"required"},t}const I=u(new t(void 0)),v=u(new t(void 0)),g=new t(void 0),m=class extends(u(g)){async update(e,t){if(t){const 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 f(e,t){return l(e).generateUrl(t)}const E=`universalcontainergetnavigationcontext${Math.floor(65536*(1+Math.random())).toString(16).substring(1)}`,_="undefined"==typeof window,N=Symbol("Navigate"),p=Symbol("GenerateUrl"),C=Symbol("NavContext"),T=Symbol("NavContext");function w(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{[T](){if(!this[C]&&(this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{callback:e=>{this[C]=e}}})),!this[C]))throw new Error(s(r.MISSING_CONTEXT))}[N](e,t){_||(this[T](),h(this[C],e,t))}async[p](e){return _?null:(this[T](),f(this[C],e))}}}w.Navigate=N,w.GenerateUrl=p,w.NavContext=C;export{t as ContextInfo,v as CurrentPageReference,m as CurrentView,I as NavigationContext,w as NavigationMixin,u as generateContextualWireAdapter,f as generateUrl,l as getNavigationHelm,h as navigate,d as registerNavigationHelm};
|
|
2
2
|
//# sourceMappingURL=navigation.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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 u(e){return Object.values(e).reduce(((e,{routeParamName:t})=>{const r=s(t);return r&&e.push(r),e}),[])}function c(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?c(Object(r),!0).forEach((function(t){l(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(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,u=s?s.substr(1):r;e[u]=i?t(i):i})),e}}return null}function d(e,t){if(t){const{original:{page:{type:o="",attributes:s={},state:u={}}={}}={}}=t,c=r(e),l=n(e),d=f(c,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(u).forEach((t=>{const r=u[t];let o;if(r&&i(r)){const t=r.substr(1);o=e[t]}else o=r;n[t]=o}));const c=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({},c),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 b(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){m(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 m(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(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))):[],[u]=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=b(b({},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 u||null}function h(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:b({},t.attributes),state:b({},t.state),pageReference:{type:t.type,attributes:b({},t.attributes),state:b({},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:u={}}={}}}=e,c=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(u).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(u).filter((e=>{const t=u[e];return null===t||!i(t)})).every((e=>u[e]===o[e]));return c&&a&&l&&p&&f&&d}));return e||null}return null}(e,t);return n?E(e,n,r):null}function v(e,t,r){const{attributeBindings:n,stateBindings:o}=r,{attributes:i,state:u}=t,c={};return e.forEach((e=>{const[t]=Object.keys(n).filter((t=>s(n[t])===e));if(t)c[e]=i[t];else{const[t]=Object.keys(o).filter((t=>s(o[t])===e));t&&(c[e]=u[t])}})),c}function E(e,t,r=""){const{params:n,original:{page:c={}}={},toPath:a,compiledQuery:l}=t,{attributes:f={},state:p={}}=c,d=a(v(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:u={}}=e||{},c={};Object.keys(u).filter((e=>!i(o[e]))).forEach((e=>c[e]=u[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}})),b(b({},c),a)}(e,v(u(l),e,{attributeBindings:f,stateBindings:p}),t);return`${r}${d}${o(g)}`}function w(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&&w(n,t-1)}}))}catch(e){}return e}const j="LWR",I=1;function P(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 R(e,t,r){if(!e)throw new Error(P(t,r))}const $={INVALID_MIXIN_CMP:{code:`${j}4001`,message:"{0} must be an Element type",level:I},MISSING_CONTEXT:{code:`${j}4002`,message:"Could not find context to perform navigation action.",level:I},INVALID_CONTEXT:{code:`${j}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:I},MULTIPLE_ROOTS:{code:`${j}4004`,message:"Router connection failed. There can only be one root router.",level:I},MULTIPLE_CHILDREN:{code:`${j}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:I},MISSING_ROUTE:{code:`${j}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:I,address:"{0}"},MISSING_URL:{code:`${j}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:I,address:"{0}"},PRENAV_FAILED:{code:`${j}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${j}4009`,message:'A route definition must contain a "uri" property.',level:I},MISSING_ROUTE_CMP:{code:`${j}4016`,message:"Expected a route view component with a default export.",level:I},MISSING_DATA_CONTEXT:{code:`${j}4018`,message:"Could not find context to retrieve navigation data.",level:I},INVALID_ROUTE_QUERY:{code:`${j}4019`,message:"Invalid query param in route definition.",level:I},MISSING_PAGE_BINDING:{code:`${j}4020`,message:"Route definition must provide page binding",level:I},INVALID_PAGE_BINDING:{code:`${j}4021`,message:"Invalid page binding in route definition",level:I},INVALID_URI_SYNTAX:{code:`${j}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:I},VIEW_IMPORT_FAILED:{code:`${j}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:I,stack:"{2}"},VIEW_MISSING:{code:`${j}4024`,message:'Expected a view with name "{0}" in the viewset',level:I},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${j}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:I,stack:"{3}"},NO_ROUTE_MATCH:{code:`${j}4026`,message:"A routing match cannot be found for: {0}",level:I},INVALID_ROUTE_HANDLER:{code:`${j}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:I},DESTINATION_NOT_FOUND:{code:`${j}4028`,message:"Route handler returned 404: Not Found",level:I},DESTINATION_ERROR:{code:`${j}4029`,message:"Route handler returned error status {0}: {1}",level:I,stack:"{2}"}};function N(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function D(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=`[^${N(t.delimiter||"/#?")}]+?`,i=[];let s=0,u=0,c="";const a=e=>{if(u<r.length&&r[u].type===e)return r[u++].value},l=e=>{const t=a(e);if(void 0!==t)return t;const{type:n,index:o}=r[u];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(;u<r.length;){const e=a("CHAR"),t=a("NAME"),r=a("PATTERN");if(t||r){let u=e||"";-1===n.indexOf(u)&&(c+=u,u=""),c&&(i.push(c),c=""),i.push({name:t||s++,prefix:u,suffix:"",pattern:r||o,modifier:a("MODIFIER")||""});continue}const u=e||a("ESCAPED_CHAR");if(u){c+=u;continue}c&&(i.push(c),c="");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 T(e,t){return function(e,t={}){const r=D(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 u=e[s];if("string"==typeof u){r+=u;continue}const c=t?t[u.name]:void 0,a="?"===u.modifier||"*"===u.modifier,l="*"===u.modifier||"+"===u.modifier;if(Array.isArray(c)){if(!l)throw new TypeError(`Expected "${u.name}" to not repeat, but got an array`);if(0===c.length){if(a)continue;throw new TypeError(`Expected "${u.name}" to not be empty`)}for(let e=0;e<c.length;e++){const t=n(c[e],u);if(o&&!i[s].test(t))throw new TypeError(`Expected all "${u.name}" to match "${u.pattern}", but got "${t}"`);r+=u.prefix+t+u.suffix}continue}if("string"==typeof c||"number"==typeof c){const e=n(String(c),u);if(o&&!i[s].test(e))throw new TypeError(`Expected "${u.name}" to match "${u.pattern}", but got "${e}"`);r+=u.prefix+e+u.suffix;continue}if(a)continue;const f=l?"an array":"a string";throw new TypeError(`Expected "${u.name}" to be ${f}`)}return r}}(A(e,t),t)}function _(e,t,r){return function(e,t,r={}){const{strict:n=!1,start:o=!0,end:i=!0,encode:s=(e=>e)}=r,u=`[${N(r.endsWith||"")}]|$`,c=`[${N(r.delimiter||"/#?")}]`;let a=o?"^":"";for(const r of e)if("string"==typeof r)a+=N(s(r));else{const e=N(s(r.prefix)),n=N(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+=`${c}?`),a+=r.endsWith?`(?=${u})`:"$";else{const t=e[e.length-1],r="string"==typeof t?c.indexOf(t[t.length-1])>-1:void 0===t;n||(a+=`(?:${c}(?=${u}))?`),r||(a+=`(?=${c}|${u})`)}return new RegExp(a,D(r))}(A(e,r),t,r)}function x(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=>x(e,t,r).source));return new RegExp(`(?:${n.join("|")})`,D(r))}(e,t,r):_(e,t,r)}function S(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 U(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?S(Object(r),!0).forEach((function(t){C(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):S(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function C(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const{INVALID_ROUTE_QUERY:k,MISSING_ROUTE_TEMPLATE:M,MISSING_PAGE_BINDING:L,INVALID_PAGE_BINDING:V,INVALID_URI_SYNTAX:H}=$;function G(e){const{routes:t,caseSensitive:o}=e;return t.map((e=>function(e,t=!1){const o=[],{uri:c,page:a}=e;R(!!c,M),R(function(e=""){const t=["*","(",")",";"].some((t=>e.indexOf(t)>=0));return!t}(c),H),R(!!a,L);const l=r(c),f=n(c),p=x(l,o,{sensitive:t,end:!1!==e.exact}),d=T(l,{encode:encodeURIComponent}),g=function(e){const t={};return Object.keys(e).forEach((r=>{const n=e[r];R(!i(r)||null===n,k),i(r)?t[r.substr(1)]={routeParamName:r}:n&&i(n)?t[r]={routeParamName:n}:t[r]={literalValue:null===n?null:n}})),t}(f),b=function(e,t=!1){const r=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],u=r[o];let c=!0;return"string"==typeof i?c=t?i===u:i.toUpperCase()===(null==u?u:u.toUpperCase()):null===i&&(c=u===i),n=c?U(U({},n),{},{[o]:{value:u,routeParamName:s}}):null}),{}):null};return r}(g,t),m={original:e,regex:p,params:o,toPath:d,compiledQuery:g,queryMatcher:b};return R(function(e){const{original:{page:t}={},params:r,compiledQuery:n}=e,o=t?t.type:t,c=(t?t.attributes:t)||{},a=(t?t.state:t)||{};if("string"!=typeof o||"object"!=typeof c||"object"!=typeof a)return!1;const l=Object.values(r).map((({name:e})=>e)),f=u(n),p=[...l,...f],d=Object.values(c).filter(i).map(s),g=Object.values(a).filter(i).map(s),b=p.every((e=>"string"==typeof e&&(d.indexOf(e)>=0||g.indexOf(e)>=0))),m=p.length===d.length+g.length;return!!(t&&o&&c&&a&&b&&m)}(m),V),m}(e,o)))}function F(){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 B(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 W(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){Q(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 Q(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class X{constructor(e){this.deprecatedConfig={},this.routeHandlerId=0,this.compiledRoutes=[],this.routeObservable=F(),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=h(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=G(this.config)}generateUrl(e){const{DEPRECATED_getUrlFromRoute:t}=this.deprecatedConfig;return t?t(e,this.config.generateUrl):this.config.generateUrl(e)}parseUrl(e){const{DEPRECATED_getRouteFromUrl:t}=this.deprecatedConfig;return t?t(e,this.config.parseUrl):this.config.parseUrl(e)}matchRoute(e){const t="string"==typeof e?e:this.generateUrl(e);if(null===t)return null;const r=h(t,this.compiledRoutes,this.config.basePath),n=r&&E(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(P($.INVALID_ROUTE_HANDLER,[n.routeDefinition.id]));const i=new o(t);i&&i.update(n.route)})):r(P($.NO_ROUTE_MATCH,[JSON.stringify(e)]))}))}navigate(e){const t=this.matchRoute(e);if(!t)throw new Error(P($.MISSING_ROUTE,[JSON.stringify(e)]));this.pendingRoute=W({},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(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||e!==this.routeHandlerId)return;if(!this.pendingRoute)throw new Error("Trying to commit route state without a route");const r=w(t.viewset);this.routeObservable.next(W(W(W({},this.pendingRoute),t),{},{viewset:r}))}}function q(e={}){return new X(e)}e(X,{fields:["deprecatedConfig","routeHandlerId"]});export{q as createRouter};
|
|
1
|
+
function e(e=""){return e=e||"",decodeURIComponent(e)}function t(e){"/"!==(e=e||"/").charAt(0)&&(e="/"+e);const t=e.match(/^[^#?]+/);if(null!==t){const e=t[0];return"/"===e?"/":e.replace(/\/$/,"")}return"/"}function n(t){const n=(t=t||"").indexOf("#");n>=0&&(t=t.substring(0,n));const r=t.indexOf("?"),o=r>=0?t.substr(r+1):null,i={};return o&&o.split("&").forEach((t=>{if(t.indexOf("=")>=0){const[n,r=""]=t.split("=");i[e(n)]=e(r)}else i[e(t)]=null})),i}function r(e={}){const t=Object.keys(e);return t.length?`?${t.map((t=>{const n=e[t];return null===n?t:`${t}=${function(e=""){return e=e||"",encodeURIComponent(e)}(n)}`})).join("&")}`:""}function o(e){return!!(e&&e.length>1)&&e.startsWith(":")}function i(e){return!!e&&(!!o(e)&&e.substr(1))}function s(e){return Object.values(e).reduce(((e,{routeParamName:t})=>{const n=i(t);return n&&e.push(n),e}),[])}function a(t,n){const{regex:r,params:o}=n,i=r.exec(t);if(i){const[,...t]=i,n={};return o.forEach(((r,o)=>{const{name:i}=r,s=t[o];n[i]=s?e(s):s})),n}return null}function u(t,n){if(t&&n){const{queryMatcher:r}=n,o=r(t);if(o){const t={};return Object.keys(o).forEach((n=>{const r=o[n],{value:i,routeParamName:s}=r,a=s?s.substr(1):n;t[a]=i?e(i):i})),t}}return null}function c(e,r){if(r){const{original:{page:{type:i="",attributes:s={},state:c={}}={}}={}}=r,l=t(e),f=n(e),d=a(l,r),p=u(f,r);if(d&&p){const e={...d,...p},t={};Object.keys(s).forEach((n=>{const r=s[n];let i;if(r&&o(r)){const t=r.substr(1);i=e[t]}else i=r;t[n]=i}));const n={};Object.keys(c).forEach((t=>{const r=c[t];let i;if(r&&o(r)){const t=r.substr(1);i=e[t]}else i=r;n[t]=i}));const a=function(e,t){const{compiledQuery:n}=t,r=Object.keys(n).filter((e=>{const{literalValue:t}=n[e];return!t})),o={};return Object.keys(e).forEach((t=>{const n=e[t];r.indexOf(t)<0&&(o[t]=n)})),o}(f,r);return{type:i,attributes:{...t},state:{...a,...n}}}}return null}function l(e,r){const o=t(e),i=n(e),s=r?r.filter((e=>e.regex.test(o))):[],[c]=s.filter((e=>{const{queryMatcher:t}=e;return t(i)&&function(e,t,n){const{original:{patterns:r=null}={}}=n||{};if(r){const o={...a(e,n),...u(t,n)};return Object.keys(r).every((e=>{const t=r[e],n=new RegExp(t),i=o[e]||"";return n.test(i)}))}return!0}(o,i,e)}));return c||null}function f(e,t,n=""){n&&0===e.indexOf(n)&&(e=e.replace(n,""));const r=l(e,t);let o;if(!r)return null;{const t=c(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:i={}}=e;if(n){const[e]=t.filter((e=>{const{original:{page:{type:t=null,attributes:s={},state:a={}}={}}}=e,u=t===n,c=Object.keys(s).every((e=>Object.keys(r).indexOf(e)>=0)),l=Object.keys(s).length===Object.keys(r).length,f=Object.keys(a).every((e=>Object.keys(i).indexOf(e)>=0)),d=Object.keys(s).filter((e=>{const t=s[e];return!t||!o(t)})).every((e=>s[e]===r[e])),p=Object.keys(a).filter((e=>{const t=a[e];return null===t||!o(t)})).every((e=>a[e]===i[e]));return u&&c&&l&&d&&f&&p}));return e||null}return null}(e,t);return r?h(e,r,n):null}function p(e,t,n){const{attributeBindings:r,stateBindings:o}=n,{attributes:s,state:a}=t,u={};return e.forEach((e=>{const[t]=Object.keys(r).filter((t=>i(r[t])===e));if(t)u[e]=s[t];else{const[t]=Object.keys(o).filter((t=>i(o[t])===e));t&&(u[e]=a[t])}})),u}function h(e,t,n=""){const{params:a,original:{page:u={}}={},toPath:c,compiledQuery:l}=t,{attributes:f={},state:d={}}=u,h=c(p(a.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:s={}}}}=n,{state:a={}}=e||{},u={};Object.keys(a).filter((e=>!o(s[e]))).forEach((e=>u[e]=a[e]));const c={};return Object.keys(t).forEach((e=>{const n=t[e],[o]=Object.keys(r).filter((t=>{const n=r[t],{routeParamName:o}=n;return i(o)===e}));if(o){c[o]=n}})),{...u,...c}}(e,p(s(l),e,{attributeBindings:f,stateBindings:d}),t);return`${n}${h}${r(g)}`}function g(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&&g(r,t-1)}}))}catch(e){}return e}const m="LWR",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 I={INVALID_MIXIN_CMP:{code:`${m}4001`,message:"{0} must be an Element type",level:E},MISSING_CONTEXT:{code:`${m}4002`,message:"Could not find context to perform navigation action.",level:E},INVALID_CONTEXT:{code:`${m}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:E},MULTIPLE_ROOTS:{code:`${m}4004`,message:"Router connection failed. There can only be one root router.",level:E},MULTIPLE_CHILDREN:{code:`${m}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:E},MISSING_ROUTE:{code:`${m}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:E,address:"{0}"},MISSING_URL:{code:`${m}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:E,address:"{0}"},PRENAV_FAILED:{code:`${m}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${m}4009`,message:'A route definition must contain a "uri" property.',level:E},MISSING_ROUTE_CMP:{code:`${m}4016`,message:"Expected a route view component with a default export.",level:E},MISSING_DATA_CONTEXT:{code:`${m}4018`,message:"Could not find context to retrieve navigation data.",level:E},INVALID_ROUTE_QUERY:{code:`${m}4019`,message:"Invalid query param in route definition.",level:E},MISSING_PAGE_BINDING:{code:`${m}4020`,message:"Route definition must provide page binding",level:E},INVALID_PAGE_BINDING:{code:`${m}4021`,message:"Invalid page binding in route definition",level:E},INVALID_URI_SYNTAX:{code:`${m}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:E},VIEW_IMPORT_FAILED:{code:`${m}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:E,stack:"{2}"},VIEW_MISSING:{code:`${m}4024`,message:'Expected a view with name "{0}" in the viewset',level:E},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${m}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:E,stack:"{3}"},NO_ROUTE_MATCH:{code:`${m}4026`,message:"A routing match cannot be found for: {0}",level:E},INVALID_ROUTE_HANDLER:{code:`${m}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:E},DESTINATION_NOT_FOUND:{code:`${m}4028`,message:"Route handler returned 404: Not Found",level:E},DESTINATION_ERROR:{code:`${m}4029`,message:"Route handler returned error status {0}: {1}",level:E,stack:"{2}"},NO_INIT_URL:{code:`${m}4030`,message:'Cannot initialize a server router without a "url"',level:E}};function v(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function R(e){return e&&e.sensitive?"":"i"}function $(e,t={}){const n=function(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];if("*"!==r&&"+"!==r&&"?"!==r)if("\\"!==r)if("{"!==r)if("}"!==r)if(":"!==r)if("("!==r)t.push({type:"CHAR",index:n,value:e[n++]});else{let r=1,o="",i=n+1;if("?"===e[i])throw new TypeError(`Pattern cannot start with "?" at ${i}`);for(;i<e.length;)if("\\"!==e[i]){if(")"===e[i]){if(r--,0===r){i++;break}}else if("("===e[i]&&(r++,"?"!==e[i+1]))throw new TypeError(`Capturing groups are not allowed at ${i}`);o+=e[i++]}else o+=e[i++]+e[i++];if(r)throw new TypeError(`Unbalanced pattern at ${n}`);if(!o)throw new TypeError(`Missing pattern at ${n}`);t.push({type:"PATTERN",index:n,value:o}),n=i}else{let r="",o=n+1;for(;o<e.length;){const t=e.charCodeAt(o);if(!(t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||95===t))break;r+=e[o++]}if(!r)throw new TypeError(`Missing parameter name at ${n}`);t.push({type:"NAME",index:n,value:r}),n=o}else t.push({type:"CLOSE",index:n,value:e[n++]});else t.push({type:"OPEN",index:n,value:e[n++]});else t.push({type:"ESCAPED_CHAR",index:n++,value:e[n++]});else t.push({type:"MODIFIER",index:n,value:e[n++]})}return t.push({type:"END",index:n,value:""}),t}(e),{prefixes:r="./"}=t,o=`[^${v(t.delimiter||"/#?")}]+?`,i=[];let s=0,a=0,u="";const c=e=>{if(a<n.length&&n[a].type===e)return n[a++].value},l=e=>{const t=c(e);if(void 0!==t)return t;const{type:r,index:o}=n[a];throw new TypeError(`Unexpected ${r} at ${o}, expected ${e}`)},f=()=>{let e,t="";for(;e=c("CHAR")||c("ESCAPED_CHAR");)t+=e;return t};for(;a<n.length;){const e=c("CHAR"),t=c("NAME"),n=c("PATTERN");if(t||n){let a=e||"";-1===r.indexOf(a)&&(u+=a,a=""),u&&(i.push(u),u=""),i.push({name:t||s++,prefix:a,suffix:"",pattern:n||o,modifier:c("MODIFIER")||""});continue}const a=e||c("ESCAPED_CHAR");if(a){u+=a;continue}u&&(i.push(u),u="");if(c("OPEN")){const e=f(),t=c("NAME")||"",n=c("PATTERN")||"",r=f();l("CLOSE"),i.push({name:t||(n?s++:""),pattern:t&&!n?o:n,prefix:e,suffix:r,modifier:c("MODIFIER")||""})}else l("END")}return i}function O(e,t){return function(e,t={}){const n=R(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}}($(e,t),t)}function N(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,R(n))}($(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("|")})`,R(n))}(e,t,n):N(e,t,n)}const{INVALID_ROUTE_QUERY:A,MISSING_ROUTE_TEMPLATE:x,MISSING_PAGE_BINDING:T,INVALID_PAGE_BINDING:w,INVALID_URI_SYNTAX:D}=I;function U(e){const{routes:r,caseSensitive:a}=e;return r.map((e=>function(e,r=!1){const a=[],{uri:u,page:c}=e;b(!!u,x),b(function(e=""){const t=["*","(",")",";"].some((t=>e.indexOf(t)>=0));return!t}(u),D),b(!!c,T);const l=t(u),f=n(u),d=_(l,a,{sensitive:r,end:!1!==e.exact}),p=O(l,{encode:encodeURIComponent}),h=function(e){const t={};return Object.keys(e).forEach((n=>{const r=e[n];b(!o(n)||null===r,A),o(n)?t[n.substr(1)]={routeParamName:n}:r&&o(r)?t[n]={routeParamName:r}:t[n]={literalValue:null===r?null:r}})),t}(f),g=function(e,t=!1){const n=n=>{const r=Object.keys(n),o=Object.keys(e);return o.every((e=>r.indexOf(e)>=0))?o.reduce(((r,o)=>{if(null===r)return null;const{literalValue:i,routeParamName:s}=e[o],a=n[o];let u=!0;return"string"==typeof i?u=t?i===a:i.toUpperCase()===(null==a?a:a.toUpperCase()):null===i&&(u=a===i),r=u?{...r,[o]:{value:a,routeParamName:s}}:null}),{}):null};return n}(h,r),m={original:e,regex:d,params:a,toPath:p,compiledQuery:h,queryMatcher:g};return b(function(e){const{original:{page:t}={},params:n,compiledQuery:r}=e,a=t?t.type:t,u=(t?t.attributes:t)||{},c=(t?t.state:t)||{};if("string"!=typeof a||"object"!=typeof u||"object"!=typeof c)return!1;const l=Object.values(n).map((({name:e})=>e)),f=s(r),d=[...l,...f],p=Object.values(u).filter(o).map(i),h=Object.values(c).filter(o).map(i),g=d.every((e=>"string"==typeof e&&(p.indexOf(e)>=0||h.indexOf(e)>=0))),m=d.length===p.length+h.length;return!!(t&&a&&u&&c&&g&&m)}(m),w),m}(e,a)))}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 C{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=>d(e,this.compiledRoutes,this.config.basePath),parseUrl:e=>function(e,t,n=""){const r=f(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=U(this.config)}generateUrl(e){const{DEPRECATED_getUrlFromRoute:t}=this.deprecatedConfig;return t?t(e,this.config.generateUrl):this.config.generateUrl(e)}parseUrl(e){const{DEPRECATED_getRouteFromUrl:t}=this.deprecatedConfig;return t?t(e,this.config.parseUrl):this.config.parseUrl(e)}matchRoute(e){const t="string"==typeof e?e:this.generateUrl(e);if(null===t)return null;const n=f(t,this.compiledRoutes,this.config.basePath),r=n&&h(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(I.INVALID_ROUTE_HANDLER,[r.routeDefinition.id]));const i=new o(t);i&&i.update(r.route)})):n(y(I.NO_ROUTE_MATCH,[JSON.stringify(e)]))}))}navigate(e){const t=this.matchRoute(e);if(!t)throw new Error(y(I.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?.()),r=n?.default;if(!r)throw new Error(y(I.INVALID_ROUTE_HANDLER,[e.routeDefinition.id]));return this.routeHandler=new r((e=>{this._updateView(t,e)})),this.routeHandler&&this.routeHandler.update(e.route),!0}_updateView(e,t){if(!t||e!==this.routeHandlerId)return;if(!this.pendingRoute)throw new Error("Trying to commit route state without a route");const n=g(t.viewset);this.routeObservable.next({...this.pendingRoute,...t,viewset:n})}}function S(e={}){return new C(e)}export{S as createRouter};
|
|
2
2
|
//# sourceMappingURL=router.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{parseFragment as e,registerTemplate as t,freezeTemplate as r,createContextProvider as i,registerDecorators as n,registerComponent as o,LightningElement as s}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as l,logOperationStart as h}from"lwr/profiler";var u=[function(e,t,r){return"span.router-title"+(e?"["+e+"]":"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}];const p=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,v={key:0},g=[];function f(e,t,r,i){const{s:n,st:o,f:s}=e;return s([n("",v,g,r),o(p(),2)])}var m=t(f);function b(e){if(null==e)throw new TypeError("Provider must be defined.")}f.slots=[""],f.stylesheets=[],f.renderMode="light",u&&f.stylesheets.push.apply(f.stylesheets,u),f.stylesheetToken="lwc-7bis3qj4jjc",r(f);class E{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){b(e);const r=t,i=this.getInfo(e);i.contextValue=t,i.consumers.forEach((e=>e.provide(r))),0===i.consumers.size&&r?.onComplete&&r.onComplete()}getContext(e){b(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){b(e),this.infoMap.delete(e)}subscribeContext(e,t){b(e);const{consumers:r,contextValue:i}=this.getInfo(e);r.has(t)||(r.add(t),t.provide(i))}unsubscribeContext(e,t){b(e),this.getInfo(e).consumers.delete(t)}}function I(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 w(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?I(Object(r),!0).forEach((function(t){N(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function N(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const y="LWR",_=1;function O(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,r)=>t[r])):e}function P(e,t){const r=w(w({},e),{},{message:O(e.message,t)});return e.address&&(r.address=O(e.address,t)),e.stack&&(r.stack=O(e.stack,t)),r}function R(e,t,r){if(!e)throw new Error(function(e,t){return`${e.code}: ${O(e.message,t)}`}(t,r))}const x={INVALID_MIXIN_CMP:{code:`${y}4001`,message:"{0} must be an Element type",level:_},MISSING_CONTEXT:{code:`${y}4002`,message:"Could not find context to perform navigation action.",level:_},INVALID_CONTEXT:{code:`${y}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:_},MULTIPLE_ROOTS:{code:`${y}4004`,message:"Router connection failed. There can only be one root router.",level:_},MULTIPLE_CHILDREN:{code:`${y}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:_},MISSING_ROUTE:{code:`${y}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:_,address:"{0}"},MISSING_URL:{code:`${y}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:_,address:"{0}"},PRENAV_FAILED:{code:`${y}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${y}4009`,message:'A route definition must contain a "uri" property.',level:_},MISSING_ROUTE_CMP:{code:`${y}4016`,message:"Expected a route view component with a default export.",level:_},MISSING_DATA_CONTEXT:{code:`${y}4018`,message:"Could not find context to retrieve navigation data.",level:_},INVALID_ROUTE_QUERY:{code:`${y}4019`,message:"Invalid query param in route definition.",level:_},MISSING_PAGE_BINDING:{code:`${y}4020`,message:"Route definition must provide page binding",level:_},INVALID_PAGE_BINDING:{code:`${y}4021`,message:"Invalid page binding in route definition",level:_},INVALID_URI_SYNTAX:{code:`${y}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:_},VIEW_IMPORT_FAILED:{code:`${y}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:_,stack:"{2}"},VIEW_MISSING:{code:`${y}4024`,message:'Expected a view with name "{0}" in the viewset',level:_},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${y}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:_,stack:"{3}"},NO_ROUTE_MATCH:{code:`${y}4026`,message:"A routing match cannot be found for: {0}",level:_},INVALID_ROUTE_HANDLER:{code:`${y}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:_},DESTINATION_NOT_FOUND:{code:`${y}4028`,message:"Route handler returned 404: Not Found",level:_},DESTINATION_ERROR:{code:`${y}4029`,message:"Route handler returned error status {0}: {1}",level:_,stack:"{2}"}},C=new WeakMap;function T(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,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 S=T(new E(void 0)),D=T(new E(void 0)),A=new E(void 0),M=class extends(T(A)){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?P(x.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[n.specifier,r,t.message,t.stack||""]):P(x.VIEW_IMPORT_FAILED,[r,t.message,t.stack||""])}else s=P(x.VIEW_MISSING,[r]);t.onComplete&&t.onComplete(s)}}};function $(){const e=[],t=t=>{"function"==typeof t&&e.push(t)};return{add:(e=[])=>{Array.isArray(e)?e.forEach((e=>t(e))):t(e)},compile:t=>0===e.length?Promise.resolve(!0):e.reduce(((e,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 L(e=""){return e=e||"",decodeURIComponent(e)}function j(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const U="undefined"!=typeof document,k=`universalcontainergetnavigationcontext${j()}`,F=U?i(D):void 0,V=U?i(M):void 0,G=U?i(S):void 0;function W(e,t,r,i){r&&i&&(i.setContext(t,e),r(t,{consumerConnectedCallback:i.subscribeContext.bind(i,t),consumerDisconnectedCallback:i.unsubscribeContext.bind(i,t)}))}function H(){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 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 X(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){q(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 q(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const z=`universalcontainernavigationevent${j()}`,Y=`universalcontainerparentevent${j()}`;class J{constructor(e,t,r){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=$(),this.errorNavFilters=$(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:r,address:i}=t.detail;this.config.handleNavigation(i,r)?this.root&&!e?this.root.processError(P(x.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.router.contextId=this.contextId,this.routeObservable=H()}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;l({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||X(X({},e),{},{url:t}),this.committedRoute=X(X({},this.pendingRoute),e),D.setContext(this.target,e.route.pageReference),this.routeObservable.next(X(X({},this.committedRoute),{},{viewset:e.viewset})),l({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(Y,(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}};C.set(r.id,r)}(this.contextId,e),W(this.contextId,this.target,G,S),W(void 0,this.target,F,D),W(void 0,this.target,V,M),this.router.subscribe((e=>{if(404===e.status)return void this.processError(P(x.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(P(x.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},r=this.router.generateUrl(t)||"";if(h({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,r)};M.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,r)}),!0),U&&(this.target.addEventListener(z,this._handleNavigationEvent),this.target.addEventListener(Y,this._handleParentEvent),this.target.addEventListener(k,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(z,this._handleNavigationEvent),this.target.removeEventListener(Y,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{R(!this.child,x.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t){this.eventId=(new Date).getTime().toString(),h({id:c,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(P(x.MISSING_ROUTE,[e]));this.pendingRoute=X({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(P(x.PRENAV_FAILED,[e]))))}processError(e){h({id:d}),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(z,{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){U&&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 Q(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[L(r)]=L(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,"")}class K extends J{constructor(){super(...arguments),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(U&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&U&&this.catchBrowserUpdate(Q(document.location.href))}disconnect(){super.disconnect(),U&&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)}}let Z=!1;class ee extends s{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=U?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 J(t,r,e):new K(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(),R(!Z||!!i.parent,x.MULTIPLE_ROOTS),Z=Z||!i.parent,n.id=i.contextId},disconnect:()=>{Z=Z&&!!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);const r=this.querySelector("span.router-title");r&&(r.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})}}ee.renderMode="light",n(ee,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var te=o(ee,{tmpl:m,sel:"lwr-router-container",apiVersion:59});export{te as default};
|
|
1
|
+
import{parseFragment as e,registerTemplate as t,freezeTemplate as i,createContextProvider as r,registerDecorators as s,registerComponent as o,LightningElement as n}from"lwc";import{ROUTER_VIEW as a,ROUTER_NAV as c,ROUTER_ERROR as d}from"lwr/metrics";import{logOperationEnd as h,logOperationStart as l}from"lwr/profiler";var u=[function(e,t,i){return"span.router-title"+(e?"["+e+"]":"")+" {position: absolute;margin: -1px;border: 0;padding: 0;width: 1px;height: 1px;overflow: hidden;clip: rect(0 0 0 0);text-transform: none;white-space: nowrap;}"}];const p=e`<span class="router-title${0}" aria-live="polite" aria-atomic="true"${2}></span>`,v={key:0},g=[];function m(e,t,i,r){const{s:s,st:o}=e;return[s("",v,g,i),o(p(),2)]}var f=t(m);function E(e){if(null==e)throw new TypeError("Provider must be defined.")}m.slots=[""],m.stylesheets=[],m.renderMode="light",u&&m.stylesheets.push.apply(m.stylesheets,u),m.stylesheetToken="lwc-7bis3qj4jjc",m.legacyStylesheetToken="lwr-routerContainer_routerContainer",i(m);class I{constructor(e){this.infoMap=new WeakMap,this.defaultValue=e}getInfo(e){let t=this.infoMap.get(e);return void 0===t&&(t={consumers:new Set},this.infoMap.set(e,t)),t}setContext(e,t){E(e);const i=t,r=this.getInfo(e);r.contextValue=t,r.consumers.forEach((e=>e.provide(i))),0===r.consumers.size&&i?.onComplete&&i.onComplete()}getContext(e){E(e);const{contextValue:t}=this.getInfo(e);return void 0!==t?t:this.defaultValue}clearContext(e){E(e),this.infoMap.delete(e)}subscribeContext(e,t){E(e);const{consumers:i,contextValue:r}=this.getInfo(e);i.has(t)||(i.add(t),t.provide(r))}unsubscribeContext(e,t){E(e),this.getInfo(e).consumers.delete(t)}}const b="LWR",N=1;function w(e,t){return Array.isArray(t)?e.replace(/\{([0-9]+)\}/g,((e,i)=>t[i])):e}function _(e,t){const i={...e,message:w(e.message,t)};return e.address&&(i.address=w(e.address,t)),e.stack&&(i.stack=w(e.stack,t)),i}function R(e,t,i){if(!e)throw new Error(function(e,t){return`${e.code}: ${w(e.message,t)}`}(t,i))}const x={INVALID_MIXIN_CMP:{code:`${b}4001`,message:"{0} must be an Element type",level:N},MISSING_CONTEXT:{code:`${b}4002`,message:"Could not find context to perform navigation action.",level:N},INVALID_CONTEXT:{code:`${b}4003`,message:"Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }",level:N},MULTIPLE_ROOTS:{code:`${b}4004`,message:"Router connection failed. There can only be one root router.",level:N},MULTIPLE_CHILDREN:{code:`${b}4005`,message:"Could not add to the navigation hierarchy. There can only be one child per navigation node.",level:N},MISSING_ROUTE:{code:`${b}4006`,message:'A route cannot be created to navigate to URL "{0}"',level:N,address:"{0}"},MISSING_URL:{code:`${b}4007`,message:'A URL cannot be created to navigate to route "{0}"',level:N,address:"{0}"},PRENAV_FAILED:{code:`${b}4008`,message:'A preNavigate hook listener blocked routing to "{0}"',level:2,address:"{0}"},MISSING_ROUTE_TEMPLATE:{code:`${b}4009`,message:'A route definition must contain a "uri" property.',level:N},MISSING_ROUTE_CMP:{code:`${b}4016`,message:"Expected a route view component with a default export.",level:N},MISSING_DATA_CONTEXT:{code:`${b}4018`,message:"Could not find context to retrieve navigation data.",level:N},INVALID_ROUTE_QUERY:{code:`${b}4019`,message:"Invalid query param in route definition.",level:N},MISSING_PAGE_BINDING:{code:`${b}4020`,message:"Route definition must provide page binding",level:N},INVALID_PAGE_BINDING:{code:`${b}4021`,message:"Invalid page binding in route definition",level:N},INVALID_URI_SYNTAX:{code:`${b}4022`,message:"Invalid uri syntax. URI cannot contain *, +, (, ), ",level:N},VIEW_IMPORT_FAILED:{code:`${b}4023`,message:'Error importing view with name "{0}", failure was: {1}',level:N,stack:"{2}"},VIEW_MISSING:{code:`${b}4024`,message:'Expected a view with name "{0}" in the viewset',level:N},VIEW_IMPORT_FAILED_WITH_SPECIFIER:{code:`${b}4025`,message:'Error importing module "{0}" from view with name "{1}", failure was: {2}',level:N,stack:"{3}"},NO_ROUTE_MATCH:{code:`${b}4026`,message:"A routing match cannot be found for: {0}",level:N},INVALID_ROUTE_HANDLER:{code:`${b}4027`,message:'Route definition "{0}" does not have a valid route handler module',level:N},DESTINATION_NOT_FOUND:{code:`${b}4028`,message:"Route handler returned 404: Not Found",level:N},DESTINATION_ERROR:{code:`${b}4029`,message:"Route handler returned error status {0}: {1}",level:N,stack:"{2}"},NO_INIT_URL:{code:`${b}4030`,message:'Cannot initialize a server router without a "url"',level:N}},C=new WeakMap;function T(e){var t;return(t=class{constructor(e){this._callback=e}connect(){}disconnect(){}update(e,t){t&&this._callback(t)}static setContext(t,i){e.setContext(t,i)}static getContext(t){return e.getContext(t)}static clearContext(t){e.clearContext(t)}static subscribeContext(t,i){e.subscribeContext(t,i)}static unsubscribeContext(t,i){e.unsubscribeContext(t,i)}}).contextSchema={value:"required"},t}const P=T(new I(void 0)),y=T(new I(void 0)),S=new I(void 0),A=class extends(T(S)){async update(e,t){if(t){const i=e&&e.viewName?e.viewName:"default",r=t.viewset[i],s=r,o=s&&s.module||r;let n;if(o)try{const e=await o(),t=e&&e.default;if(!t||void 0===t.constructor)throw new Error("error occurred with view import");this._callback(t)}catch(e){const t=e;n=s.specifier?_(x.VIEW_IMPORT_FAILED_WITH_SPECIFIER,[s.specifier,i,t.message,t.stack||""]):_(x.VIEW_IMPORT_FAILED,[i,t.message,t.stack||""])}else n=_(x.VIEW_MISSING,[i]);t.onComplete&&t.onComplete(n)}}};function $(){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 M(e=""){return e=e||"",decodeURIComponent(e)}function L(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}const O="undefined"!=typeof document,U=`universalcontainergetnavigationcontext${L()}`,D=r(y),k=O?r(A):void 0,F=r(P);function V(e,t,i,r){i&&r&&(r.setContext(t,e),i(t,{consumerConnectedCallback:r.subscribeContext.bind(r,t),consumerDisconnectedCallback:r.unsubscribeContext.bind(r,t)}))}function G(){let e,t,i=[];const r=r=>{i.filter((e=>null!==e)).forEach((e=>e.error&&e.error(r))),e=void 0,t=r};return{next:r=>{i.filter((e=>null!==e)).forEach((e=>e.next&&e.next(r))),e=r,t=void 0},error:r,complete:()=>{i.filter((e=>null!==e)).forEach((e=>e.complete&&e.complete())),i=[],e=void 0,t=void 0},subscribe:(s,o=!0)=>{(e=>{i.push(e)})(s),e&&o&&s.next(e),t&&r(t);const n=i.length-1;return{unsubscribe:()=>(e=>{i=[...i.slice(0,e),...i.slice(e+1)]})(n)}}}}const W=`universalcontainernavigationevent${L()}`,j=`universalcontainerparentevent${L()}`;class H{constructor(e,t,i){this.pendingRoute=null,this.committedRoute=null,this.contextId=Object.freeze((()=>{})),this.connected=!1,this.preNavFilters=$(),this.errorNavFilters=$(),this._handleNavigationEvent=e=>{const t=e;if(t.detail&&"object"==typeof t.detail){const{url:e,replace:i,address:r}=t.detail;this.config.handleNavigation(r,i)?this.root&&!e?this.root.processError(_(x.MISSING_URL,[JSON.stringify(r)])):this.parent||this.process(e,i):t.stopPropagation()}},this._handleParentEvent=e=>{e.stopImmediatePropagation();const t=e;t&&t.detail&&"function"==typeof t.detail&&t.detail(this)},this.config={handleNavigation:e.handleNavigation||(()=>!0)},this.target=i||window,this.router=t,this.router.contextId=this.contextId,this.routeObservable=G()}get root(){if(!this.parent)return this;let e=this.parent;for(;e;){if(!e.parent)return e;e=e.parent}throw new Error("No root router could be found")}updateWires(e,t,i){if(i)this.processError(i);else{if(this.committedRoute&&e.route===this.committedRoute.route)return;h({id:a,specifier:this.eventId}),this.pendingRoute=this.pendingRoute||{...e,url:t},this.committedRoute={...this.pendingRoute,...e},y.setContext(this.target,e.route.pageReference),this.routeObservable.next({...this.committedRoute,viewset:e.viewset}),h({id:c,specifier:this.eventId}),this.child&&this.child.process(this._stripUrlForChild(this.committedRoute.url))}}connect(){this._sendEvent(j,(e=>{this.parent=e,e.addChild(this)}));const e={navigate:(e,t)=>this.navigate(e,t),generateUrl:e=>this.generateUrl(e),subscribe:(e,t)=>this.subscribe(e,t)};!function(e,t){const i={id:e,value:t,update:e=>{i.value=e}};C.set(i.id,i)}(this.contextId,e),V(this.contextId,this.target,F,P),V(void 0,this.target,D,y),V(void 0,this.target,k,A),this.router.subscribe((e=>{if(404===e.status)return void this.processError(_(x.DESTINATION_NOT_FOUND));if(e.status&&e.status>=400){const t=e.error||new Error;return void this.processError(_(x.DESTINATION_ERROR,[e.status.toString(),t.message,t.stack||""]))}const t=e.route.pageReference||{},i=this.router.generateUrl(t)||"";if(l({id:a,specifier:this.eventId}),e.viewset){const t={viewset:e.viewset,onComplete:this.updateWires.bind(this,e,i)};A.setContext(this.target,t)}else e.route.pageReference&&this.updateWires(e,i)}),!0),O&&(this.target.addEventListener(W,this._handleNavigationEvent),this.target.addEventListener(j,this._handleParentEvent),this.target.addEventListener(U,(e=>{const t=e;t.detail.callback&&t.detail.callback(this.contextId)}))),this.connected=!0}disconnect(){this.target.removeEventListener(W,this._handleNavigationEvent),this.target.removeEventListener(j,this._handleParentEvent),this.parent&&(this.parent.child=void 0),this.parent=void 0,this.child&&(this.child.parent=void 0),this.child=void 0,this.connected=!1}addPreNavigate(e){this.preNavFilters.add(e)}addErrorNavigate(e){this.errorNavFilters.add(e)}async addChild(e){if(await new Promise((t=>{setTimeout((()=>{R(!this.child,x.MULTIPLE_CHILDREN),this.child=e,t()}),0)})),this.child&&this.committedRoute){const e=this._stripUrlForChild(this.committedRoute.url);await this.child.preProcess(e)&&this.child.process(e)}}async process(e,t){this.eventId=(new Date).getTime().toString(),l({id:c,specifier:this.eventId});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(_(x.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(_(x.PRENAV_FAILED,[e]))))}processError(e){l({id:d}),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(W,{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){O&&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 B(e){const t=function(e=""){if((e=e||"").indexOf("://")<0){const t=window.location.port?`:${window.location.port}`:"",i=`${window.location.protocol}//${window.location.hostname}${t}`,r="/"===e.charAt(0)?"":"/";e=i+r+e}const t={},i=document.createElement("a");i.href=e;const r=i.search.substring(1);return r&&r.split("&").forEach((e=>{const[i,r=""]=e.split("=");t[M(i)]=M(r)})),{href:i.href,origin:`${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`,pathname:i.pathname.replace(/(\/)?/,"/"),searchParams:t}}(e),i=t.href.replace(/:\d+/,""),r=t.origin.replace(/:\d+/,"");return i.replace(r,"")}class X extends H{constructor(){super(...arguments),this.historyDisabled=!1}connect(){super.connect(),this.historyDisabled||(O&&window.addEventListener("popstate",this.onpopstate.bind(this)),this.onpopstate())}onpopstate(){!this.parent&&O&&this.catchBrowserUpdate(B(window.location.href))}disconnect(){super.disconnect(),O&&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)}}let q=!1;class z extends n{constructor(){super(),this.router=void 0,this.historyDisabled=!1,this.currentTitle=O?document.title:""}connectedCallback(){const e={historyDisabled:this.historyDisabled,handleNavigation:this.handleNavigation.bind(this)};O&&this.router&&(this.routerApi=function(e,t={},i){const r=t.historyDisabled?new H(t,i,e):new X(t,i,e),s={addPreNavigate:e=>(r.addPreNavigate(e),s),addPostNavigate:e=>(r.subscribe(e),s),addErrorNavigate:e=>(r.addErrorNavigate(e),s),connect:()=>{r.connect(),R(!q||!!r.parent,x.MULTIPLE_ROOTS),q=q||!r.parent,s.id=r.contextId},disconnect:()=>{q=q&&!!r.parent,r.disconnect()}};return s}(this,e,this.router),this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect())}preNavigate(e){const t=this._createEvent("prenavigate",e,!0);return this.dispatchEvent(t),!t.defaultPrevented}postNavigate(e){this.dispatchEvent(this._createEvent("postnavigate",e));const t=e.routeDefinition.metadata&&e.routeDefinition.metadata.title;t&&(this.currentTitle=t,document.title=t);const i=this.querySelector("span.router-title");i&&(i.innerHTML=this.currentTitle)}errorNavigate(e){return this.dispatchEvent(this._createEvent("errornavigate",e)),!0}handleNavigation(e,t){const i=this._createEvent("handlenavigation",{address:e,replace:t},!0);return this.dispatchEvent(i),!i.defaultPrevented}disconnectedCallback(){this.routerApi&&this.routerApi.disconnect()}_createEvent(e,t,i){return new CustomEvent(e,{detail:t,bubbles:!1,composed:!1,cancelable:i})}}z.renderMode="light",s(z,{publicProps:{router:{config:0},historyDisabled:{config:0}}});var Y=o(z,{tmpl:f,sel:"lwr-router-container",apiVersion:60});export{Y as default};
|
|
2
2
|
//# sourceMappingURL=routerContainer.js.map
|
|
@@ -32,9 +32,9 @@ __export(exports, {
|
|
|
32
32
|
var import_lwc = __toModule(require("lwc"));
|
|
33
33
|
var import_routerUtils = __toModule(require("lwr/routerUtils"));
|
|
34
34
|
var import_navigation = __toModule(require("lwr/navigation"));
|
|
35
|
-
var currentPageReferenceContextualizer =
|
|
35
|
+
var currentPageReferenceContextualizer = (0, import_lwc.createContextProvider)(import_navigation.CurrentPageReference);
|
|
36
36
|
var currentViewContextualizer = import_routerUtils.hasDocument ? (0, import_lwc.createContextProvider)(import_navigation.CurrentView) : void 0;
|
|
37
|
-
var navigationContextContextualizer =
|
|
37
|
+
var navigationContextContextualizer = (0, import_lwc.createContextProvider)(import_navigation.NavigationContext);
|
|
38
38
|
function provideContext(contextValue, providerNode, contextualizer, contextualAdapter) {
|
|
39
39
|
if (contextualizer && contextualAdapter) {
|
|
40
40
|
contextualAdapter.setContext(providerNode, contextValue);
|
|
@@ -44,7 +44,7 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
|
|
|
44
44
|
}
|
|
45
45
|
onpopstate() {
|
|
46
46
|
if (!this.parent && import_routerUtils.hasDocument) {
|
|
47
|
-
this.catchBrowserUpdate((0, import_domRouterUtils.getRelativeUrl)(
|
|
47
|
+
this.catchBrowserUpdate((0, import_domRouterUtils.getRelativeUrl)(window.location.href));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
disconnect() {
|
|
@@ -89,7 +89,7 @@ var RouterImpl = class {
|
|
|
89
89
|
if (!routingMatch) {
|
|
90
90
|
return reject((0, import_routerErrors.generateMessage)(import_routerErrors.messages.NO_ROUTE_MATCH, [JSON.stringify(address)]));
|
|
91
91
|
}
|
|
92
|
-
return routingMatch.routeDefinition.handler().then((handlerModule) => {
|
|
92
|
+
return routingMatch.routeDefinition.handler?.().then((handlerModule) => {
|
|
93
93
|
const routeHandlerClass = handlerModule.default;
|
|
94
94
|
if (!routeHandlerClass) {
|
|
95
95
|
return reject((0, import_routerErrors.generateMessage)(import_routerErrors.messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id]));
|
|
@@ -121,8 +121,8 @@ var RouterImpl = class {
|
|
|
121
121
|
async _mapView(routingMatch) {
|
|
122
122
|
const routeHandlerId = Math.random();
|
|
123
123
|
this.routeHandlerId = routeHandlerId;
|
|
124
|
-
const handlerModule = await routingMatch.routeDefinition.handler();
|
|
125
|
-
const routeHandlerClass = handlerModule
|
|
124
|
+
const handlerModule = await routingMatch.routeDefinition.handler?.();
|
|
125
|
+
const routeHandlerClass = handlerModule?.default;
|
|
126
126
|
if (!routeHandlerClass) {
|
|
127
127
|
throw new Error((0, import_routerErrors.generateMessage)(import_routerErrors.messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id]));
|
|
128
128
|
}
|
|
@@ -49,7 +49,7 @@ var RouterContainer = class extends import_lwc.LightningElement {
|
|
|
49
49
|
historyDisabled: this.historyDisabled,
|
|
50
50
|
handleNavigation: this.handleNavigation.bind(this)
|
|
51
51
|
};
|
|
52
|
-
if (this.router) {
|
|
52
|
+
if (import_routerUtils.hasDocument && this.router) {
|
|
53
53
|
this.routerApi = (0, import_utils.createNavigationContext)(this, config, this.router);
|
|
54
54
|
this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect();
|
|
55
55
|
}
|
|
@@ -162,5 +162,10 @@ var messages = {
|
|
|
162
162
|
message: "Route handler returned error status {0}: {1}",
|
|
163
163
|
level: DiagnosticLevel.Error,
|
|
164
164
|
stack: "{2}"
|
|
165
|
+
},
|
|
166
|
+
NO_INIT_URL: {
|
|
167
|
+
code: `${ERROR_CODE_PREFIX}4030`,
|
|
168
|
+
message: 'Cannot initialize a server router without a "url"',
|
|
169
|
+
level: DiagnosticLevel.Error
|
|
165
170
|
}
|
|
166
171
|
};
|
|
@@ -0,0 +1,121 @@
|
|
|
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/serverRouter/serverRouter.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
ServerRouter: () => ServerRouter,
|
|
28
|
+
createServerRouter: () => createServerRouter
|
|
29
|
+
});
|
|
30
|
+
var import_contextProvider = __toModule(require("lwr/contextProvider"));
|
|
31
|
+
var import_metrics = __toModule(require("lwr/metrics"));
|
|
32
|
+
var import_navigation = __toModule(require("lwr/navigation"));
|
|
33
|
+
var import_navigationMixinHacks = __toModule(require("lwr/navigationMixinHacks"));
|
|
34
|
+
var import_profiler = __toModule(require("lwr/profiler"));
|
|
35
|
+
var import_router = __toModule(require("lwr/router"));
|
|
36
|
+
var import_routerErrors = __toModule(require("lwr/routerErrors"));
|
|
37
|
+
var import_routerUtils = __toModule(require("lwr/routerUtils"));
|
|
38
|
+
var ServerRouter = class {
|
|
39
|
+
constructor(config, router, target) {
|
|
40
|
+
this.contextId = Object.freeze(() => void 0);
|
|
41
|
+
this.router = router;
|
|
42
|
+
this.target = target;
|
|
43
|
+
this.preNavHook = config.preNavigate;
|
|
44
|
+
this.errorNavHook = config.errorNavigate;
|
|
45
|
+
this.initWires(config.url);
|
|
46
|
+
}
|
|
47
|
+
async navigate(address) {
|
|
48
|
+
if (import_routerUtils.hasDocument) {
|
|
49
|
+
const url = await this.getValidatedUrl(address);
|
|
50
|
+
if (url) {
|
|
51
|
+
document.location.href = url;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
generateUrl(address) {
|
|
56
|
+
return this.router.generateUrl(address);
|
|
57
|
+
}
|
|
58
|
+
initWires(url) {
|
|
59
|
+
if (!url && import_routerUtils.hasDocument) {
|
|
60
|
+
url = document.location.href;
|
|
61
|
+
}
|
|
62
|
+
if (!url) {
|
|
63
|
+
this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.NO_INIT_URL));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
url = this.getRelativeUrl(url);
|
|
67
|
+
const routingMatch = this.router.matchRoute(url);
|
|
68
|
+
if (!routingMatch) {
|
|
69
|
+
this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.MISSING_ROUTE, [url]));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.currentRoute = routingMatch;
|
|
73
|
+
(0, import_navigation.registerNavigationHelm)(this.contextId, {
|
|
74
|
+
navigate: (address) => this.navigate(address),
|
|
75
|
+
generateUrl: (address) => this.generateUrl(address),
|
|
76
|
+
subscribe: () => {
|
|
77
|
+
throw new Error("The server router does not support the subscribe API");
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
(0, import_contextProvider.provideContext)(this.contextId, this.target, import_contextProvider.navigationContextContextualizer, import_navigation.NavigationContext);
|
|
81
|
+
(0, import_contextProvider.provideContext)(this.currentRoute?.route.pageReference, this.target, import_contextProvider.currentPageReferenceContextualizer, import_navigation.CurrentPageReference);
|
|
82
|
+
if (import_routerUtils.hasDocument) {
|
|
83
|
+
this.target.addEventListener(import_navigationMixinHacks.CONTEXT_ID_BACKDOOR, (event) => {
|
|
84
|
+
const navCtxEvent = event;
|
|
85
|
+
if (navCtxEvent.detail.callback) {
|
|
86
|
+
navCtxEvent.detail.callback(this.contextId);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
getRelativeUrl(url) {
|
|
92
|
+
if (url.startsWith("http")) {
|
|
93
|
+
const parsed = new URL(url);
|
|
94
|
+
return `${parsed.pathname}${parsed.search}`;
|
|
95
|
+
}
|
|
96
|
+
return url;
|
|
97
|
+
}
|
|
98
|
+
async getValidatedUrl(address) {
|
|
99
|
+
const routingMatch = this.router.matchRoute(address);
|
|
100
|
+
if (!routingMatch) {
|
|
101
|
+
this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.NO_ROUTE_MATCH, [JSON.stringify(address)]));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const valid = this.preNavHook && await this.preNavHook({
|
|
105
|
+
current: this.currentRoute,
|
|
106
|
+
next: routingMatch
|
|
107
|
+
});
|
|
108
|
+
if (!valid) {
|
|
109
|
+
this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.PRENAV_FAILED, [JSON.stringify(address)]));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
return this.router.generateUrl(address);
|
|
113
|
+
}
|
|
114
|
+
processError(messageObject) {
|
|
115
|
+
(0, import_profiler.logOperationStart)({id: import_metrics.ROUTER_ERROR});
|
|
116
|
+
this.errorNavHook && this.errorNavHook(messageObject);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
function createServerRouter(config, target) {
|
|
120
|
+
new ServerRouter(config, (0, import_router.createRouter)(config), target);
|
|
121
|
+
}
|
|
@@ -30,6 +30,7 @@ __export(exports, {
|
|
|
30
30
|
parseSpecifier: () => parseSpecifier,
|
|
31
31
|
setUpWatcher: () => setUpWatcher
|
|
32
32
|
});
|
|
33
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
33
34
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
34
35
|
var SPECIFIER_PREFIX = "@lwrjs/router/";
|
|
35
36
|
function parseSpecifier(specifier) {
|
|
@@ -43,7 +44,7 @@ function setUpWatcher(factory, onModuleChange) {
|
|
|
43
44
|
const watcher = factory.createFileWatcher();
|
|
44
45
|
watcher.on("change", (0, import_shared_utils.debounce)((file) => onModuleChange(file), 500));
|
|
45
46
|
watcher.on("unlink", (0, import_shared_utils.debounce)((file) => onModuleChange(file, true), 500));
|
|
46
|
-
watcher.on("add", (file) =>
|
|
47
|
+
watcher.on("add", (file) => import_diagnostics.logger.info(`Watching Router Config file at "${file}"`));
|
|
47
48
|
return watcher;
|
|
48
49
|
}
|
|
49
50
|
function getHandlerClassName(specifier) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ContextualWireAdapter } from 'lwr/contextUtils';
|
|
3
|
-
export declare const currentPageReferenceContextualizer: Contextualizer
|
|
4
|
-
export declare const currentViewContextualizer: Contextualizer
|
|
5
|
-
|
|
1
|
+
/// <reference types="lwc" />
|
|
2
|
+
import type { ContextualWireAdapter, LwcContextualizer } from 'lwr/contextUtils';
|
|
3
|
+
export declare const currentPageReferenceContextualizer: import("lwc").Contextualizer<import("lwr/routerUtils").PageReference>;
|
|
4
|
+
export declare const currentViewContextualizer: import("lwc").Contextualizer<{
|
|
5
|
+
viewset: import("lwr/routerUtils").ViewSet;
|
|
6
|
+
onComplete?: Function | undefined;
|
|
7
|
+
}> | undefined;
|
|
8
|
+
export declare const navigationContextContextualizer: import("lwc").Contextualizer<import("lwr/navigation").ContextId>;
|
|
6
9
|
/**
|
|
7
10
|
*
|
|
8
11
|
* @param {TContext} contextValue - Context API object
|
|
@@ -10,5 +13,5 @@ export declare const navigationContextContextualizer: Contextualizer | undefined
|
|
|
10
13
|
* @param {Contextualizer} contextualizer - Function for providing this context to subtree nodes wired to a specific adapter
|
|
11
14
|
* @param {ContextualWireAdapter<TContext, TEmit, TConfig>} contextualAdapter - Contextual wire adapter capable of subscribing to context changes
|
|
12
15
|
*/
|
|
13
|
-
export declare function provideContext<TContext, TEmit, TConfig>(contextValue: TContext, providerNode: EventTarget, contextualizer?:
|
|
16
|
+
export declare function provideContext<TContext, TEmit, TConfig>(contextValue: TContext, providerNode: EventTarget, contextualizer?: LwcContextualizer, contextualAdapter?: ContextualWireAdapter<TContext, TEmit, TConfig>): void;
|
|
14
17
|
//# sourceMappingURL=contextProvider.d.ts.map
|
|
@@ -2,13 +2,9 @@ import { createContextProvider } from 'lwc';
|
|
|
2
2
|
import { hasDocument } from 'lwr/routerUtils';
|
|
3
3
|
import { CurrentPageReference, CurrentView, NavigationContext } from 'lwr/navigation';
|
|
4
4
|
// Creating a context with LWC requires eventing APIs, which are not available from "@lwc/engine-server"
|
|
5
|
-
export const currentPageReferenceContextualizer =
|
|
6
|
-
? createContextProvider(CurrentPageReference)
|
|
7
|
-
: undefined;
|
|
5
|
+
export const currentPageReferenceContextualizer = createContextProvider(CurrentPageReference);
|
|
8
6
|
export const currentViewContextualizer = hasDocument ? createContextProvider(CurrentView) : undefined;
|
|
9
|
-
export const navigationContextContextualizer =
|
|
10
|
-
? createContextProvider(NavigationContext)
|
|
11
|
-
: undefined;
|
|
7
|
+
export const navigationContextContextualizer = createContextProvider(NavigationContext);
|
|
12
8
|
/**
|
|
13
9
|
*
|
|
14
10
|
* @param {TContext} contextValue - Context API object
|
|
@@ -18,7 +14,7 @@ export const navigationContextContextualizer = hasDocument
|
|
|
18
14
|
*/
|
|
19
15
|
export function provideContext(contextValue, providerNode, contextualizer, contextualAdapter) {
|
|
20
16
|
if (contextualizer && contextualAdapter) {
|
|
21
|
-
// Set up provider to give context to wire
|
|
17
|
+
// Set up provider to give context to wire adapters so that a component connected
|
|
22
18
|
// under the providerNode subtree and wired to those adapters will receive this id
|
|
23
19
|
contextualAdapter.setContext(providerNode, contextValue);
|
|
24
20
|
contextualizer(providerNode, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LwcContextConsumer } from './contextUtils';
|
|
2
2
|
/**
|
|
3
3
|
* Manages context for various providers
|
|
4
4
|
*/
|
|
@@ -14,7 +14,7 @@ export declare class ContextInfo<TContext> {
|
|
|
14
14
|
* @param targetProvider the context provider
|
|
15
15
|
*/
|
|
16
16
|
getInfo(targetProvider: object): {
|
|
17
|
-
consumers: Set<
|
|
17
|
+
consumers: Set<LwcContextConsumer>;
|
|
18
18
|
contextValue: TContext;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
@@ -48,13 +48,13 @@ export declare class ContextInfo<TContext> {
|
|
|
48
48
|
* @param {Object} targetProvider
|
|
49
49
|
* @param {ContextConsumer} consumer object with a provide(context) function property.
|
|
50
50
|
*/
|
|
51
|
-
subscribeContext(targetProvider: object, consumer:
|
|
51
|
+
subscribeContext(targetProvider: object, consumer: LwcContextConsumer): void;
|
|
52
52
|
/**
|
|
53
53
|
* Unsubscribe a previously subscribed consumer from listening to changes on the
|
|
54
54
|
* target
|
|
55
55
|
* @param {Object} targetProvider
|
|
56
56
|
* @param {ContextConsumer} consumer
|
|
57
57
|
*/
|
|
58
|
-
unsubscribeContext(targetProvider: object, consumer:
|
|
58
|
+
unsubscribeContext(targetProvider: object, consumer: LwcContextConsumer): void;
|
|
59
59
|
}
|
|
60
60
|
//# sourceMappingURL=contextInfo.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextConsumer } from 'lwc';
|
|
1
|
+
import type { ContextConsumer, Contextualizer } from 'lwc';
|
|
2
2
|
import { ContextInfo } from './contextInfo';
|
|
3
3
|
export { ContextInfo };
|
|
4
4
|
export type { NavigationHelm } from './navigationApiStore';
|
|
@@ -17,8 +17,10 @@ export interface ContextualWireAdapter<TContext, TConfig, TEmit> {
|
|
|
17
17
|
setContext: (targetProvider: globalThis.EventTarget, contextValue: TContext) => void;
|
|
18
18
|
getContext: (targetProvider: globalThis.EventTarget) => TContext;
|
|
19
19
|
clearContext: (targetProvider: globalThis.EventTarget) => void;
|
|
20
|
-
subscribeContext: (targetProvider: globalThis.EventTarget, consumer:
|
|
21
|
-
unsubscribeContext: (targetProvider: globalThis.EventTarget, consumer:
|
|
20
|
+
subscribeContext: (targetProvider: globalThis.EventTarget, consumer: LwcContextConsumer) => void;
|
|
21
|
+
unsubscribeContext: (targetProvider: globalThis.EventTarget, consumer: LwcContextConsumer) => void;
|
|
22
22
|
}
|
|
23
23
|
export declare function generateContextualWireAdapter<TContext, TConfig = unknown, TEmit = TContext>(contextInstance: ContextInfo<TContext>): ContextualWireAdapter<TContext, TConfig, TEmit>;
|
|
24
|
+
export type LwcContextualizer = Contextualizer<Record<string, any>>;
|
|
25
|
+
export type LwcContextConsumer = ContextConsumer<Record<string, any>>;
|
|
24
26
|
//# sourceMappingURL=contextUtils.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="lwc" />
|
|
2
1
|
import type { ViewSet } from 'lwr/router';
|
|
3
2
|
import type { Constructable } from 'lwr/routerUtils';
|
|
4
3
|
type ViewContext = {
|
|
@@ -22,8 +21,8 @@ export declare const CurrentView: {
|
|
|
22
21
|
setContext: (targetProvider: EventTarget, contextValue: ViewContext) => void;
|
|
23
22
|
getContext: (targetProvider: EventTarget) => ViewContext;
|
|
24
23
|
clearContext: (targetProvider: EventTarget) => void;
|
|
25
|
-
subscribeContext: (targetProvider: EventTarget, consumer: import("
|
|
26
|
-
unsubscribeContext: (targetProvider: EventTarget, consumer: import("
|
|
24
|
+
subscribeContext: (targetProvider: EventTarget, consumer: import("lwr/contextUtils").LwcContextConsumer) => void;
|
|
25
|
+
unsubscribeContext: (targetProvider: EventTarget, consumer: import("lwr/contextUtils").LwcContextConsumer) => void;
|
|
27
26
|
};
|
|
28
27
|
export {};
|
|
29
28
|
//# sourceMappingURL=currentView.d.ts.map
|
|
@@ -31,7 +31,7 @@ export class HistoryRouter extends DomRouterImpl {
|
|
|
31
31
|
onpopstate() {
|
|
32
32
|
// Only the root should update the url since it has the full context
|
|
33
33
|
if (!this.parent && hasDocument) {
|
|
34
|
-
this.catchBrowserUpdate(getRelativeUrl(
|
|
34
|
+
this.catchBrowserUpdate(getRelativeUrl(window.location.href));
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
disconnect() {
|
|
@@ -99,7 +99,7 @@ class RouterImpl {
|
|
|
99
99
|
}
|
|
100
100
|
// retrieve the route handler and use it to get the RouteDestination
|
|
101
101
|
// handler ~= import('my/handlerModule');
|
|
102
|
-
return routingMatch.routeDefinition.handler().then((handlerModule) => {
|
|
102
|
+
return routingMatch.routeDefinition.handler?.().then((handlerModule) => {
|
|
103
103
|
// the route handler class is the module's default export
|
|
104
104
|
const routeHandlerClass = handlerModule.default;
|
|
105
105
|
if (!routeHandlerClass) {
|
|
@@ -161,8 +161,8 @@ class RouterImpl {
|
|
|
161
161
|
// set an id in case _mapView is called again.
|
|
162
162
|
const routeHandlerId = Math.random();
|
|
163
163
|
this.routeHandlerId = routeHandlerId;
|
|
164
|
-
const handlerModule = await routingMatch.routeDefinition.handler();
|
|
165
|
-
const routeHandlerClass = handlerModule
|
|
164
|
+
const handlerModule = await routingMatch.routeDefinition.handler?.();
|
|
165
|
+
const routeHandlerClass = handlerModule?.default;
|
|
166
166
|
if (!routeHandlerClass) {
|
|
167
167
|
throw new Error(generateMessage(messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id]));
|
|
168
168
|
}
|
|
@@ -30,7 +30,7 @@ export default class RouterContainer extends LightningElement {
|
|
|
30
30
|
historyDisabled: this.historyDisabled,
|
|
31
31
|
handleNavigation: this.handleNavigation.bind(this),
|
|
32
32
|
};
|
|
33
|
-
if (this.router) {
|
|
33
|
+
if (hasDocument && this.router) {
|
|
34
34
|
// Create the router.
|
|
35
35
|
this.routerApi = createNavigationContext(this, config, this.router);
|
|
36
36
|
// Convert hook APIs into DOM events.
|
|
@@ -150,5 +150,10 @@ export const messages = {
|
|
|
150
150
|
level: DiagnosticLevel.Error,
|
|
151
151
|
stack: '{2}',
|
|
152
152
|
},
|
|
153
|
+
NO_INIT_URL: {
|
|
154
|
+
code: `${ERROR_CODE_PREFIX}4030`,
|
|
155
|
+
message: 'Cannot initialize a server router without a "url"',
|
|
156
|
+
level: DiagnosticLevel.Error,
|
|
157
|
+
},
|
|
153
158
|
};
|
|
154
159
|
//# sourceMappingURL=routerErrors.js.map
|
|
@@ -43,7 +43,7 @@ export interface RouteDefinition<TMetadata = Record<string, any>> {
|
|
|
43
43
|
patterns?: RouteParameterPatterns;
|
|
44
44
|
exact?: boolean;
|
|
45
45
|
page: Partial<PageReference>;
|
|
46
|
-
handler
|
|
46
|
+
handler?: () => Promise<RouteHandlerModule>;
|
|
47
47
|
metadata?: TMetadata;
|
|
48
48
|
}
|
|
49
49
|
export type PageBindings = {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { RouteChange } from 'lwr/domRouterUtils';
|
|
2
|
+
import type { ContextId } from 'lwr/navigation';
|
|
3
|
+
import type { PageReference, Router, RouterConfig, RoutingMatch } from 'lwr/router';
|
|
4
|
+
import type { MessageObject } from 'lwr/routerUtils';
|
|
5
|
+
type PreNavFunction = (r: RouteChange) => Promise<boolean>;
|
|
6
|
+
type ErrorNavFunction = (m: MessageObject) => void;
|
|
7
|
+
type ServerRouterConfig = RouterConfig & {
|
|
8
|
+
url?: string;
|
|
9
|
+
preNavigate?: PreNavFunction;
|
|
10
|
+
errorNavigate?: ErrorNavFunction;
|
|
11
|
+
};
|
|
12
|
+
export declare class ServerRouter {
|
|
13
|
+
router: Router<PageReference | string>;
|
|
14
|
+
target: EventTarget;
|
|
15
|
+
contextId: ContextId;
|
|
16
|
+
preNavHook?: PreNavFunction;
|
|
17
|
+
errorNavHook?: ErrorNavFunction;
|
|
18
|
+
currentRoute: RoutingMatch | undefined;
|
|
19
|
+
constructor(config: ServerRouterConfig, router: Router<PageReference>, target: EventTarget);
|
|
20
|
+
/**
|
|
21
|
+
* lightning/navigation
|
|
22
|
+
* Perform a hard navigation to the given page reference
|
|
23
|
+
* Client only!
|
|
24
|
+
*/
|
|
25
|
+
navigate(address: PageReference): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* lightning/navigation
|
|
28
|
+
* Generate a URL based on the given page reference
|
|
29
|
+
*/
|
|
30
|
+
generateUrl(address: PageReference): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Initialize the CurrentPageReference & NavigationContext wires plus the client-only NavigationMixin
|
|
33
|
+
* On the server, use the URL from the config
|
|
34
|
+
* On the client, pull the URL from the current location
|
|
35
|
+
*/
|
|
36
|
+
private initWires;
|
|
37
|
+
/**
|
|
38
|
+
* Get a relative URL from a fully qualified one
|
|
39
|
+
* eg: "http://www.site.com/items/123abc?mode=dark" -> "/items/123abc?mode=dark"
|
|
40
|
+
*/
|
|
41
|
+
private getRelativeUrl;
|
|
42
|
+
/**
|
|
43
|
+
* Validate the page reference passed to the navigate API
|
|
44
|
+
*/
|
|
45
|
+
private getValidatedUrl;
|
|
46
|
+
/**
|
|
47
|
+
* Run the errorNavigate filters
|
|
48
|
+
*/
|
|
49
|
+
private processError;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create and initialize a new Server Router
|
|
53
|
+
* On the server, enable the CurrentPageReference & NavigationContext wires plus the generateUrl API
|
|
54
|
+
* On the client, do hard navigations and enable all "lightning/navigation" APIs for hydrated or CSR islands
|
|
55
|
+
* Note: This router does not implement subscribe() or the CurrentView wire
|
|
56
|
+
*/
|
|
57
|
+
export declare function createServerRouter(config: ServerRouterConfig, target: EventTarget): void;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=serverRouter.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { currentPageReferenceContextualizer, navigationContextContextualizer, provideContext, } from 'lwr/contextProvider'; // @ts-ignore - import from client-modules package
|
|
2
|
+
import { ROUTER_ERROR } from 'lwr/metrics';
|
|
3
|
+
import { CurrentPageReference, NavigationContext, registerNavigationHelm } from 'lwr/navigation';
|
|
4
|
+
import { CONTEXT_ID_BACKDOOR } from 'lwr/navigationMixinHacks'; // @ts-ignore - import from client-modules package
|
|
5
|
+
import { logOperationStart } from 'lwr/profiler';
|
|
6
|
+
import { createRouter } from 'lwr/router';
|
|
7
|
+
import { generateMessageObject, messages } from 'lwr/routerErrors';
|
|
8
|
+
import { hasDocument } from 'lwr/routerUtils';
|
|
9
|
+
export class ServerRouter {
|
|
10
|
+
constructor(config, router, target) {
|
|
11
|
+
this.contextId = Object.freeze(() => undefined);
|
|
12
|
+
this.router = router;
|
|
13
|
+
this.target = target;
|
|
14
|
+
this.preNavHook = config.preNavigate;
|
|
15
|
+
this.errorNavHook = config.errorNavigate;
|
|
16
|
+
this.initWires(config.url);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* lightning/navigation
|
|
20
|
+
* Perform a hard navigation to the given page reference
|
|
21
|
+
* Client only!
|
|
22
|
+
*/
|
|
23
|
+
async navigate(address) {
|
|
24
|
+
if (hasDocument) {
|
|
25
|
+
const url = await this.getValidatedUrl(address);
|
|
26
|
+
if (url) {
|
|
27
|
+
// hard navigation
|
|
28
|
+
document.location.href = url;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* lightning/navigation
|
|
34
|
+
* Generate a URL based on the given page reference
|
|
35
|
+
*/
|
|
36
|
+
generateUrl(address) {
|
|
37
|
+
return this.router.generateUrl(address);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Initialize the CurrentPageReference & NavigationContext wires plus the client-only NavigationMixin
|
|
41
|
+
* On the server, use the URL from the config
|
|
42
|
+
* On the client, pull the URL from the current location
|
|
43
|
+
*/
|
|
44
|
+
initWires(url) {
|
|
45
|
+
if (!url && hasDocument) {
|
|
46
|
+
// get the browser URL on the client
|
|
47
|
+
url = document.location.href;
|
|
48
|
+
}
|
|
49
|
+
/* istanbul ignore next */
|
|
50
|
+
if (!url) {
|
|
51
|
+
this.processError(generateMessageObject(messages.NO_INIT_URL));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
url = this.getRelativeUrl(url);
|
|
55
|
+
// ensure the initial URL matches a valid route definition
|
|
56
|
+
const routingMatch = this.router.matchRoute(url);
|
|
57
|
+
if (!routingMatch) {
|
|
58
|
+
this.processError(generateMessageObject(messages.MISSING_ROUTE, [url]));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.currentRoute = routingMatch;
|
|
62
|
+
// set up the navigation context APIs
|
|
63
|
+
registerNavigationHelm(this.contextId, {
|
|
64
|
+
navigate: (address) => this.navigate(address),
|
|
65
|
+
generateUrl: (address) => this.generateUrl(address),
|
|
66
|
+
// the JS context is lost during hard navigations, so subcribing to route changes will not work
|
|
67
|
+
subscribe: () => {
|
|
68
|
+
throw new Error('The server router does not support the subscribe API');
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
// provide initial context values to the navigation wires
|
|
72
|
+
provideContext(this.contextId, this.target, navigationContextContextualizer, NavigationContext);
|
|
73
|
+
provideContext(this.currentRoute?.route.pageReference, this.target, currentPageReferenceContextualizer, CurrentPageReference);
|
|
74
|
+
// used by NavigationMixin because it is very special * it can't use the @wires directly
|
|
75
|
+
if (hasDocument) {
|
|
76
|
+
this.target.addEventListener(CONTEXT_ID_BACKDOOR, (event) => {
|
|
77
|
+
const navCtxEvent = event;
|
|
78
|
+
if (navCtxEvent.detail.callback) {
|
|
79
|
+
navCtxEvent.detail.callback(this.contextId);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get a relative URL from a fully qualified one
|
|
86
|
+
* eg: "http://www.site.com/items/123abc?mode=dark" -> "/items/123abc?mode=dark"
|
|
87
|
+
*/
|
|
88
|
+
getRelativeUrl(url) {
|
|
89
|
+
// portable URL parsing
|
|
90
|
+
if (url.startsWith('http')) {
|
|
91
|
+
const parsed = new URL(url);
|
|
92
|
+
return `${parsed.pathname}${parsed.search}`;
|
|
93
|
+
}
|
|
94
|
+
return url;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Validate the page reference passed to the navigate API
|
|
98
|
+
*/
|
|
99
|
+
async getValidatedUrl(address) {
|
|
100
|
+
// match the URL to a route definition; fail if there is no match
|
|
101
|
+
const routingMatch = this.router.matchRoute(address);
|
|
102
|
+
if (!routingMatch) {
|
|
103
|
+
this.processError(generateMessageObject(messages.NO_ROUTE_MATCH, [JSON.stringify(address)]));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// execute the preNav hook; fail if it blocks the navigation event
|
|
107
|
+
const valid = this.preNavHook &&
|
|
108
|
+
(await this.preNavHook({
|
|
109
|
+
current: this.currentRoute,
|
|
110
|
+
next: routingMatch,
|
|
111
|
+
}));
|
|
112
|
+
if (!valid) {
|
|
113
|
+
this.processError(generateMessageObject(messages.PRENAV_FAILED, [JSON.stringify(address)]));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
return this.router.generateUrl(address);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Run the errorNavigate filters
|
|
120
|
+
*/
|
|
121
|
+
processError(messageObject) {
|
|
122
|
+
logOperationStart({ id: ROUTER_ERROR });
|
|
123
|
+
this.errorNavHook && this.errorNavHook(messageObject);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create and initialize a new Server Router
|
|
128
|
+
* On the server, enable the CurrentPageReference & NavigationContext wires plus the generateUrl API
|
|
129
|
+
* On the client, do hard navigations and enable all "lightning/navigation" APIs for hydrated or CSR islands
|
|
130
|
+
* Note: This router does not implement subscribe() or the CurrentView wire
|
|
131
|
+
*/
|
|
132
|
+
export function createServerRouter(config, target) {
|
|
133
|
+
new ServerRouter(config, createRouter(config), target);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=serverRouter.js.map
|
|
@@ -2,9 +2,9 @@ import { createContextProvider } from 'lwc';
|
|
|
2
2
|
import { hasDocument } from 'lwr/routerUtils';
|
|
3
3
|
import { CurrentPageReference, CurrentView, NavigationContext } from 'lwr/navigation';
|
|
4
4
|
// Creating a context with LWC requires eventing APIs, which are not available from "@lwc/engine-server"
|
|
5
|
-
export const currentPageReferenceContextualizer =
|
|
5
|
+
export const currentPageReferenceContextualizer = createContextProvider(CurrentPageReference);
|
|
6
6
|
export const currentViewContextualizer = hasDocument ? createContextProvider(CurrentView) : undefined;
|
|
7
|
-
export const navigationContextContextualizer =
|
|
7
|
+
export const navigationContextContextualizer = createContextProvider(NavigationContext);
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
@@ -15,7 +15,7 @@ export const navigationContextContextualizer = hasDocument ? createContextProvid
|
|
|
15
15
|
*/
|
|
16
16
|
export function provideContext(contextValue, providerNode, contextualizer, contextualAdapter) {
|
|
17
17
|
if (contextualizer && contextualAdapter) {
|
|
18
|
-
// Set up provider to give context to wire
|
|
18
|
+
// Set up provider to give context to wire adapters so that a component connected
|
|
19
19
|
// under the providerNode subtree and wired to those adapters will receive this id
|
|
20
20
|
contextualAdapter.setContext(providerNode, contextValue);
|
|
21
21
|
contextualizer(providerNode, {
|
|
@@ -86,4 +86,11 @@ export function generateContextualWireAdapter(contextInstance) {
|
|
|
86
86
|
};
|
|
87
87
|
};
|
|
88
88
|
return Adapter;
|
|
89
|
-
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Prior to LWC version 4.0.0, the types `Contextualizer` and `ContextConsumer` were not generic.
|
|
92
|
+
// Adding the ts-ignore in case this code is compiled with a version of LWC that is older than 4.0.
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
96
|
+
// @ts-ignore
|
|
@@ -32,7 +32,7 @@ export class HistoryRouter extends DomRouterImpl {
|
|
|
32
32
|
onpopstate() {
|
|
33
33
|
// Only the root should update the url since it has the full context
|
|
34
34
|
if (!this.parent && hasDocument) {
|
|
35
|
-
this.catchBrowserUpdate(getRelativeUrl(
|
|
35
|
+
this.catchBrowserUpdate(getRelativeUrl(window.location.href));
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
disconnect() {
|
|
@@ -113,7 +113,7 @@ class RouterImpl {
|
|
|
113
113
|
|
|
114
114
|
// retrieve the route handler and use it to get the RouteDestination
|
|
115
115
|
// handler ~= import('my/handlerModule');
|
|
116
|
-
return routingMatch.routeDefinition.handler().then(handlerModule => {
|
|
116
|
+
return routingMatch.routeDefinition.handler?.().then(handlerModule => {
|
|
117
117
|
// the route handler class is the module's default export
|
|
118
118
|
const routeHandlerClass = handlerModule.default;
|
|
119
119
|
if (!routeHandlerClass) {
|
|
@@ -183,8 +183,8 @@ class RouterImpl {
|
|
|
183
183
|
// set an id in case _mapView is called again.
|
|
184
184
|
const routeHandlerId = Math.random();
|
|
185
185
|
this.routeHandlerId = routeHandlerId;
|
|
186
|
-
const handlerModule = await routingMatch.routeDefinition.handler();
|
|
187
|
-
const routeHandlerClass = handlerModule
|
|
186
|
+
const handlerModule = await routingMatch.routeDefinition.handler?.();
|
|
187
|
+
const routeHandlerClass = handlerModule?.default;
|
|
188
188
|
if (!routeHandlerClass) {
|
|
189
189
|
throw new Error(generateMessage(messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id]));
|
|
190
190
|
}
|
|
@@ -33,7 +33,7 @@ export default class RouterContainer extends LightningElement {
|
|
|
33
33
|
historyDisabled: this.historyDisabled,
|
|
34
34
|
handleNavigation: this.handleNavigation.bind(this)
|
|
35
35
|
};
|
|
36
|
-
if (this.router) {
|
|
36
|
+
if (hasDocument && this.router) {
|
|
37
37
|
// Create the router.
|
|
38
38
|
this.routerApi = createNavigationContext(this, config, this.router);
|
|
39
39
|
|
|
@@ -155,5 +155,10 @@ export const messages = {
|
|
|
155
155
|
message: 'Route handler returned error status {0}: {1}',
|
|
156
156
|
level: DiagnosticLevel.Error,
|
|
157
157
|
stack: '{2}'
|
|
158
|
+
},
|
|
159
|
+
NO_INIT_URL: {
|
|
160
|
+
code: `${ERROR_CODE_PREFIX}4030`,
|
|
161
|
+
message: 'Cannot initialize a server router without a "url"',
|
|
162
|
+
level: DiagnosticLevel.Error
|
|
158
163
|
}
|
|
159
164
|
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
|
|
3
|
+
import { currentPageReferenceContextualizer, navigationContextContextualizer, provideContext } from 'lwr/contextProvider'; // @ts-ignore - import from client-modules package
|
|
4
|
+
import { ROUTER_ERROR } from 'lwr/metrics';
|
|
5
|
+
import { CurrentPageReference, NavigationContext, registerNavigationHelm } from 'lwr/navigation';
|
|
6
|
+
import { CONTEXT_ID_BACKDOOR } from 'lwr/navigationMixinHacks'; // @ts-ignore - import from client-modules package
|
|
7
|
+
import { logOperationStart } from 'lwr/profiler';
|
|
8
|
+
import { createRouter } from 'lwr/router';
|
|
9
|
+
import { generateMessageObject, messages } from 'lwr/routerErrors';
|
|
10
|
+
import { hasDocument } from 'lwr/routerUtils';
|
|
11
|
+
export class ServerRouter {
|
|
12
|
+
contextId = Object.freeze(() => undefined);
|
|
13
|
+
constructor(config, router, target) {
|
|
14
|
+
this.router = router;
|
|
15
|
+
this.target = target;
|
|
16
|
+
this.preNavHook = config.preNavigate;
|
|
17
|
+
this.errorNavHook = config.errorNavigate;
|
|
18
|
+
this.initWires(config.url);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* lightning/navigation
|
|
23
|
+
* Perform a hard navigation to the given page reference
|
|
24
|
+
* Client only!
|
|
25
|
+
*/
|
|
26
|
+
async navigate(address) {
|
|
27
|
+
if (hasDocument) {
|
|
28
|
+
const url = await this.getValidatedUrl(address);
|
|
29
|
+
if (url) {
|
|
30
|
+
// hard navigation
|
|
31
|
+
document.location.href = url;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* lightning/navigation
|
|
38
|
+
* Generate a URL based on the given page reference
|
|
39
|
+
*/
|
|
40
|
+
generateUrl(address) {
|
|
41
|
+
return this.router.generateUrl(address);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Initialize the CurrentPageReference & NavigationContext wires plus the client-only NavigationMixin
|
|
46
|
+
* On the server, use the URL from the config
|
|
47
|
+
* On the client, pull the URL from the current location
|
|
48
|
+
*/
|
|
49
|
+
initWires(url) {
|
|
50
|
+
if (!url && hasDocument) {
|
|
51
|
+
// get the browser URL on the client
|
|
52
|
+
url = document.location.href;
|
|
53
|
+
}
|
|
54
|
+
/* istanbul ignore next */
|
|
55
|
+
if (!url) {
|
|
56
|
+
this.processError(generateMessageObject(messages.NO_INIT_URL));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
url = this.getRelativeUrl(url);
|
|
60
|
+
|
|
61
|
+
// ensure the initial URL matches a valid route definition
|
|
62
|
+
const routingMatch = this.router.matchRoute(url);
|
|
63
|
+
if (!routingMatch) {
|
|
64
|
+
this.processError(generateMessageObject(messages.MISSING_ROUTE, [url]));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.currentRoute = routingMatch;
|
|
68
|
+
|
|
69
|
+
// set up the navigation context APIs
|
|
70
|
+
registerNavigationHelm(this.contextId, {
|
|
71
|
+
navigate: address => this.navigate(address),
|
|
72
|
+
generateUrl: address => this.generateUrl(address),
|
|
73
|
+
// the JS context is lost during hard navigations, so subcribing to route changes will not work
|
|
74
|
+
subscribe: () => {
|
|
75
|
+
throw new Error('The server router does not support the subscribe API');
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// provide initial context values to the navigation wires
|
|
80
|
+
provideContext(this.contextId, this.target, navigationContextContextualizer, NavigationContext);
|
|
81
|
+
provideContext(this.currentRoute?.route.pageReference, this.target, currentPageReferenceContextualizer, CurrentPageReference);
|
|
82
|
+
|
|
83
|
+
// used by NavigationMixin because it is very special * it can't use the @wires directly
|
|
84
|
+
if (hasDocument) {
|
|
85
|
+
this.target.addEventListener(CONTEXT_ID_BACKDOOR, event => {
|
|
86
|
+
const navCtxEvent = event;
|
|
87
|
+
if (navCtxEvent.detail.callback) {
|
|
88
|
+
navCtxEvent.detail.callback(this.contextId);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get a relative URL from a fully qualified one
|
|
96
|
+
* eg: "http://www.site.com/items/123abc?mode=dark" -> "/items/123abc?mode=dark"
|
|
97
|
+
*/
|
|
98
|
+
getRelativeUrl(url) {
|
|
99
|
+
// portable URL parsing
|
|
100
|
+
if (url.startsWith('http')) {
|
|
101
|
+
const parsed = new URL(url);
|
|
102
|
+
return `${parsed.pathname}${parsed.search}`;
|
|
103
|
+
}
|
|
104
|
+
return url;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Validate the page reference passed to the navigate API
|
|
109
|
+
*/
|
|
110
|
+
async getValidatedUrl(address) {
|
|
111
|
+
// match the URL to a route definition; fail if there is no match
|
|
112
|
+
const routingMatch = this.router.matchRoute(address);
|
|
113
|
+
if (!routingMatch) {
|
|
114
|
+
this.processError(generateMessageObject(messages.NO_ROUTE_MATCH, [JSON.stringify(address)]));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// execute the preNav hook; fail if it blocks the navigation event
|
|
119
|
+
const valid = this.preNavHook && (await this.preNavHook({
|
|
120
|
+
current: this.currentRoute,
|
|
121
|
+
next: routingMatch
|
|
122
|
+
}));
|
|
123
|
+
if (!valid) {
|
|
124
|
+
this.processError(generateMessageObject(messages.PRENAV_FAILED, [JSON.stringify(address)]));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
return this.router.generateUrl(address);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Run the errorNavigate filters
|
|
132
|
+
*/
|
|
133
|
+
processError(messageObject) {
|
|
134
|
+
logOperationStart({
|
|
135
|
+
id: ROUTER_ERROR
|
|
136
|
+
});
|
|
137
|
+
this.errorNavHook && this.errorNavHook(messageObject);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Create and initialize a new Server Router
|
|
143
|
+
* On the server, enable the CurrentPageReference & NavigationContext wires plus the generateUrl API
|
|
144
|
+
* On the client, do hard navigations and enable all "lightning/navigation" APIs for hydrated or CSR islands
|
|
145
|
+
* Note: This router does not implement subscribe() or the CurrentView wire
|
|
146
|
+
*/
|
|
147
|
+
export function createServerRouter(config, target) {
|
|
148
|
+
new ServerRouter(config, createRouter(config), target);
|
|
149
|
+
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.11.0
|
|
8
|
+
"version": "0.11.0",
|
|
9
9
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -53,21 +53,23 @@
|
|
|
53
53
|
"test:server": "jest --config ./jest.server.config.cjs"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@lwrjs/client-modules": "0.11.0
|
|
57
|
-
"@lwrjs/diagnostics": "0.11.0
|
|
58
|
-
"@lwrjs/shared-utils": "0.11.0
|
|
56
|
+
"@lwrjs/client-modules": "0.11.0",
|
|
57
|
+
"@lwrjs/diagnostics": "0.11.0",
|
|
58
|
+
"@lwrjs/shared-utils": "0.11.0",
|
|
59
59
|
"ajv": "6.12.6"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@lwc/jest-preset": "^14.1.0",
|
|
63
|
-
"@
|
|
63
|
+
"@lwrjs/fs-watch": "0.11.0",
|
|
64
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
64
65
|
"jest": "^26.6.3",
|
|
65
66
|
"rollup": "^2.78.0",
|
|
66
67
|
"ts-jest": "^26.5.6",
|
|
68
|
+
"typescript": "^4.9.5",
|
|
67
69
|
"utam": "2.2.0-alpha1"
|
|
68
70
|
},
|
|
69
71
|
"peerDependencies": {
|
|
70
|
-
"lwc": "2.x || 3.x"
|
|
72
|
+
"lwc": "2.x || 3.x || 4.x"
|
|
71
73
|
},
|
|
72
74
|
"lwc": {
|
|
73
75
|
"modules": [
|
|
@@ -86,7 +88,8 @@
|
|
|
86
88
|
"lwr/outlet",
|
|
87
89
|
"lwr/router",
|
|
88
90
|
"lwr/routerErrors",
|
|
89
|
-
"lwr/routerBridge"
|
|
91
|
+
"lwr/routerBridge",
|
|
92
|
+
"lwr/serverRouter"
|
|
90
93
|
]
|
|
91
94
|
},
|
|
92
95
|
"engines": {
|
|
@@ -95,5 +98,5 @@
|
|
|
95
98
|
"volta": {
|
|
96
99
|
"extends": "../../../package.json"
|
|
97
100
|
},
|
|
98
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "fbc883ea90a12672ce6f1adc2201144fda8762bd"
|
|
99
102
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ViewSet } from 'lwr/router';
|
|
2
|
-
import type { Constructable } from 'lwr/routerUtils';
|
|
3
|
-
type ViewContext = {
|
|
4
|
-
viewset: ViewSet;
|
|
5
|
-
onComplete?: Function;
|
|
6
|
-
} | undefined;
|
|
7
|
-
type CurrentViewConfig = {
|
|
8
|
-
viewName?: string;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Services @wire(CurrentView) requests.
|
|
12
|
-
* Hooks up to an Observable from the current navigation context.
|
|
13
|
-
*/
|
|
14
|
-
export declare const CurrentView: {
|
|
15
|
-
new (callback: (value: Constructable<object>) => void): {
|
|
16
|
-
update(config: CurrentViewConfig, context: ViewContext): Promise<void>;
|
|
17
|
-
_callback(value: Constructable<object>): void;
|
|
18
|
-
connect(): void;
|
|
19
|
-
disconnect(): void;
|
|
20
|
-
};
|
|
21
|
-
setContext: (targetProvider: EventTarget, contextValue: ViewContext) => void;
|
|
22
|
-
getContext: (targetProvider: EventTarget) => ViewContext;
|
|
23
|
-
clearContext: (targetProvider: EventTarget) => void;
|
|
24
|
-
subscribeContext: (targetProvider: EventTarget, consumer: import("lwc").ContextConsumer) => void;
|
|
25
|
-
unsubscribeContext: (targetProvider: EventTarget, consumer: import("lwc").ContextConsumer) => void;
|
|
26
|
-
};
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=currentView.d.ts.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ViewSet } from 'lwr/router';
|
|
2
|
-
import type { Constructable } from 'lwr/routerUtils';
|
|
3
|
-
type ViewContext = {
|
|
4
|
-
viewset: ViewSet;
|
|
5
|
-
onComplete?: Function;
|
|
6
|
-
} | undefined;
|
|
7
|
-
type CurrentViewConfig = {
|
|
8
|
-
viewName?: string;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Services @wire(CurrentView) requests.
|
|
12
|
-
* Hooks up to an Observable from the current navigation context.
|
|
13
|
-
*/
|
|
14
|
-
export declare const CurrentView: {
|
|
15
|
-
new (callback: (value: Constructable<object>) => void): {
|
|
16
|
-
update(config: CurrentViewConfig, context: ViewContext): Promise<void>;
|
|
17
|
-
_callback(value: Constructable<object>): void;
|
|
18
|
-
connect(): void;
|
|
19
|
-
disconnect(): void;
|
|
20
|
-
};
|
|
21
|
-
setContext: (targetProvider: EventTarget, contextValue: ViewContext) => void;
|
|
22
|
-
getContext: (targetProvider: EventTarget) => ViewContext;
|
|
23
|
-
clearContext: (targetProvider: EventTarget) => void;
|
|
24
|
-
subscribeContext: (targetProvider: EventTarget, consumer: import("lwc").ContextConsumer) => void;
|
|
25
|
-
unsubscribeContext: (targetProvider: EventTarget, consumer: import("lwc").ContextConsumer) => void;
|
|
26
|
-
};
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=currentView.d.ts.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ViewSet } from 'lwr/router';
|
|
2
|
-
import type { Constructable } from 'lwr/routerUtils';
|
|
3
|
-
type ViewContext = {
|
|
4
|
-
viewset: ViewSet;
|
|
5
|
-
onComplete?: Function;
|
|
6
|
-
} | undefined;
|
|
7
|
-
type CurrentViewConfig = {
|
|
8
|
-
viewName?: string;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Services @wire(CurrentView) requests.
|
|
12
|
-
* Hooks up to an Observable from the current navigation context.
|
|
13
|
-
*/
|
|
14
|
-
export declare const CurrentView: {
|
|
15
|
-
new (callback: (value: Constructable<object>) => void): {
|
|
16
|
-
update(config: CurrentViewConfig, context: ViewContext): Promise<void>;
|
|
17
|
-
_callback(value: Constructable<object>): void;
|
|
18
|
-
connect(): void;
|
|
19
|
-
disconnect(): void;
|
|
20
|
-
};
|
|
21
|
-
setContext: (targetProvider: EventTarget, contextValue: ViewContext) => void;
|
|
22
|
-
getContext: (targetProvider: EventTarget) => ViewContext;
|
|
23
|
-
clearContext: (targetProvider: EventTarget) => void;
|
|
24
|
-
subscribeContext: (targetProvider: EventTarget, consumer: import("lwc").ContextConsumer) => void;
|
|
25
|
-
unsubscribeContext: (targetProvider: EventTarget, consumer: import("lwc").ContextConsumer) => void;
|
|
26
|
-
};
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=currentView.d.ts.map
|