single-spa
Advanced tools
Comparing version 5.3.1 to 5.3.2
@@ -1,2 +0,2 @@ | ||
/* single-spa@5.3.1 - ESM - dev */ | ||
/* single-spa@5.3.2 - ESM - dev */ | ||
var singleSpa = /*#__PURE__*/Object.freeze({ | ||
@@ -1293,3 +1293,3 @@ __proto__: null, | ||
let wasNoOp = true; | ||
const appsThatChanged = []; | ||
@@ -1303,10 +1303,10 @@ if (isStarted()) { | ||
function addChangedApps(apps) { | ||
appsThatChanged.push(...apps); | ||
return apps; | ||
} | ||
function loadApps() { | ||
return Promise.resolve().then(() => { | ||
const loadPromises = getAppsToLoad().map(toLoadPromise); | ||
if (loadPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
const loadPromises = addChangedApps(getAppsToLoad()).map(toLoadPromise); | ||
return Promise.all(loadPromises).then(callAllEventListeners) // there are no mounted apps, before start() is called, so we always return [] | ||
@@ -1323,12 +1323,7 @@ .then(() => []).catch(err => { | ||
window.dispatchEvent(new customEvent("single-spa:before-routing-event", getCustomEventDetail())); | ||
const unloadPromises = getAppsToUnload().map(toUnloadPromise); | ||
const unmountUnloadPromises = getAppsToUnmount().map(toUnmountPromise).map(unmountPromise => unmountPromise.then(toUnloadPromise)); | ||
const unloadPromises = addChangedApps(getAppsToUnload()).map(toUnloadPromise); | ||
const unmountUnloadPromises = addChangedApps(getAppsToUnmount()).map(toUnmountPromise).map(unmountPromise => unmountPromise.then(toUnloadPromise)); | ||
const allUnmountPromises = unmountUnloadPromises.concat(unloadPromises); | ||
if (allUnmountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
const unmountAllPromise = Promise.all(allUnmountPromises); | ||
const appsToLoad = getAppsToLoad(); | ||
const appsToLoad = addChangedApps(getAppsToLoad()); | ||
/* We load and bootstrap apps while other apps are unmounting, but we | ||
@@ -1343,6 +1338,2 @@ * wait to mount the app until all apps are finishing unmounting | ||
}); | ||
if (loadThenMountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
/* These are the apps that are already bootstrapped and just need | ||
@@ -1353,11 +1344,6 @@ * to be mounted. They each wait for all unmounting apps to finish up | ||
const mountPromises = getAppsToMount().filter(appToMount => appsToLoad.indexOf(appToMount) < 0).map(appToMount => { | ||
appsThatChanged.push(appToMount); | ||
return toBootstrapPromise(appToMount).then(() => unmountAllPromise).then(() => toMountPromise(appToMount)); | ||
}); | ||
if (mountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
return unmountAllPromise.catch(err => { | ||
@@ -1385,3 +1371,3 @@ callAllEventListeners(); | ||
try { | ||
const appChangeEventName = wasNoOp ? "single-spa:no-app-change" : "single-spa:app-change"; | ||
const appChangeEventName = appsThatChanged.length === 0 ? "single-spa:no-app-change" : "single-spa:app-change"; | ||
window.dispatchEvent(new customEvent(appChangeEventName, getCustomEventDetail())); | ||
@@ -1434,11 +1420,28 @@ window.dispatchEvent(new customEvent("single-spa:routing-event", getCustomEventDetail())); | ||
function getCustomEventDetail() { | ||
const result = { | ||
detail: {} | ||
const newAppStatuses = {}; | ||
const appsByNewStatus = { | ||
// for apps that were mounted | ||
[MOUNTED]: [], | ||
// for apps that were unmounted | ||
[NOT_MOUNTED]: [], | ||
// apps that were forcibly unloaded | ||
[NOT_LOADED]: [], | ||
// apps that attempted to do something but are broken now | ||
[SKIP_BECAUSE_BROKEN]: [] | ||
}; | ||
if (eventArguments && eventArguments[0]) { | ||
result.detail.originalEvent = eventArguments[0]; | ||
} | ||
return result; | ||
appsThatChanged.forEach(app => { | ||
const appName = toName(app); | ||
const status = getAppStatus(appName); | ||
newAppStatuses[appName] = status; | ||
const statusArr = appsByNewStatus[status] = appsByNewStatus[status] || []; | ||
statusArr.push(appName); | ||
}); | ||
return { | ||
detail: { | ||
newAppStatuses, | ||
appsByNewStatus, | ||
totalAppChanges: appsThatChanged.length, | ||
originalEvent: eventArguments === null || eventArguments === void 0 ? void 0 : eventArguments[0] | ||
} | ||
}; | ||
} | ||
@@ -1445,0 +1448,0 @@ } |
@@ -1,3 +0,3 @@ | ||
/* single-spa@5.3.1 - ESM - prod */ | ||
var t=Object.freeze({__proto__:null,get start(){return Ut},get ensureJQuerySupport(){return pt},get setBootstrapMaxTime(){return V},get setMountMaxTime(){return q},get setUnmountMaxTime(){return z},get setUnloadMaxTime(){return X},get registerApplication(){return Ot},get getMountedApps(){return yt},get getAppStatus(){return Pt},get unloadApplication(){return At},get checkActivityFunctions(){return Tt},get getAppNames(){return vt},get navigateToUrl(){return ot},get triggerAppChange(){return Dt},get addErrorHandler(){return i},get removeErrorHandler(){return s},get mountRootParcel(){return K},get NOT_LOADED(){return c},get LOADING_SOURCE_CODE(){return l},get NOT_BOOTSTRAPPED(){return f},get BOOTSTRAPPING(){return p},get NOT_MOUNTED(){return h},get MOUNTING(){return m},get UPDATING(){return w},get LOAD_ERROR(){return E},get MOUNTED(){return d},get UNMOUNTING(){return g},get SKIP_BECAUSE_BROKEN(){return y}}),e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{}).CustomEvent,n=function(){try{var t=new e("cat",{detail:{foo:"bar"}});return"cat"===t.type&&"bar"===t.detail.foo}catch(t){}return!1}()?e:"undefined"!=typeof document&&"function"==typeof document.createEvent?function(t,e){var n=document.createEvent("CustomEvent");return e?n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail):n.initCustomEvent(t,!1,!1,void 0),n}:function(t,e){var n=document.createEventObject();return n.type=t,e?(n.bubbles=Boolean(e.bubbles),n.cancelable=Boolean(e.cancelable),n.detail=e.detail):(n.bubbles=!1,n.cancelable=!1,n.detail=void 0),n};let r=[];function o(t,e,n){const o=a(t,e,n);r.length?r.forEach(t=>t(o)):setTimeout(()=>{throw o})}function i(t){if("function"!=typeof t)throw Error(u(28,!1));r.push(t)}function s(t){if("function"!=typeof t)throw Error(u(29,!1));let e=!1;return r=r.filter(n=>{const r=n===t;return e=e||r,!r}),e}function u(t,e,...n){return`single-spa minified message #${t}: ${e?e+" ":""}See https://single-spa.js.org/error/?code=${t}${n.length?`&arg=${n.join("&arg=")}`:""}`}function a(t,e,n){const r=`${j(e)} '${S(e)}' died in status ${e.status}: `;let o;if(t instanceof Error){try{t.message=r+t.message}catch(t){}o=t}else{console.warn(u(30,!1,e.status,S(e)));try{o=Error(r+JSON.stringify(t))}catch(e){o=t}}return o.appOrParcelName=S(e),e.status=n,o}const c="NOT_LOADED",l="LOADING_SOURCE_CODE",f="NOT_BOOTSTRAPPED",p="BOOTSTRAPPING",h="NOT_MOUNTED",m="MOUNTING",d="MOUNTED",w="UPDATING",g="UNMOUNTING",E="LOAD_ERROR",y="SKIP_BECAUSE_BROKEN";function v(t){return t.status===d}function P(t){return!v(t)}function O(t){return t.status!==c&&t.status!==l&&t.status!==E}function T(t){return!O(t)}function b(t){try{return t.activeWhen(window.location)}catch(e){o(e,t,y)}}function A(t){try{return!b(t)}catch(e){o(e,t,y)}}function N(t){return t!==y&&(!t||t.status!==y)}function _(t){return t.status!==E||(new Date).getTime()-t.loadErrorTime>=200}function S(t){return t.name}function D(t){return Boolean(t.unmountThisParcel)}function j(t){return D(t)?"parcel":"application"}function M(){for(let t=arguments.length-1;t>0;t--)for(let e in arguments[t])"__proto__"!==e&&(arguments[t-1][e]=arguments[t][e]);return arguments[0]}function U(t,e){for(let n=0;n<t.length;n++)if(e(t[n]))return t[n];return null}function L(t){return t&&("function"==typeof t||(e=t,Array.isArray(e)&&!U(e,t=>"function"!=typeof t)));var e}function R(t,e){let n=t[e]||[];n=Array.isArray(n)?n:[n],0===n.length&&(n=[()=>Promise.resolve()]);const r=j(t),o=S(t);return function(t){return n.reduce((n,i,s)=>n.then(()=>{const n=i(t);return I(n)?n:Promise.reject(u(15,!1,r,o,e,s))}),Promise.resolve())}}function I(t){return t&&"function"==typeof t.then&&"function"==typeof t.catch}function x(t,e){return Promise.resolve().then(()=>t.status!==f?t:(t.status=p,Y(t,"bootstrap").then(()=>(t.status=h,t)).catch(n=>{if(e)throw a(n,t,y);return o(n,t,y),t})))}function $(t,e){return Promise.resolve().then(()=>{if(t.status!==d)return t;t.status=g;const n=Object.keys(t.parcels).map(e=>t.parcels[e].unmountThisParcel());return Promise.all(n).then(r,n=>r().then(()=>{const r=Error(n.message);if(e)throw a(r,t,y);o(r,t,y)})).then(()=>t);function r(){return Y(t,"unmount").then(()=>{t.status=h}).catch(n=>{if(e)throw a(n,t,y);o(n,t,y)})}})}let G=!1,B=!1;function W(t,e){return Promise.resolve().then(()=>t.status!==h?t:(G||(window.dispatchEvent(new n("single-spa:before-first-mount")),G=!0),Y(t,"mount").then(()=>(t.status=d,B||(window.dispatchEvent(new n("single-spa:first-mount")),B=!0),t)).catch(n=>{return t.status=d,$(t,!0).then(r,r);function r(){if(e)throw a(n,t,y);return o(n,t,y),t}})))}let C=0;const k={parcels:{}};function K(){return F.apply(k,arguments)}function F(t,e){const n=this;if(!t||"object"!=typeof t&&"function"!=typeof t)throw Error(u(2,!1));if(t.name&&"string"!=typeof t.name)throw Error(u(3,!1,typeof t.name));if("object"!=typeof e)throw Error(u(4,!1,name,typeof e));if(!e.domElement)throw Error(u(5,!1,name));const r=C++,o="function"==typeof t,i=o?t:()=>Promise.resolve(t),s={id:r,parcels:{},status:o?l:f,customProps:e,parentName:S(n),unmountThisParcel(){if(s.status!==d)throw Error(u(6,!1,name,s.status));return $(s,!0).then(t=>(s.parentName&&delete n.parcels[s.id],t)).then(t=>(E(t),t)).catch(t=>{throw s.status=y,v(t),t})}};let c;n.parcels[r]=s;let p=i();if(!p||"function"!=typeof p.then)throw Error(u(7,!1));p=p.then(t=>{if(!t)throw Error(u(8,!1));const e=t.name||`parcel-${r}`;if(!L(t.bootstrap))throw Error(u(9,!1,e));if(!L(t.mount))throw Error(u(10,!1,e));if(!L(t.unmount))throw Error(u(11,!1,e));if(t.update&&!L(t.update))throw Error(u(12,!1,e));const n=R(t,"bootstrap"),o=R(t,"mount"),i=R(t,"unmount");s.status=f,s.name=e,s.bootstrap=n,s.mount=o,s.unmount=i,s.timeouts=Z(t.timeouts),t.update&&(s.update=R(t,"update"),c.update=function(t){return s.customProps=t,J(function(t){return Promise.resolve().then(()=>{if(t.status!==d)throw Error(u(32,!1,S(t)));return t.status=w,Y(t,"update").then(()=>(t.status=d,t)).catch(e=>{throw a(e,t,y)})})}(s))})});const m=p.then(()=>x(s,!0)),g=m.then(()=>W(s,!0));let E,v;const P=new Promise((t,e)=>{E=t,v=e});return c={mount:()=>J(Promise.resolve().then(()=>{if(s.status!==h)throw Error(u(13,!1,name,s.status));return n.parcels[r]=s,W(s)})),unmount:()=>J(s.unmountThisParcel()),getStatus:()=>s.status,loadPromise:J(p),bootstrapPromise:J(m),mountPromise:J(g),unmountPromise:J(P)},c}function J(t){return t.then(()=>null)}function H(e){const n=M({},e.customProps,{name:S(e),mountParcel:F.bind(e),singleSpa:t});return D(e)&&(n.unmountSelf=e.unmountThisParcel),n}const Q={bootstrap:{millis:4e3,dieOnTimeout:!1,warningMillis:1e3},mount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unmount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unload:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},update:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3}};function V(t,e,n){if("number"!=typeof t||t<=0)throw Error(u(16,!1));Q.bootstrap={millis:t,dieOnTimeout:e,warningMillis:n||1e3}}function q(t,e,n){if("number"!=typeof t||t<=0)throw Error(u(17,!1));Q.mount={millis:t,dieOnTimeout:e,warningMillis:n||1e3}}function z(t,e,n){if("number"!=typeof t||t<=0)throw Error(u(18,!1));Q.unmount={millis:t,dieOnTimeout:e,warningMillis:n||1e3}}function X(t,e,n){if("number"!=typeof t||t<=0)throw Error(u(19,!1));Q.unload={millis:t,dieOnTimeout:e,warningMillis:n||1e3}}function Y(t,e){const n=t.timeouts[e],r=n.warningMillis,o=j(t);return new Promise((i,s)=>{let a=!1,c=!1;t[e](H(t)).then(t=>{a=!0,i(t)}).catch(t=>{a=!0,s(t)}),setTimeout(()=>f(1),r),setTimeout(()=>f(!0),n.millis);const l=u(31,!1,e,o,S(t),n.millis);function f(t){if(!a)if(!0===t)c=!0,n.dieOnTimeout?s(Error(l)):console.error(l);else if(!c){const e=t,o=e*r;console.warn(l),o+r<n.millis&&setTimeout(()=>f(e+1),r)}}})}function Z(t){const e={};for(let n in Q)e[n]=M({},Q[n],t&&t[n]||{});return e}function tt(t){return Promise.resolve().then(()=>{if(t.loadPromise)return t.loadPromise;if(t.status!==c&&t.status!==E)return t;let e,n;return t.status=l,t.loadPromise=Promise.resolve().then(()=>{const r=t.loadApp(H(t));if(!I(r))throw n=!0,Error(u(33,!1,S(t)));return r.then(n=>{let r;t.loadErrorTime=null,e=n,"object"!=typeof e&&(r=34),L(e.bootstrap)||(r=35),L(e.mount)||(r=36),L(e.unmount)||(r=37);const i=j(e);if(r){let n;try{n=JSON.stringify(e)}catch(t){}return console.error(u(r,!1,i,S(t),n),e),o(void 0,t,y),t}return e.devtools&&e.devtools.overlays&&(t.devtools.overlays=M({},t.devtools.overlays,e.devtools.overlays)),t.status=f,t.bootstrap=R(e,"bootstrap"),t.mount=R(e,"mount"),t.unmount=R(e,"unmount"),t.unload=R(e,"unload"),t.timeouts=Z(e.timeouts),delete t.loadPromise,t})}).catch(e=>{let r;return delete t.loadPromise,n?r=y:(r=E,t.loadErrorTime=(new Date).getTime()),o(e,t,r),t})})}const et="undefined"!=typeof window,nt={hashchange:[],popstate:[]},rt=["hashchange","popstate"];function ot(t){let e;if("string"==typeof t)e=t;else if(this&&this.href)e=this.href;else{if(!(t&&t.currentTarget&&t.currentTarget.href&&t.preventDefault))throw Error(u(14,!1));e=t.currentTarget.href,t.preventDefault()}const n=lt(window.location.href),r=lt(e);0===e.indexOf("#")?window.location.hash=r.hash:n.host!==r.host&&r.host?window.location.href=e:r.pathname===n.pathname&&r.search===n.pathname?window.location.hash=r.hash:window.history.pushState(null,null,e)}function it(t){if(t){const e=t[0].type;rt.indexOf(e)>=0&&nt[e].forEach(e=>{try{e.apply(this,t)}catch(t){setTimeout(()=>{throw t})}})}}let st;function ut(){jt([],arguments)}if(et){window.addEventListener("hashchange",ut),window.addEventListener("popstate",ut);const t=window.addEventListener,e=window.removeEventListener;function at(t){return function(){const e=window.location.href,n=t.apply(this,arguments),r=window.location.href;return st&&e===r||ut(ct(window.history.state)),n}}function ct(t){try{return new PopStateEvent("popstate",{state:t})}catch(e){const n=document.createEvent("PopStateEvent");return n.initPopStateEvent("popstate",!1,!1,t),n}}window.addEventListener=function(e,n){if(!("function"==typeof n&&rt.indexOf(e)>=0)||U(nt[e],t=>t===n))return t.apply(this,arguments);nt[e].push(n)},window.removeEventListener=function(t,n){if(!("function"==typeof n&&rt.indexOf(t)>=0))return e.apply(this,arguments);nt[t]=nt[t].filter(t=>t!==n)},window.history.pushState=at(window.history.pushState),window.history.replaceState=at(window.history.replaceState),window.singleSpaNavigate=ot}function lt(t){const e=document.createElement("a");return e.href=t,e}let ft=!1;function pt(t=window.jQuery){if(t||window.$&&window.$.fn&&window.$.fn.jquery&&(t=window.$),t&&!ft){const e=t.fn.on,n=t.fn.off;t.fn.on=function(t,n){return ht.call(this,e,window.addEventListener,t,n,arguments)},t.fn.off=function(t,e){return ht.call(this,n,window.removeEventListener,t,e,arguments)},ft=!0}}function ht(t,e,n,r,o){return"string"!=typeof n?t.apply(this,o):(n.split(/\s+/).forEach(t=>{rt.indexOf(t)>=0&&(e(t,r),n=n.replace(t,""))}),""===n.trim()?this:t.apply(this,o))}const mt={};function dt(t){return Promise.resolve().then(()=>{const e=mt[S(t)];return e?t.status===c?(wt(t,e),t):"UNLOADING"===t.status?e.promise.then(()=>t):t.status!==h?t:(t.status="UNLOADING",Y(t,"unload").then(()=>(wt(t,e),t)).catch(n=>(function(t,e,n){delete mt[S(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,o(n,t,y),e.reject(n)}(t,e,n),t))):t})}function wt(t,e){delete mt[S(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,t.status=c,e.resolve()}function gt(t,e,n,r){mt[S(t)]={app:t,resolve:n,reject:r},Object.defineProperty(mt[S(t)],"promise",{get:e})}const Et=[];function yt(){return Et.filter(v).map(S)}function vt(){return Et.map(S)}function Pt(t){const e=U(Et,e=>S(e)===t);return e?e.status:null}function Ot(t,e,n,r){const o=function(t,e,n,r){const o={name:null,loadApp:null,activeWhen:null,customProps:null};return"object"==typeof t?(function(t){if(Array.isArray(t)||null===t)throw Error(u(39,!1));const e=["name","app","activeWhen","customProps"],n=Object.keys(t).reduce((t,n)=>e.includes(n)?t:t.concat(n),[]);if(0!==n.length)throw Error(u(38,!1,e.join(", "),n.join(", ")));if("string"!=typeof t.name||0===t.name.length)throw Error(u(20,!1));if("object"!=typeof t.app&&"function"!=typeof t.app)throw Error(u(20,!1));const r=t=>"string"==typeof t||"function"==typeof t;if(!(r(t.activeWhen)||Array.isArray(t.activeWhen)&&t.activeWhen.every(r)))throw Error(u(24,!1));if(t.customProps&&("object"!=typeof t.customProps||Array.isArray(t.customProps)))throw Error(u(22,!1))}(t),o.name=t.name,o.loadApp=t.app,o.activeWhen=t.activeWhen,o.customProps=t.customProps):(function(t,e,n,r){if("string"!=typeof t||0===t.length)throw Error(u(20,!1));if(!e)throw Error(u(23,!1));if("function"!=typeof n)throw Error(u(24,!1));if(r&&("object"!=typeof r||Array.isArray(r)))throw Error(u(22,!1))}(t,e,n,r),o.name=t,o.loadApp=e,o.activeWhen=n,o.customProps=r),o.loadApp="function"!=typeof(i=o.loadApp)?()=>Promise.resolve(i):i,o.customProps=function(t){return t||{}}(o.customProps),o.activeWhen=function(t){let e=Array.isArray(t)?t:[t];return e=e.map(t=>"function"==typeof t?t:function(t){const e=function(t){let e=0,n=!1,r="^";for(let e=0;e<t.length;e++){const r=t[e],i=n&&"/"===r;(!n&&":"===r||i)&&o(e)}return o(t.length),new RegExp(r,"i");function o(o){const i=t.slice(e,o).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&");r+=n?"[^/]+/?":i,n=!n,e=o}}(t);return t=>{const n=t.href.replace(t.origin,"");return e.test(n)}}(t)),t=>e.some(e=>e(t))}(o.activeWhen),o;var i}(t,e,n,r);if(-1!==vt().indexOf(o.name))throw Error(u(21,!1,o.name));Et.push(M({loadErrorTime:null,status:c,parcels:{},devtools:{overlays:{options:{},selectors:[]}}},o)),et&&(pt(),jt())}function Tt(t){return Et.filter(e=>e.activeWhen(t)).map(S)}function bt(){return Et.filter(N).filter(_).filter(T).filter(b)}function At(t,e={waitForUnmount:!1}){if("string"!=typeof t)throw Error(u(26,!1));const n=U(Et,e=>S(e)===t);if(!n)throw Error(u(27,!1,t));const r=function(t){return mt[t]}(S(n));if(e&&e.waitForUnmount){if(r)return r.promise;{const t=new Promise((e,r)=>{gt(n,()=>t,e,r)});return t}}{let t;return r?(t=r.promise,Nt(n,r.resolve,r.reject)):t=new Promise((e,r)=>{gt(n,()=>t,e,r),Nt(n,e,r)}),t}}function Nt(t,e,n){$(t).then(dt).then(()=>{e(),setTimeout(()=>{jt()})}).catch(n)}let _t=!1,St=[];function Dt(){return jt()}function jt(t=[],e){if(_t)return new Promise((t,n)=>{St.push({resolve:t,reject:n,eventArguments:e})});let r=!0;return Mt?(_t=!0,Promise.resolve().then(()=>{window.dispatchEvent(new n("single-spa:before-routing-event",s()));const e=Object.keys(mt).map(t=>mt[t].app).filter(P).map(dt),u=Et.filter(N).filter(v).filter(A).map($).map(t=>t.then(dt)).concat(e);u.length>0&&(r=!1);const a=Promise.all(u),c=bt(),l=c.map(t=>tt(t).then(x).then(t=>a.then(()=>W(t))));l.length>0&&(r=!1);const f=Et.filter(N).filter(P).filter(O).filter(b).filter(t=>c.indexOf(t)<0).map(t=>x(t).then(()=>a).then(()=>W(t)));return f.length>0&&(r=!1),a.catch(t=>{throw i(),t}).then(()=>(i(),Promise.all(l.concat(f)).catch(e=>{throw t.forEach(t=>t.reject(e)),e}).then(o)))})):Promise.resolve().then(()=>{const t=bt().map(tt);return t.length>0&&(r=!1),Promise.all(t).then(i).then(()=>[]).catch(t=>{throw i(),t})});function o(){const e=yt();t.forEach(t=>t.resolve(e));try{const t=r?"single-spa:no-app-change":"single-spa:app-change";window.dispatchEvent(new n(t,s())),window.dispatchEvent(new n("single-spa:routing-event",s()))}catch(t){setTimeout(()=>{throw t})}if(_t=!1,St.length>0){const t=St;St=[],jt(t)}return e}function i(){t.forEach(t=>{it(t.eventArguments)}),it(e)}function s(){const t={detail:{}};return e&&e[0]&&(t.detail.originalEvent=e[0]),t}}let Mt=!1;function Ut(t){var e;Mt=!0,t&&t.urlRerouteOnly&&(e=t.urlRerouteOnly,st=e),et&&jt()}et&&setTimeout(()=>{Mt||console.warn(u(1,!1))},5e3);var Lt={getRawAppData:function(){return[...Et]},reroute:jt,NOT_LOADED:c,toLoadPromise:tt,toBootstrapPromise:x,unregisterApplication:function(t){if(!Et.find(e=>S(e)===t))throw Error(u(25,!1,t));return At(t).then(()=>{const e=Et.findIndex(e=>S(e)===t);Et.splice(e,1)})}};et&&window.__SINGLE_SPA_DEVTOOLS__&&(window.__SINGLE_SPA_DEVTOOLS__.exposedMethods=Lt);export{p as BOOTSTRAPPING,l as LOADING_SOURCE_CODE,E as LOAD_ERROR,d as MOUNTED,m as MOUNTING,f as NOT_BOOTSTRAPPED,c as NOT_LOADED,h as NOT_MOUNTED,y as SKIP_BECAUSE_BROKEN,g as UNMOUNTING,w as UPDATING,i as addErrorHandler,Tt as checkActivityFunctions,pt as ensureJQuerySupport,vt as getAppNames,Pt as getAppStatus,yt as getMountedApps,K as mountRootParcel,ot as navigateToUrl,Ot as registerApplication,s as removeErrorHandler,V as setBootstrapMaxTime,q as setMountMaxTime,X as setUnloadMaxTime,z as setUnmountMaxTime,Ut as start,Dt as triggerAppChange,At as unloadApplication}; | ||
/* single-spa@5.3.2 - ESM - prod */ | ||
var t=Object.freeze({__proto__:null,get start(){return Ut},get ensureJQuerySupport(){return pt},get setBootstrapMaxTime(){return V},get setMountMaxTime(){return q},get setUnmountMaxTime(){return z},get setUnloadMaxTime(){return X},get registerApplication(){return Ot},get getMountedApps(){return yt},get getAppStatus(){return Pt},get unloadApplication(){return At},get checkActivityFunctions(){return Tt},get getAppNames(){return vt},get navigateToUrl(){return ot},get triggerAppChange(){return Dt},get addErrorHandler(){return i},get removeErrorHandler(){return s},get mountRootParcel(){return K},get NOT_LOADED(){return c},get LOADING_SOURCE_CODE(){return l},get NOT_BOOTSTRAPPED(){return f},get BOOTSTRAPPING(){return p},get NOT_MOUNTED(){return h},get MOUNTING(){return m},get UPDATING(){return w},get LOAD_ERROR(){return E},get MOUNTED(){return d},get UNMOUNTING(){return g},get SKIP_BECAUSE_BROKEN(){return y}}),e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{}).CustomEvent,n=function(){try{var t=new e("cat",{detail:{foo:"bar"}});return"cat"===t.type&&"bar"===t.detail.foo}catch(t){}return!1}()?e:"undefined"!=typeof document&&"function"==typeof document.createEvent?function(t,e){var n=document.createEvent("CustomEvent");return e?n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail):n.initCustomEvent(t,!1,!1,void 0),n}:function(t,e){var n=document.createEventObject();return n.type=t,e?(n.bubbles=Boolean(e.bubbles),n.cancelable=Boolean(e.cancelable),n.detail=e.detail):(n.bubbles=!1,n.cancelable=!1,n.detail=void 0),n};let r=[];function o(t,e,n){const o=a(t,e,n);r.length?r.forEach(t=>t(o)):setTimeout(()=>{throw o})}function i(t){if("function"!=typeof t)throw Error(u(28,!1));r.push(t)}function s(t){if("function"!=typeof t)throw Error(u(29,!1));let e=!1;return r=r.filter(n=>{const r=n===t;return e=e||r,!r}),e}function u(t,e,...n){return`single-spa minified message #${t}: ${e?e+" ":""}See https://single-spa.js.org/error/?code=${t}${n.length?`&arg=${n.join("&arg=")}`:""}`}function a(t,e,n){const r=`${j(e)} '${S(e)}' died in status ${e.status}: `;let o;if(t instanceof Error){try{t.message=r+t.message}catch(t){}o=t}else{console.warn(u(30,!1,e.status,S(e)));try{o=Error(r+JSON.stringify(t))}catch(e){o=t}}return o.appOrParcelName=S(e),e.status=n,o}const c="NOT_LOADED",l="LOADING_SOURCE_CODE",f="NOT_BOOTSTRAPPED",p="BOOTSTRAPPING",h="NOT_MOUNTED",m="MOUNTING",d="MOUNTED",w="UPDATING",g="UNMOUNTING",E="LOAD_ERROR",y="SKIP_BECAUSE_BROKEN";function v(t){return t.status===d}function P(t){return!v(t)}function O(t){return t.status!==c&&t.status!==l&&t.status!==E}function T(t){return!O(t)}function b(t){try{return t.activeWhen(window.location)}catch(e){o(e,t,y)}}function A(t){try{return!b(t)}catch(e){o(e,t,y)}}function N(t){return t!==y&&(!t||t.status!==y)}function _(t){return t.status!==E||(new Date).getTime()-t.loadErrorTime>=200}function S(t){return t.name}function D(t){return Boolean(t.unmountThisParcel)}function j(t){return D(t)?"parcel":"application"}function M(){for(let t=arguments.length-1;t>0;t--)for(let e in arguments[t])"__proto__"!==e&&(arguments[t-1][e]=arguments[t][e]);return arguments[0]}function U(t,e){for(let n=0;n<t.length;n++)if(e(t[n]))return t[n];return null}function L(t){return t&&("function"==typeof t||(e=t,Array.isArray(e)&&!U(e,t=>"function"!=typeof t)));var e}function R(t,e){let n=t[e]||[];n=Array.isArray(n)?n:[n],0===n.length&&(n=[()=>Promise.resolve()]);const r=j(t),o=S(t);return function(t){return n.reduce((n,i,s)=>n.then(()=>{const n=i(t);return I(n)?n:Promise.reject(u(15,!1,r,o,e,s))}),Promise.resolve())}}function I(t){return t&&"function"==typeof t.then&&"function"==typeof t.catch}function x(t,e){return Promise.resolve().then(()=>t.status!==f?t:(t.status=p,Y(t,"bootstrap").then(()=>(t.status=h,t)).catch(n=>{if(e)throw a(n,t,y);return o(n,t,y),t})))}function $(t,e){return Promise.resolve().then(()=>{if(t.status!==d)return t;t.status=g;const n=Object.keys(t.parcels).map(e=>t.parcels[e].unmountThisParcel());return Promise.all(n).then(r,n=>r().then(()=>{const r=Error(n.message);if(e)throw a(r,t,y);o(r,t,y)})).then(()=>t);function r(){return Y(t,"unmount").then(()=>{t.status=h}).catch(n=>{if(e)throw a(n,t,y);o(n,t,y)})}})}let B=!1,G=!1;function C(t,e){return Promise.resolve().then(()=>t.status!==h?t:(B||(window.dispatchEvent(new n("single-spa:before-first-mount")),B=!0),Y(t,"mount").then(()=>(t.status=d,G||(window.dispatchEvent(new n("single-spa:first-mount")),G=!0),t)).catch(n=>{return t.status=d,$(t,!0).then(r,r);function r(){if(e)throw a(n,t,y);return o(n,t,y),t}})))}let W=0;const k={parcels:{}};function K(){return F.apply(k,arguments)}function F(t,e){const n=this;if(!t||"object"!=typeof t&&"function"!=typeof t)throw Error(u(2,!1));if(t.name&&"string"!=typeof t.name)throw Error(u(3,!1,typeof t.name));if("object"!=typeof e)throw Error(u(4,!1,name,typeof e));if(!e.domElement)throw Error(u(5,!1,name));const r=W++,o="function"==typeof t,i=o?t:()=>Promise.resolve(t),s={id:r,parcels:{},status:o?l:f,customProps:e,parentName:S(n),unmountThisParcel(){if(s.status!==d)throw Error(u(6,!1,name,s.status));return $(s,!0).then(t=>(s.parentName&&delete n.parcels[s.id],t)).then(t=>(E(t),t)).catch(t=>{throw s.status=y,v(t),t})}};let c;n.parcels[r]=s;let p=i();if(!p||"function"!=typeof p.then)throw Error(u(7,!1));p=p.then(t=>{if(!t)throw Error(u(8,!1));const e=t.name||`parcel-${r}`;if(!L(t.bootstrap))throw Error(u(9,!1,e));if(!L(t.mount))throw Error(u(10,!1,e));if(!L(t.unmount))throw Error(u(11,!1,e));if(t.update&&!L(t.update))throw Error(u(12,!1,e));const n=R(t,"bootstrap"),o=R(t,"mount"),i=R(t,"unmount");s.status=f,s.name=e,s.bootstrap=n,s.mount=o,s.unmount=i,s.timeouts=Z(t.timeouts),t.update&&(s.update=R(t,"update"),c.update=function(t){return s.customProps=t,J(function(t){return Promise.resolve().then(()=>{if(t.status!==d)throw Error(u(32,!1,S(t)));return t.status=w,Y(t,"update").then(()=>(t.status=d,t)).catch(e=>{throw a(e,t,y)})})}(s))})});const m=p.then(()=>x(s,!0)),g=m.then(()=>C(s,!0));let E,v;const P=new Promise((t,e)=>{E=t,v=e});return c={mount:()=>J(Promise.resolve().then(()=>{if(s.status!==h)throw Error(u(13,!1,name,s.status));return n.parcels[r]=s,C(s)})),unmount:()=>J(s.unmountThisParcel()),getStatus:()=>s.status,loadPromise:J(p),bootstrapPromise:J(m),mountPromise:J(g),unmountPromise:J(P)},c}function J(t){return t.then(()=>null)}function H(e){const n=M({},e.customProps,{name:S(e),mountParcel:F.bind(e),singleSpa:t});return D(e)&&(n.unmountSelf=e.unmountThisParcel),n}const Q={bootstrap:{millis:4e3,dieOnTimeout:!1,warningMillis:1e3},mount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unmount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unload:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},update:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3}};function V(t,e,n){if("number"!=typeof t||t<=0)throw Error(u(16,!1));Q.bootstrap={millis:t,dieOnTimeout:e,warningMillis:n||1e3}}function q(t,e,n){if("number"!=typeof t||t<=0)throw Error(u(17,!1));Q.mount={millis:t,dieOnTimeout:e,warningMillis:n||1e3}}function z(t,e,n){if("number"!=typeof t||t<=0)throw Error(u(18,!1));Q.unmount={millis:t,dieOnTimeout:e,warningMillis:n||1e3}}function X(t,e,n){if("number"!=typeof t||t<=0)throw Error(u(19,!1));Q.unload={millis:t,dieOnTimeout:e,warningMillis:n||1e3}}function Y(t,e){const n=t.timeouts[e],r=n.warningMillis,o=j(t);return new Promise((i,s)=>{let a=!1,c=!1;t[e](H(t)).then(t=>{a=!0,i(t)}).catch(t=>{a=!0,s(t)}),setTimeout(()=>f(1),r),setTimeout(()=>f(!0),n.millis);const l=u(31,!1,e,o,S(t),n.millis);function f(t){if(!a)if(!0===t)c=!0,n.dieOnTimeout?s(Error(l)):console.error(l);else if(!c){const e=t,o=e*r;console.warn(l),o+r<n.millis&&setTimeout(()=>f(e+1),r)}}})}function Z(t){const e={};for(let n in Q)e[n]=M({},Q[n],t&&t[n]||{});return e}function tt(t){return Promise.resolve().then(()=>{if(t.loadPromise)return t.loadPromise;if(t.status!==c&&t.status!==E)return t;let e,n;return t.status=l,t.loadPromise=Promise.resolve().then(()=>{const r=t.loadApp(H(t));if(!I(r))throw n=!0,Error(u(33,!1,S(t)));return r.then(n=>{let r;t.loadErrorTime=null,e=n,"object"!=typeof e&&(r=34),L(e.bootstrap)||(r=35),L(e.mount)||(r=36),L(e.unmount)||(r=37);const i=j(e);if(r){let n;try{n=JSON.stringify(e)}catch(t){}return console.error(u(r,!1,i,S(t),n),e),o(void 0,t,y),t}return e.devtools&&e.devtools.overlays&&(t.devtools.overlays=M({},t.devtools.overlays,e.devtools.overlays)),t.status=f,t.bootstrap=R(e,"bootstrap"),t.mount=R(e,"mount"),t.unmount=R(e,"unmount"),t.unload=R(e,"unload"),t.timeouts=Z(e.timeouts),delete t.loadPromise,t})}).catch(e=>{let r;return delete t.loadPromise,n?r=y:(r=E,t.loadErrorTime=(new Date).getTime()),o(e,t,r),t})})}const et="undefined"!=typeof window,nt={hashchange:[],popstate:[]},rt=["hashchange","popstate"];function ot(t){let e;if("string"==typeof t)e=t;else if(this&&this.href)e=this.href;else{if(!(t&&t.currentTarget&&t.currentTarget.href&&t.preventDefault))throw Error(u(14,!1));e=t.currentTarget.href,t.preventDefault()}const n=lt(window.location.href),r=lt(e);0===e.indexOf("#")?window.location.hash=r.hash:n.host!==r.host&&r.host?window.location.href=e:r.pathname===n.pathname&&r.search===n.pathname?window.location.hash=r.hash:window.history.pushState(null,null,e)}function it(t){if(t){const e=t[0].type;rt.indexOf(e)>=0&&nt[e].forEach(e=>{try{e.apply(this,t)}catch(t){setTimeout(()=>{throw t})}})}}let st;function ut(){jt([],arguments)}if(et){window.addEventListener("hashchange",ut),window.addEventListener("popstate",ut);const t=window.addEventListener,e=window.removeEventListener;function at(t){return function(){const e=window.location.href,n=t.apply(this,arguments),r=window.location.href;return st&&e===r||ut(ct(window.history.state)),n}}function ct(t){try{return new PopStateEvent("popstate",{state:t})}catch(e){const n=document.createEvent("PopStateEvent");return n.initPopStateEvent("popstate",!1,!1,t),n}}window.addEventListener=function(e,n){if(!("function"==typeof n&&rt.indexOf(e)>=0)||U(nt[e],t=>t===n))return t.apply(this,arguments);nt[e].push(n)},window.removeEventListener=function(t,n){if(!("function"==typeof n&&rt.indexOf(t)>=0))return e.apply(this,arguments);nt[t]=nt[t].filter(t=>t!==n)},window.history.pushState=at(window.history.pushState),window.history.replaceState=at(window.history.replaceState),window.singleSpaNavigate=ot}function lt(t){const e=document.createElement("a");return e.href=t,e}let ft=!1;function pt(t=window.jQuery){if(t||window.$&&window.$.fn&&window.$.fn.jquery&&(t=window.$),t&&!ft){const e=t.fn.on,n=t.fn.off;t.fn.on=function(t,n){return ht.call(this,e,window.addEventListener,t,n,arguments)},t.fn.off=function(t,e){return ht.call(this,n,window.removeEventListener,t,e,arguments)},ft=!0}}function ht(t,e,n,r,o){return"string"!=typeof n?t.apply(this,o):(n.split(/\s+/).forEach(t=>{rt.indexOf(t)>=0&&(e(t,r),n=n.replace(t,""))}),""===n.trim()?this:t.apply(this,o))}const mt={};function dt(t){return Promise.resolve().then(()=>{const e=mt[S(t)];return e?t.status===c?(wt(t,e),t):"UNLOADING"===t.status?e.promise.then(()=>t):t.status!==h?t:(t.status="UNLOADING",Y(t,"unload").then(()=>(wt(t,e),t)).catch(n=>(function(t,e,n){delete mt[S(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,o(n,t,y),e.reject(n)}(t,e,n),t))):t})}function wt(t,e){delete mt[S(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,t.status=c,e.resolve()}function gt(t,e,n,r){mt[S(t)]={app:t,resolve:n,reject:r},Object.defineProperty(mt[S(t)],"promise",{get:e})}const Et=[];function yt(){return Et.filter(v).map(S)}function vt(){return Et.map(S)}function Pt(t){const e=U(Et,e=>S(e)===t);return e?e.status:null}function Ot(t,e,n,r){const o=function(t,e,n,r){const o={name:null,loadApp:null,activeWhen:null,customProps:null};return"object"==typeof t?(function(t){if(Array.isArray(t)||null===t)throw Error(u(39,!1));const e=["name","app","activeWhen","customProps"],n=Object.keys(t).reduce((t,n)=>e.includes(n)?t:t.concat(n),[]);if(0!==n.length)throw Error(u(38,!1,e.join(", "),n.join(", ")));if("string"!=typeof t.name||0===t.name.length)throw Error(u(20,!1));if("object"!=typeof t.app&&"function"!=typeof t.app)throw Error(u(20,!1));const r=t=>"string"==typeof t||"function"==typeof t;if(!(r(t.activeWhen)||Array.isArray(t.activeWhen)&&t.activeWhen.every(r)))throw Error(u(24,!1));if(t.customProps&&("object"!=typeof t.customProps||Array.isArray(t.customProps)))throw Error(u(22,!1))}(t),o.name=t.name,o.loadApp=t.app,o.activeWhen=t.activeWhen,o.customProps=t.customProps):(function(t,e,n,r){if("string"!=typeof t||0===t.length)throw Error(u(20,!1));if(!e)throw Error(u(23,!1));if("function"!=typeof n)throw Error(u(24,!1));if(r&&("object"!=typeof r||Array.isArray(r)))throw Error(u(22,!1))}(t,e,n,r),o.name=t,o.loadApp=e,o.activeWhen=n,o.customProps=r),o.loadApp="function"!=typeof(i=o.loadApp)?()=>Promise.resolve(i):i,o.customProps=function(t){return t||{}}(o.customProps),o.activeWhen=function(t){let e=Array.isArray(t)?t:[t];return e=e.map(t=>"function"==typeof t?t:function(t){const e=function(t){let e=0,n=!1,r="^";for(let e=0;e<t.length;e++){const r=t[e],i=n&&"/"===r;(!n&&":"===r||i)&&o(e)}return o(t.length),new RegExp(r,"i");function o(o){const i=t.slice(e,o).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&");r+=n?"[^/]+/?":i,n=!n,e=o}}(t);return t=>{const n=t.href.replace(t.origin,"");return e.test(n)}}(t)),t=>e.some(e=>e(t))}(o.activeWhen),o;var i}(t,e,n,r);if(-1!==vt().indexOf(o.name))throw Error(u(21,!1,o.name));Et.push(M({loadErrorTime:null,status:c,parcels:{},devtools:{overlays:{options:{},selectors:[]}}},o)),et&&(pt(),jt())}function Tt(t){return Et.filter(e=>e.activeWhen(t)).map(S)}function bt(){return Et.filter(N).filter(_).filter(T).filter(b)}function At(t,e={waitForUnmount:!1}){if("string"!=typeof t)throw Error(u(26,!1));const n=U(Et,e=>S(e)===t);if(!n)throw Error(u(27,!1,t));const r=function(t){return mt[t]}(S(n));if(e&&e.waitForUnmount){if(r)return r.promise;{const t=new Promise((e,r)=>{gt(n,()=>t,e,r)});return t}}{let t;return r?(t=r.promise,Nt(n,r.resolve,r.reject)):t=new Promise((e,r)=>{gt(n,()=>t,e,r),Nt(n,e,r)}),t}}function Nt(t,e,n){$(t).then(dt).then(()=>{e(),setTimeout(()=>{jt()})}).catch(n)}let _t=!1,St=[];function Dt(){return jt()}function jt(t=[],e){if(_t)return new Promise((t,n)=>{St.push({resolve:t,reject:n,eventArguments:e})});const r=[];return Mt?(_t=!0,Promise.resolve().then(()=>{window.dispatchEvent(new n("single-spa:before-routing-event",u()));const e=o(Object.keys(mt).map(t=>mt[t].app).filter(P)).map(dt),a=o(Et.filter(N).filter(v).filter(A)).map($).map(t=>t.then(dt)).concat(e),c=Promise.all(a),l=o(bt()),f=l.map(t=>tt(t).then(x).then(t=>c.then(()=>C(t)))),p=Et.filter(N).filter(P).filter(O).filter(b).filter(t=>l.indexOf(t)<0).map(t=>(r.push(t),x(t).then(()=>c).then(()=>C(t))));return c.catch(t=>{throw s(),t}).then(()=>(s(),Promise.all(f.concat(p)).catch(e=>{throw t.forEach(t=>t.reject(e)),e}).then(i)))})):Promise.resolve().then(()=>{const t=o(bt()).map(tt);return Promise.all(t).then(s).then(()=>[]).catch(t=>{throw s(),t})});function o(t){return r.push(...t),t}function i(){const e=yt();t.forEach(t=>t.resolve(e));try{const t=0===r.length?"single-spa:no-app-change":"single-spa:app-change";window.dispatchEvent(new n(t,u())),window.dispatchEvent(new n("single-spa:routing-event",u()))}catch(t){setTimeout(()=>{throw t})}if(_t=!1,St.length>0){const t=St;St=[],jt(t)}return e}function s(){t.forEach(t=>{it(t.eventArguments)}),it(e)}function u(){const t={},n={[d]:[],[h]:[],[c]:[],[y]:[]};return r.forEach(e=>{const r=S(e),o=Pt(r);t[r]=o,(n[o]=n[o]||[]).push(r)}),{detail:{newAppStatuses:t,appsByNewStatus:n,totalAppChanges:r.length,originalEvent:null==e?void 0:e[0]}}}}let Mt=!1;function Ut(t){var e;Mt=!0,t&&t.urlRerouteOnly&&(e=t.urlRerouteOnly,st=e),et&&jt()}et&&setTimeout(()=>{Mt||console.warn(u(1,!1))},5e3);var Lt={getRawAppData:function(){return[...Et]},reroute:jt,NOT_LOADED:c,toLoadPromise:tt,toBootstrapPromise:x,unregisterApplication:function(t){if(!Et.find(e=>S(e)===t))throw Error(u(25,!1,t));return At(t).then(()=>{const e=Et.findIndex(e=>S(e)===t);Et.splice(e,1)})}};et&&window.__SINGLE_SPA_DEVTOOLS__&&(window.__SINGLE_SPA_DEVTOOLS__.exposedMethods=Lt);export{p as BOOTSTRAPPING,l as LOADING_SOURCE_CODE,E as LOAD_ERROR,d as MOUNTED,m as MOUNTING,f as NOT_BOOTSTRAPPED,c as NOT_LOADED,h as NOT_MOUNTED,y as SKIP_BECAUSE_BROKEN,g as UNMOUNTING,w as UPDATING,i as addErrorHandler,Tt as checkActivityFunctions,pt as ensureJQuerySupport,vt as getAppNames,Pt as getAppStatus,yt as getMountedApps,K as mountRootParcel,ot as navigateToUrl,Ot as registerApplication,s as removeErrorHandler,V as setBootstrapMaxTime,q as setMountMaxTime,X as setUnloadMaxTime,z as setUnmountMaxTime,Ut as start,Dt as triggerAppChange,At as unloadApplication}; | ||
//# sourceMappingURL=single-spa.min.js.map |
@@ -1,1603 +0,1647 @@ | ||
/* single-spa@5.3.1 - SystemJS - dev */ | ||
/* single-spa@5.3.2 - SystemJS - dev */ | ||
System.register([], function (exports) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
exports({ | ||
addErrorHandler: addErrorHandler, | ||
checkActivityFunctions: checkActivityFunctions, | ||
ensureJQuerySupport: ensureJQuerySupport, | ||
getAppNames: getAppNames, | ||
getAppStatus: getAppStatus, | ||
getMountedApps: getMountedApps, | ||
mountRootParcel: mountRootParcel, | ||
navigateToUrl: navigateToUrl, | ||
registerApplication: registerApplication, | ||
removeErrorHandler: removeErrorHandler, | ||
setBootstrapMaxTime: setBootstrapMaxTime, | ||
setMountMaxTime: setMountMaxTime, | ||
setUnloadMaxTime: setUnloadMaxTime, | ||
setUnmountMaxTime: setUnmountMaxTime, | ||
start: start, | ||
triggerAppChange: triggerAppChange, | ||
unloadApplication: unloadApplication | ||
}); | ||
exports({ | ||
addErrorHandler: addErrorHandler, | ||
checkActivityFunctions: checkActivityFunctions, | ||
ensureJQuerySupport: ensureJQuerySupport, | ||
getAppNames: getAppNames, | ||
getAppStatus: getAppStatus, | ||
getMountedApps: getMountedApps, | ||
mountRootParcel: mountRootParcel, | ||
navigateToUrl: navigateToUrl, | ||
registerApplication: registerApplication, | ||
removeErrorHandler: removeErrorHandler, | ||
setBootstrapMaxTime: setBootstrapMaxTime, | ||
setMountMaxTime: setMountMaxTime, | ||
setUnloadMaxTime: setUnloadMaxTime, | ||
setUnmountMaxTime: setUnmountMaxTime, | ||
start: start, | ||
triggerAppChange: triggerAppChange, | ||
unloadApplication: unloadApplication | ||
}); | ||
var singleSpa = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
get start () { return start; }, | ||
get ensureJQuerySupport () { return ensureJQuerySupport; }, | ||
get setBootstrapMaxTime () { return setBootstrapMaxTime; }, | ||
get setMountMaxTime () { return setMountMaxTime; }, | ||
get setUnmountMaxTime () { return setUnmountMaxTime; }, | ||
get setUnloadMaxTime () { return setUnloadMaxTime; }, | ||
get registerApplication () { return registerApplication; }, | ||
get getMountedApps () { return getMountedApps; }, | ||
get getAppStatus () { return getAppStatus; }, | ||
get unloadApplication () { return unloadApplication; }, | ||
get checkActivityFunctions () { return checkActivityFunctions; }, | ||
get getAppNames () { return getAppNames; }, | ||
get navigateToUrl () { return navigateToUrl; }, | ||
get triggerAppChange () { return triggerAppChange; }, | ||
get addErrorHandler () { return addErrorHandler; }, | ||
get removeErrorHandler () { return removeErrorHandler; }, | ||
get mountRootParcel () { return mountRootParcel; }, | ||
get NOT_LOADED () { return NOT_LOADED; }, | ||
get LOADING_SOURCE_CODE () { return LOADING_SOURCE_CODE; }, | ||
get NOT_BOOTSTRAPPED () { return NOT_BOOTSTRAPPED; }, | ||
get BOOTSTRAPPING () { return BOOTSTRAPPING; }, | ||
get NOT_MOUNTED () { return NOT_MOUNTED; }, | ||
get MOUNTING () { return MOUNTING; }, | ||
get UPDATING () { return UPDATING; }, | ||
get LOAD_ERROR () { return LOAD_ERROR; }, | ||
get MOUNTED () { return MOUNTED; }, | ||
get UNMOUNTING () { return UNMOUNTING; }, | ||
get SKIP_BECAUSE_BROKEN () { return SKIP_BECAUSE_BROKEN; } | ||
}); | ||
var singleSpa = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
get start () { return start; }, | ||
get ensureJQuerySupport () { return ensureJQuerySupport; }, | ||
get setBootstrapMaxTime () { return setBootstrapMaxTime; }, | ||
get setMountMaxTime () { return setMountMaxTime; }, | ||
get setUnmountMaxTime () { return setUnmountMaxTime; }, | ||
get setUnloadMaxTime () { return setUnloadMaxTime; }, | ||
get registerApplication () { return registerApplication; }, | ||
get getMountedApps () { return getMountedApps; }, | ||
get getAppStatus () { return getAppStatus; }, | ||
get unloadApplication () { return unloadApplication; }, | ||
get checkActivityFunctions () { return checkActivityFunctions; }, | ||
get getAppNames () { return getAppNames; }, | ||
get navigateToUrl () { return navigateToUrl; }, | ||
get triggerAppChange () { return triggerAppChange; }, | ||
get addErrorHandler () { return addErrorHandler; }, | ||
get removeErrorHandler () { return removeErrorHandler; }, | ||
get mountRootParcel () { return mountRootParcel; }, | ||
get NOT_LOADED () { return NOT_LOADED; }, | ||
get LOADING_SOURCE_CODE () { return LOADING_SOURCE_CODE; }, | ||
get NOT_BOOTSTRAPPED () { return NOT_BOOTSTRAPPED; }, | ||
get BOOTSTRAPPING () { return BOOTSTRAPPING; }, | ||
get NOT_MOUNTED () { return NOT_MOUNTED; }, | ||
get MOUNTING () { return MOUNTING; }, | ||
get UPDATING () { return UPDATING; }, | ||
get LOAD_ERROR () { return LOAD_ERROR; }, | ||
get MOUNTED () { return MOUNTED; }, | ||
get UNMOUNTING () { return UNMOUNTING; }, | ||
get SKIP_BECAUSE_BROKEN () { return SKIP_BECAUSE_BROKEN; } | ||
}); | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
var NativeCustomEvent = commonjsGlobal.CustomEvent; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
function useNative () { | ||
try { | ||
var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } }); | ||
return 'cat' === p.type && 'bar' === p.detail.foo; | ||
} catch (e) { | ||
} | ||
return false; | ||
} | ||
return _typeof(obj); | ||
} | ||
/** | ||
* Cross-browser `CustomEvent` constructor. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent | ||
* | ||
* @public | ||
*/ | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
var customEvent = useNative() ? NativeCustomEvent : | ||
return obj; | ||
} | ||
// IE >= 9 | ||
'undefined' !== typeof document && 'function' === typeof document.createEvent ? function CustomEvent (type, params) { | ||
var e = document.createEvent('CustomEvent'); | ||
if (params) { | ||
e.initCustomEvent(type, params.bubbles, params.cancelable, params.detail); | ||
} else { | ||
e.initCustomEvent(type, false, false, void 0); | ||
} | ||
return e; | ||
} : | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
// IE <= 8 | ||
function CustomEvent (type, params) { | ||
var e = document.createEventObject(); | ||
e.type = type; | ||
if (params) { | ||
e.bubbles = Boolean(params.bubbles); | ||
e.cancelable = Boolean(params.cancelable); | ||
e.detail = params.detail; | ||
} else { | ||
e.bubbles = false; | ||
e.cancelable = false; | ||
e.detail = void 0; | ||
} | ||
return e; | ||
}; | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(n); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
return _typeof(obj); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
var errorHandlers = []; | ||
function handleAppError(err, app, newStatus) { | ||
var transformedErr = transformErr(err, app, newStatus); | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
if (errorHandlers.length) { | ||
errorHandlers.forEach(function (handler) { | ||
return handler(transformedErr); | ||
}); | ||
} else { | ||
setTimeout(function () { | ||
throw transformedErr; | ||
}); | ||
} | ||
} | ||
function addErrorHandler(handler) { | ||
if (typeof handler !== "function") { | ||
throw Error(formatErrorMessage(28, "a single-spa error handler must be a function")); | ||
} | ||
return arr2; | ||
} | ||
errorHandlers.push(handler); | ||
} | ||
function removeErrorHandler(handler) { | ||
if (typeof handler !== "function") { | ||
throw Error(formatErrorMessage(29, "a single-spa error handler must be a function")); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var removedSomething = false; | ||
errorHandlers = errorHandlers.filter(function (h) { | ||
var isHandler = h === handler; | ||
removedSomething = removedSomething || isHandler; | ||
return !isHandler; | ||
}); | ||
return removedSomething; | ||
} | ||
function formatErrorMessage(code, msg) { | ||
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
return "single-spa minified message #".concat(code, ": ").concat(msg ? msg + " " : "", "See https://single-spa.js.org/error/?code=").concat(code).concat(args.length ? "&arg=".concat(args.join("&arg=")) : ""); | ||
} | ||
function transformErr(ogErr, appOrParcel, newStatus) { | ||
var errPrefix = "".concat(objectType(appOrParcel), " '").concat(toName(appOrParcel), "' died in status ").concat(appOrParcel.status, ": "); | ||
var result; | ||
var NativeCustomEvent = commonjsGlobal.CustomEvent; | ||
if (ogErr instanceof Error) { | ||
try { | ||
ogErr.message = errPrefix + ogErr.message; | ||
} catch (err) { | ||
/* Some errors have read-only message properties, in which case there is nothing | ||
* that we can do. | ||
*/ | ||
} | ||
function useNative () { | ||
try { | ||
var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } }); | ||
return 'cat' === p.type && 'bar' === p.detail.foo; | ||
} catch (e) { | ||
} | ||
return false; | ||
} | ||
result = ogErr; | ||
} else { | ||
console.warn(formatErrorMessage(30, "While ".concat(appOrParcel.status, ", '").concat(toName(appOrParcel), "' rejected its lifecycle function promise with a non-Error. This will cause stack traces to not be accurate."), appOrParcel.status, toName(appOrParcel))); | ||
/** | ||
* Cross-browser `CustomEvent` constructor. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent | ||
* | ||
* @public | ||
*/ | ||
try { | ||
result = Error(errPrefix + JSON.stringify(ogErr)); | ||
} catch (err) { | ||
// If it's not an Error and you can't stringify it, then what else can you even do to it? | ||
result = ogErr; | ||
} | ||
} | ||
var customEvent = useNative() ? NativeCustomEvent : | ||
result.appOrParcelName = toName(appOrParcel); // We set the status after transforming the error so that the error message | ||
// references the state the application was in before the status change. | ||
// IE >= 9 | ||
'undefined' !== typeof document && 'function' === typeof document.createEvent ? function CustomEvent (type, params) { | ||
var e = document.createEvent('CustomEvent'); | ||
if (params) { | ||
e.initCustomEvent(type, params.bubbles, params.cancelable, params.detail); | ||
} else { | ||
e.initCustomEvent(type, false, false, void 0); | ||
} | ||
return e; | ||
} : | ||
appOrParcel.status = newStatus; | ||
return result; | ||
} | ||
// IE <= 8 | ||
function CustomEvent (type, params) { | ||
var e = document.createEventObject(); | ||
e.type = type; | ||
if (params) { | ||
e.bubbles = Boolean(params.bubbles); | ||
e.cancelable = Boolean(params.cancelable); | ||
e.detail = params.detail; | ||
} else { | ||
e.bubbles = false; | ||
e.cancelable = false; | ||
e.detail = void 0; | ||
} | ||
return e; | ||
}; | ||
var NOT_LOADED = exports('NOT_LOADED', "NOT_LOADED"); | ||
var LOADING_SOURCE_CODE = exports('LOADING_SOURCE_CODE', "LOADING_SOURCE_CODE"); | ||
var NOT_BOOTSTRAPPED = exports('NOT_BOOTSTRAPPED', "NOT_BOOTSTRAPPED"); | ||
var BOOTSTRAPPING = exports('BOOTSTRAPPING', "BOOTSTRAPPING"); | ||
var NOT_MOUNTED = exports('NOT_MOUNTED', "NOT_MOUNTED"); | ||
var MOUNTING = exports('MOUNTING', "MOUNTING"); | ||
var MOUNTED = exports('MOUNTED', "MOUNTED"); | ||
var UPDATING = exports('UPDATING', "UPDATING"); | ||
var UNMOUNTING = exports('UNMOUNTING', "UNMOUNTING"); | ||
var UNLOADING = "UNLOADING"; | ||
var LOAD_ERROR = exports('LOAD_ERROR', "LOAD_ERROR"); | ||
var SKIP_BECAUSE_BROKEN = exports('SKIP_BECAUSE_BROKEN', "SKIP_BECAUSE_BROKEN"); | ||
function isActive(app) { | ||
return app.status === MOUNTED; | ||
} | ||
function isntActive(app) { | ||
return !isActive(app); | ||
} | ||
function isLoaded(app) { | ||
return app.status !== NOT_LOADED && app.status !== LOADING_SOURCE_CODE && app.status !== LOAD_ERROR; | ||
} | ||
function isntLoaded(app) { | ||
return !isLoaded(app); | ||
} | ||
function shouldBeActive(app) { | ||
try { | ||
return app.activeWhen(window.location); | ||
} catch (err) { | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
function shouldntBeActive(app) { | ||
try { | ||
return !shouldBeActive(app); | ||
} catch (err) { | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
function notSkipped(item) { | ||
return item !== SKIP_BECAUSE_BROKEN && (!item || item.status !== SKIP_BECAUSE_BROKEN); | ||
} | ||
function withoutLoadErrors(app) { | ||
return app.status === LOAD_ERROR ? new Date().getTime() - app.loadErrorTime >= 200 : true; | ||
} | ||
function toName(app) { | ||
return app.name; | ||
} | ||
function isParcel(appOrParcel) { | ||
return Boolean(appOrParcel.unmountThisParcel); | ||
} | ||
function objectType(appOrParcel) { | ||
return isParcel(appOrParcel) ? "parcel" : "application"; | ||
} | ||
var errorHandlers = []; | ||
function handleAppError(err, app, newStatus) { | ||
var transformedErr = transformErr(err, app, newStatus); | ||
// Object.assign() is not available in IE11. And the babel compiled output for object spread | ||
// syntax checks a bunch of Symbol stuff and is almost a kb. So this function is the smaller replacement. | ||
function assign() { | ||
for (var i = arguments.length - 1; i > 0; i--) { | ||
for (var key in arguments[i]) { | ||
if (key === "__proto__") { | ||
continue; | ||
} | ||
if (errorHandlers.length) { | ||
errorHandlers.forEach(function (handler) { | ||
return handler(transformedErr); | ||
}); | ||
} else { | ||
setTimeout(function () { | ||
throw transformedErr; | ||
}); | ||
} | ||
} | ||
function addErrorHandler(handler) { | ||
if (typeof handler !== "function") { | ||
throw Error(formatErrorMessage(28, "a single-spa error handler must be a function")); | ||
} | ||
arguments[i - 1][key] = arguments[i][key]; | ||
} | ||
} | ||
errorHandlers.push(handler); | ||
} | ||
function removeErrorHandler(handler) { | ||
if (typeof handler !== "function") { | ||
throw Error(formatErrorMessage(29, "a single-spa error handler must be a function")); | ||
} | ||
return arguments[0]; | ||
} | ||
var removedSomething = false; | ||
errorHandlers = errorHandlers.filter(function (h) { | ||
var isHandler = h === handler; | ||
removedSomething = removedSomething || isHandler; | ||
return !isHandler; | ||
}); | ||
return removedSomething; | ||
} | ||
function formatErrorMessage(code, msg) { | ||
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
/* the array.prototype.find polyfill on npmjs.com is ~20kb (not worth it) | ||
* and lodash is ~200kb (not worth it) | ||
*/ | ||
function find(arr, func) { | ||
for (var i = 0; i < arr.length; i++) { | ||
if (func(arr[i])) { | ||
return arr[i]; | ||
} | ||
} | ||
return "single-spa minified message #".concat(code, ": ").concat(msg ? msg + " " : "", "See https://single-spa.js.org/error/?code=").concat(code).concat(args.length ? "&arg=".concat(args.join("&arg=")) : ""); | ||
} | ||
function transformErr(ogErr, appOrParcel, newStatus) { | ||
var errPrefix = "".concat(objectType(appOrParcel), " '").concat(toName(appOrParcel), "' died in status ").concat(appOrParcel.status, ": "); | ||
var result; | ||
return null; | ||
} | ||
if (ogErr instanceof Error) { | ||
try { | ||
ogErr.message = errPrefix + ogErr.message; | ||
} catch (err) { | ||
/* Some errors have read-only message properties, in which case there is nothing | ||
* that we can do. | ||
*/ | ||
} | ||
function validLifecycleFn(fn) { | ||
return fn && (typeof fn === "function" || isArrayOfFns(fn)); | ||
result = ogErr; | ||
} else { | ||
console.warn(formatErrorMessage(30, "While ".concat(appOrParcel.status, ", '").concat(toName(appOrParcel), "' rejected its lifecycle function promise with a non-Error. This will cause stack traces to not be accurate."), appOrParcel.status, toName(appOrParcel))); | ||
function isArrayOfFns(arr) { | ||
return Array.isArray(arr) && !find(arr, function (item) { | ||
return typeof item !== "function"; | ||
}); | ||
} | ||
} | ||
function flattenFnArray(appOrParcel, lifecycle) { | ||
var fns = appOrParcel[lifecycle] || []; | ||
fns = Array.isArray(fns) ? fns : [fns]; | ||
try { | ||
result = Error(errPrefix + JSON.stringify(ogErr)); | ||
} catch (err) { | ||
// If it's not an Error and you can't stringify it, then what else can you even do to it? | ||
result = ogErr; | ||
} | ||
} | ||
if (fns.length === 0) { | ||
fns = [function () { | ||
return Promise.resolve(); | ||
}]; | ||
} | ||
result.appOrParcelName = toName(appOrParcel); // We set the status after transforming the error so that the error message | ||
// references the state the application was in before the status change. | ||
var type = objectType(appOrParcel); | ||
var name = toName(appOrParcel); | ||
return function (props) { | ||
return fns.reduce(function (resultPromise, fn, index) { | ||
return resultPromise.then(function () { | ||
var thisPromise = fn(props); | ||
return smellsLikeAPromise(thisPromise) ? thisPromise : Promise.reject(formatErrorMessage(15, "Within ".concat(type, " ").concat(name, ", the lifecycle function ").concat(lifecycle, " at array index ").concat(index, " did not return a promise"), type, name, lifecycle, index)); | ||
}); | ||
}, Promise.resolve()); | ||
}; | ||
} | ||
function smellsLikeAPromise(promise) { | ||
return promise && typeof promise.then === "function" && typeof promise.catch === "function"; | ||
} | ||
appOrParcel.status = newStatus; | ||
return result; | ||
} | ||
function toBootstrapPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== NOT_BOOTSTRAPPED) { | ||
return appOrParcel; | ||
} | ||
var NOT_LOADED = exports('NOT_LOADED', "NOT_LOADED"); | ||
var LOADING_SOURCE_CODE = exports('LOADING_SOURCE_CODE', "LOADING_SOURCE_CODE"); | ||
var NOT_BOOTSTRAPPED = exports('NOT_BOOTSTRAPPED', "NOT_BOOTSTRAPPED"); | ||
var BOOTSTRAPPING = exports('BOOTSTRAPPING', "BOOTSTRAPPING"); | ||
var NOT_MOUNTED = exports('NOT_MOUNTED', "NOT_MOUNTED"); | ||
var MOUNTING = exports('MOUNTING', "MOUNTING"); | ||
var MOUNTED = exports('MOUNTED', "MOUNTED"); | ||
var UPDATING = exports('UPDATING', "UPDATING"); | ||
var UNMOUNTING = exports('UNMOUNTING', "UNMOUNTING"); | ||
var UNLOADING = "UNLOADING"; | ||
var LOAD_ERROR = exports('LOAD_ERROR', "LOAD_ERROR"); | ||
var SKIP_BECAUSE_BROKEN = exports('SKIP_BECAUSE_BROKEN', "SKIP_BECAUSE_BROKEN"); | ||
function isActive(app) { | ||
return app.status === MOUNTED; | ||
} | ||
function isntActive(app) { | ||
return !isActive(app); | ||
} | ||
function isLoaded(app) { | ||
return app.status !== NOT_LOADED && app.status !== LOADING_SOURCE_CODE && app.status !== LOAD_ERROR; | ||
} | ||
function isntLoaded(app) { | ||
return !isLoaded(app); | ||
} | ||
function shouldBeActive(app) { | ||
try { | ||
return app.activeWhen(window.location); | ||
} catch (err) { | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
function shouldntBeActive(app) { | ||
try { | ||
return !shouldBeActive(app); | ||
} catch (err) { | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
function notSkipped(item) { | ||
return item !== SKIP_BECAUSE_BROKEN && (!item || item.status !== SKIP_BECAUSE_BROKEN); | ||
} | ||
function withoutLoadErrors(app) { | ||
return app.status === LOAD_ERROR ? new Date().getTime() - app.loadErrorTime >= 200 : true; | ||
} | ||
function toName(app) { | ||
return app.name; | ||
} | ||
function isParcel(appOrParcel) { | ||
return Boolean(appOrParcel.unmountThisParcel); | ||
} | ||
function objectType(appOrParcel) { | ||
return isParcel(appOrParcel) ? "parcel" : "application"; | ||
} | ||
appOrParcel.status = BOOTSTRAPPING; | ||
return reasonableTime(appOrParcel, "bootstrap").then(function () { | ||
appOrParcel.status = NOT_MOUNTED; | ||
return appOrParcel; | ||
}).catch(function (err) { | ||
if (hardFail) { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
return appOrParcel; | ||
} | ||
}); | ||
}); | ||
} | ||
// Object.assign() is not available in IE11. And the babel compiled output for object spread | ||
// syntax checks a bunch of Symbol stuff and is almost a kb. So this function is the smaller replacement. | ||
function assign() { | ||
for (var i = arguments.length - 1; i > 0; i--) { | ||
for (var key in arguments[i]) { | ||
if (key === "__proto__") { | ||
continue; | ||
} | ||
function toUnmountPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== MOUNTED) { | ||
return appOrParcel; | ||
} | ||
arguments[i - 1][key] = arguments[i][key]; | ||
} | ||
} | ||
appOrParcel.status = UNMOUNTING; | ||
var unmountChildrenParcels = Object.keys(appOrParcel.parcels).map(function (parcelId) { | ||
return appOrParcel.parcels[parcelId].unmountThisParcel(); | ||
}); | ||
return Promise.all(unmountChildrenParcels).then(unmountAppOrParcel, function (parcelError) { | ||
// There is a parcel unmount error | ||
return unmountAppOrParcel().then(function () { | ||
// Unmounting the app/parcel succeeded, but unmounting its children parcels did not | ||
var parentError = Error(parcelError.message); | ||
return arguments[0]; | ||
} | ||
if (hardFail) { | ||
throw transformErr(parentError, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(parentError, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
}); | ||
}).then(function () { | ||
return appOrParcel; | ||
}); | ||
/* the array.prototype.find polyfill on npmjs.com is ~20kb (not worth it) | ||
* and lodash is ~200kb (not worth it) | ||
*/ | ||
function find(arr, func) { | ||
for (var i = 0; i < arr.length; i++) { | ||
if (func(arr[i])) { | ||
return arr[i]; | ||
} | ||
} | ||
function unmountAppOrParcel() { | ||
// We always try to unmount the appOrParcel, even if the children parcels failed to unmount. | ||
return reasonableTime(appOrParcel, "unmount").then(function () { | ||
// The appOrParcel needs to stay in a broken status if its children parcels fail to unmount | ||
{ | ||
appOrParcel.status = NOT_MOUNTED; | ||
} | ||
}).catch(function (err) { | ||
if (hardFail) { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
return null; | ||
} | ||
var beforeFirstMountFired = false; | ||
var firstMountFired = false; | ||
function toMountPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== NOT_MOUNTED) { | ||
return appOrParcel; | ||
} | ||
function validLifecycleFn(fn) { | ||
return fn && (typeof fn === "function" || isArrayOfFns(fn)); | ||
if (!beforeFirstMountFired) { | ||
window.dispatchEvent(new customEvent("single-spa:before-first-mount")); | ||
beforeFirstMountFired = true; | ||
} | ||
function isArrayOfFns(arr) { | ||
return Array.isArray(arr) && !find(arr, function (item) { | ||
return typeof item !== "function"; | ||
}); | ||
} | ||
} | ||
function flattenFnArray(appOrParcel, lifecycle) { | ||
var fns = appOrParcel[lifecycle] || []; | ||
fns = Array.isArray(fns) ? fns : [fns]; | ||
return reasonableTime(appOrParcel, "mount").then(function () { | ||
appOrParcel.status = MOUNTED; | ||
if (fns.length === 0) { | ||
fns = [function () { | ||
return Promise.resolve(); | ||
}]; | ||
} | ||
if (!firstMountFired) { | ||
window.dispatchEvent(new customEvent("single-spa:first-mount")); | ||
firstMountFired = true; | ||
} | ||
var type = objectType(appOrParcel); | ||
var name = toName(appOrParcel); | ||
return function (props) { | ||
return fns.reduce(function (resultPromise, fn, index) { | ||
return resultPromise.then(function () { | ||
var thisPromise = fn(props); | ||
return smellsLikeAPromise(thisPromise) ? thisPromise : Promise.reject(formatErrorMessage(15, "Within ".concat(type, " ").concat(name, ", the lifecycle function ").concat(lifecycle, " at array index ").concat(index, " did not return a promise"), type, name, lifecycle, index)); | ||
}); | ||
}, Promise.resolve()); | ||
}; | ||
} | ||
function smellsLikeAPromise(promise) { | ||
return promise && typeof promise.then === "function" && typeof promise.catch === "function"; | ||
} | ||
return appOrParcel; | ||
}).catch(function (err) { | ||
// If we fail to mount the appOrParcel, we should attempt to unmount it before putting in SKIP_BECAUSE_BROKEN | ||
// We temporarily put the appOrParcel into MOUNTED status so that toUnmountPromise actually attempts to unmount it | ||
// instead of just doing a no-op. | ||
appOrParcel.status = MOUNTED; | ||
return toUnmountPromise(appOrParcel, true).then(setSkipBecauseBroken, setSkipBecauseBroken); | ||
function toBootstrapPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== NOT_BOOTSTRAPPED) { | ||
return appOrParcel; | ||
} | ||
function setSkipBecauseBroken() { | ||
if (!hardFail) { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
return appOrParcel; | ||
} else { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
appOrParcel.status = BOOTSTRAPPING; | ||
return reasonableTime(appOrParcel, "bootstrap").then(function () { | ||
appOrParcel.status = NOT_MOUNTED; | ||
return appOrParcel; | ||
}).catch(function (err) { | ||
if (hardFail) { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
return appOrParcel; | ||
} | ||
}); | ||
}); | ||
} | ||
function toUpdatePromise(parcel) { | ||
return Promise.resolve().then(function () { | ||
if (parcel.status !== MOUNTED) { | ||
throw Error(formatErrorMessage(32, "Cannot update parcel '".concat(toName(parcel), "' because it is not mounted"), toName(parcel))); | ||
} | ||
function toUnmountPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== MOUNTED) { | ||
return appOrParcel; | ||
} | ||
parcel.status = UPDATING; | ||
return reasonableTime(parcel, "update").then(function () { | ||
parcel.status = MOUNTED; | ||
return parcel; | ||
}).catch(function (err) { | ||
throw transformErr(err, parcel, SKIP_BECAUSE_BROKEN); | ||
}); | ||
}); | ||
} | ||
appOrParcel.status = UNMOUNTING; | ||
var unmountChildrenParcels = Object.keys(appOrParcel.parcels).map(function (parcelId) { | ||
return appOrParcel.parcels[parcelId].unmountThisParcel(); | ||
}); | ||
return Promise.all(unmountChildrenParcels).then(unmountAppOrParcel, function (parcelError) { | ||
// There is a parcel unmount error | ||
return unmountAppOrParcel().then(function () { | ||
// Unmounting the app/parcel succeeded, but unmounting its children parcels did not | ||
var parentError = Error(parcelError.message); | ||
var parcelCount = 0; | ||
var rootParcels = { | ||
parcels: {} | ||
}; // This is a public api, exported to users of single-spa | ||
if (hardFail) { | ||
throw transformErr(parentError, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(parentError, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
}); | ||
}).then(function () { | ||
return appOrParcel; | ||
}); | ||
function mountRootParcel() { | ||
return mountParcel.apply(rootParcels, arguments); | ||
} | ||
function mountParcel(config, customProps) { | ||
var owningAppOrParcel = this; // Validate inputs | ||
function unmountAppOrParcel() { | ||
// We always try to unmount the appOrParcel, even if the children parcels failed to unmount. | ||
return reasonableTime(appOrParcel, "unmount").then(function () { | ||
// The appOrParcel needs to stay in a broken status if its children parcels fail to unmount | ||
{ | ||
appOrParcel.status = NOT_MOUNTED; | ||
} | ||
}).catch(function (err) { | ||
if (hardFail) { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
if (!config || _typeof(config) !== "object" && typeof config !== "function") { | ||
throw Error(formatErrorMessage(2, "Cannot mount parcel without a config object or config loading function")); | ||
} | ||
var beforeFirstMountFired = false; | ||
var firstMountFired = false; | ||
function toMountPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== NOT_MOUNTED) { | ||
return appOrParcel; | ||
} | ||
if (config.name && typeof config.name !== "string") { | ||
throw Error(formatErrorMessage(3, "Parcel name must be a string, if provided. Was given ".concat(_typeof(config.name)), _typeof(config.name))); | ||
} | ||
if (!beforeFirstMountFired) { | ||
window.dispatchEvent(new customEvent("single-spa:before-first-mount")); | ||
beforeFirstMountFired = true; | ||
} | ||
if (_typeof(customProps) !== "object") { | ||
throw Error(formatErrorMessage(4, "Parcel ".concat(name, " has invalid customProps -- must be an object but was given ").concat(_typeof(customProps)), name, _typeof(customProps))); | ||
} | ||
return reasonableTime(appOrParcel, "mount").then(function () { | ||
appOrParcel.status = MOUNTED; | ||
if (!customProps.domElement) { | ||
throw Error(formatErrorMessage(5, "Parcel ".concat(name, " cannot be mounted without a domElement provided as a prop"), name)); | ||
} | ||
if (!firstMountFired) { | ||
window.dispatchEvent(new customEvent("single-spa:first-mount")); | ||
firstMountFired = true; | ||
} | ||
var id = parcelCount++; | ||
var passedConfigLoadingFunction = typeof config === "function"; | ||
var configLoadingFunction = passedConfigLoadingFunction ? config : function () { | ||
return Promise.resolve(config); | ||
}; // Internal representation | ||
return appOrParcel; | ||
}).catch(function (err) { | ||
// If we fail to mount the appOrParcel, we should attempt to unmount it before putting in SKIP_BECAUSE_BROKEN | ||
// We temporarily put the appOrParcel into MOUNTED status so that toUnmountPromise actually attempts to unmount it | ||
// instead of just doing a no-op. | ||
appOrParcel.status = MOUNTED; | ||
return toUnmountPromise(appOrParcel, true).then(setSkipBecauseBroken, setSkipBecauseBroken); | ||
var parcel = { | ||
id: id, | ||
parcels: {}, | ||
status: passedConfigLoadingFunction ? LOADING_SOURCE_CODE : NOT_BOOTSTRAPPED, | ||
customProps: customProps, | ||
parentName: toName(owningAppOrParcel), | ||
unmountThisParcel: function unmountThisParcel() { | ||
if (parcel.status !== MOUNTED) { | ||
throw Error(formatErrorMessage(6, "Cannot unmount parcel '".concat(name, "' -- it is in a ").concat(parcel.status, " status"), name, parcel.status)); | ||
} | ||
function setSkipBecauseBroken() { | ||
if (!hardFail) { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
return appOrParcel; | ||
} else { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
return toUnmountPromise(parcel, true).then(function (value) { | ||
if (parcel.parentName) { | ||
delete owningAppOrParcel.parcels[parcel.id]; | ||
} | ||
function toUpdatePromise(parcel) { | ||
return Promise.resolve().then(function () { | ||
if (parcel.status !== MOUNTED) { | ||
throw Error(formatErrorMessage(32, "Cannot update parcel '".concat(toName(parcel), "' because it is not mounted"), toName(parcel))); | ||
} | ||
return value; | ||
}).then(function (value) { | ||
resolveUnmount(value); | ||
return value; | ||
}).catch(function (err) { | ||
parcel.status = SKIP_BECAUSE_BROKEN; | ||
rejectUnmount(err); | ||
throw err; | ||
}); | ||
} | ||
}; // We return an external representation | ||
parcel.status = UPDATING; | ||
return reasonableTime(parcel, "update").then(function () { | ||
parcel.status = MOUNTED; | ||
return parcel; | ||
}).catch(function (err) { | ||
throw transformErr(err, parcel, SKIP_BECAUSE_BROKEN); | ||
}); | ||
}); | ||
} | ||
var externalRepresentation; // Add to owning app or parcel | ||
var parcelCount = 0; | ||
var rootParcels = { | ||
parcels: {} | ||
}; // This is a public api, exported to users of single-spa | ||
owningAppOrParcel.parcels[id] = parcel; | ||
var loadPromise = configLoadingFunction(); | ||
function mountRootParcel() { | ||
return mountParcel.apply(rootParcels, arguments); | ||
} | ||
function mountParcel(config, customProps) { | ||
var owningAppOrParcel = this; // Validate inputs | ||
if (!loadPromise || typeof loadPromise.then !== "function") { | ||
throw Error(formatErrorMessage(7, "When mounting a parcel, the config loading function must return a promise that resolves with the parcel config")); | ||
} | ||
if (!config || _typeof(config) !== "object" && typeof config !== "function") { | ||
throw Error(formatErrorMessage(2, "Cannot mount parcel without a config object or config loading function")); | ||
} | ||
loadPromise = loadPromise.then(function (config) { | ||
if (!config) { | ||
throw Error(formatErrorMessage(8, "When mounting a parcel, the config loading function returned a promise that did not resolve with a parcel config")); | ||
} | ||
if (config.name && typeof config.name !== "string") { | ||
throw Error(formatErrorMessage(3, "Parcel name must be a string, if provided. Was given ".concat(_typeof(config.name)), _typeof(config.name))); | ||
} | ||
var name = config.name || "parcel-".concat(id); | ||
if (_typeof(customProps) !== "object") { | ||
throw Error(formatErrorMessage(4, "Parcel ".concat(name, " has invalid customProps -- must be an object but was given ").concat(_typeof(customProps)), name, _typeof(customProps))); | ||
} | ||
if (!validLifecycleFn(config.bootstrap)) { | ||
throw Error(formatErrorMessage(9, "Parcel ".concat(name, " must have a valid bootstrap function"), name)); | ||
} | ||
if (!customProps.domElement) { | ||
throw Error(formatErrorMessage(5, "Parcel ".concat(name, " cannot be mounted without a domElement provided as a prop"), name)); | ||
} | ||
if (!validLifecycleFn(config.mount)) { | ||
throw Error(formatErrorMessage(10, "Parcel ".concat(name, " must have a valid mount function"), name)); | ||
} | ||
var id = parcelCount++; | ||
var passedConfigLoadingFunction = typeof config === "function"; | ||
var configLoadingFunction = passedConfigLoadingFunction ? config : function () { | ||
return Promise.resolve(config); | ||
}; // Internal representation | ||
if (!validLifecycleFn(config.unmount)) { | ||
throw Error(formatErrorMessage(11, "Parcel ".concat(name, " must have a valid unmount function"), name)); | ||
} | ||
var parcel = { | ||
id: id, | ||
parcels: {}, | ||
status: passedConfigLoadingFunction ? LOADING_SOURCE_CODE : NOT_BOOTSTRAPPED, | ||
customProps: customProps, | ||
parentName: toName(owningAppOrParcel), | ||
unmountThisParcel: function unmountThisParcel() { | ||
if (parcel.status !== MOUNTED) { | ||
throw Error(formatErrorMessage(6, "Cannot unmount parcel '".concat(name, "' -- it is in a ").concat(parcel.status, " status"), name, parcel.status)); | ||
} | ||
if (config.update && !validLifecycleFn(config.update)) { | ||
throw Error(formatErrorMessage(12, "Parcel ".concat(name, " provided an invalid update function"), name)); | ||
} | ||
return toUnmountPromise(parcel, true).then(function (value) { | ||
if (parcel.parentName) { | ||
delete owningAppOrParcel.parcels[parcel.id]; | ||
} | ||
var bootstrap = flattenFnArray(config, "bootstrap"); | ||
var mount = flattenFnArray(config, "mount"); | ||
var unmount = flattenFnArray(config, "unmount"); | ||
parcel.status = NOT_BOOTSTRAPPED; | ||
parcel.name = name; | ||
parcel.bootstrap = bootstrap; | ||
parcel.mount = mount; | ||
parcel.unmount = unmount; | ||
parcel.timeouts = ensureValidAppTimeouts(config.timeouts); | ||
return value; | ||
}).then(function (value) { | ||
resolveUnmount(value); | ||
return value; | ||
}).catch(function (err) { | ||
parcel.status = SKIP_BECAUSE_BROKEN; | ||
rejectUnmount(err); | ||
throw err; | ||
}); | ||
} | ||
}; // We return an external representation | ||
if (config.update) { | ||
parcel.update = flattenFnArray(config, "update"); | ||
var externalRepresentation; // Add to owning app or parcel | ||
externalRepresentation.update = function (customProps) { | ||
parcel.customProps = customProps; | ||
return promiseWithoutReturnValue(toUpdatePromise(parcel)); | ||
}; | ||
} | ||
}); // Start bootstrapping and mounting | ||
// The .then() causes the work to be put on the event loop instead of happening immediately | ||
owningAppOrParcel.parcels[id] = parcel; | ||
var loadPromise = configLoadingFunction(); | ||
var bootstrapPromise = loadPromise.then(function () { | ||
return toBootstrapPromise(parcel, true); | ||
}); | ||
var mountPromise = bootstrapPromise.then(function () { | ||
return toMountPromise(parcel, true); | ||
}); | ||
var resolveUnmount, rejectUnmount; | ||
var unmountPromise = new Promise(function (resolve, reject) { | ||
resolveUnmount = resolve; | ||
rejectUnmount = reject; | ||
}); | ||
externalRepresentation = { | ||
mount: function mount() { | ||
return promiseWithoutReturnValue(Promise.resolve().then(function () { | ||
if (parcel.status !== NOT_MOUNTED) { | ||
throw Error(formatErrorMessage(13, "Cannot mount parcel '".concat(name, "' -- it is in a ").concat(parcel.status, " status"), name, parcel.status)); | ||
} // Add to owning app or parcel | ||
if (!loadPromise || typeof loadPromise.then !== "function") { | ||
throw Error(formatErrorMessage(7, "When mounting a parcel, the config loading function must return a promise that resolves with the parcel config")); | ||
} | ||
loadPromise = loadPromise.then(function (config) { | ||
if (!config) { | ||
throw Error(formatErrorMessage(8, "When mounting a parcel, the config loading function returned a promise that did not resolve with a parcel config")); | ||
} | ||
owningAppOrParcel.parcels[id] = parcel; | ||
return toMountPromise(parcel); | ||
})); | ||
}, | ||
unmount: function unmount() { | ||
return promiseWithoutReturnValue(parcel.unmountThisParcel()); | ||
}, | ||
getStatus: function getStatus() { | ||
return parcel.status; | ||
}, | ||
loadPromise: promiseWithoutReturnValue(loadPromise), | ||
bootstrapPromise: promiseWithoutReturnValue(bootstrapPromise), | ||
mountPromise: promiseWithoutReturnValue(mountPromise), | ||
unmountPromise: promiseWithoutReturnValue(unmountPromise) | ||
}; | ||
return externalRepresentation; | ||
} | ||
var name = config.name || "parcel-".concat(id); | ||
function promiseWithoutReturnValue(promise) { | ||
return promise.then(function () { | ||
return null; | ||
}); | ||
} | ||
if (!validLifecycleFn(config.bootstrap)) { | ||
throw Error(formatErrorMessage(9, "Parcel ".concat(name, " must have a valid bootstrap function"), name)); | ||
} | ||
function getProps(appOrParcel) { | ||
var result = assign({}, appOrParcel.customProps, { | ||
name: toName(appOrParcel), | ||
mountParcel: mountParcel.bind(appOrParcel), | ||
singleSpa: singleSpa | ||
}); | ||
if (!validLifecycleFn(config.mount)) { | ||
throw Error(formatErrorMessage(10, "Parcel ".concat(name, " must have a valid mount function"), name)); | ||
} | ||
if (isParcel(appOrParcel)) { | ||
result.unmountSelf = appOrParcel.unmountThisParcel; | ||
} | ||
if (!validLifecycleFn(config.unmount)) { | ||
throw Error(formatErrorMessage(11, "Parcel ".concat(name, " must have a valid unmount function"), name)); | ||
} | ||
return result; | ||
} | ||
if (config.update && !validLifecycleFn(config.update)) { | ||
throw Error(formatErrorMessage(12, "Parcel ".concat(name, " provided an invalid update function"), name)); | ||
} | ||
var defaultWarningMillis = 1000; | ||
var globalTimeoutConfig = { | ||
bootstrap: { | ||
millis: 4000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
mount: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
unmount: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
unload: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
update: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
} | ||
}; | ||
function setBootstrapMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(16, "bootstrap max time must be a positive integer number of milliseconds")); | ||
} | ||
var bootstrap = flattenFnArray(config, "bootstrap"); | ||
var mount = flattenFnArray(config, "mount"); | ||
var unmount = flattenFnArray(config, "unmount"); | ||
parcel.status = NOT_BOOTSTRAPPED; | ||
parcel.name = name; | ||
parcel.bootstrap = bootstrap; | ||
parcel.mount = mount; | ||
parcel.unmount = unmount; | ||
parcel.timeouts = ensureValidAppTimeouts(config.timeouts); | ||
globalTimeoutConfig.bootstrap = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setMountMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(17, "mount max time must be a positive integer number of milliseconds")); | ||
} | ||
if (config.update) { | ||
parcel.update = flattenFnArray(config, "update"); | ||
globalTimeoutConfig.mount = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setUnmountMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(18, "unmount max time must be a positive integer number of milliseconds")); | ||
} | ||
externalRepresentation.update = function (customProps) { | ||
parcel.customProps = customProps; | ||
return promiseWithoutReturnValue(toUpdatePromise(parcel)); | ||
}; | ||
} | ||
}); // Start bootstrapping and mounting | ||
// The .then() causes the work to be put on the event loop instead of happening immediately | ||
globalTimeoutConfig.unmount = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setUnloadMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(19, "unload max time must be a positive integer number of milliseconds")); | ||
} | ||
var bootstrapPromise = loadPromise.then(function () { | ||
return toBootstrapPromise(parcel, true); | ||
}); | ||
var mountPromise = bootstrapPromise.then(function () { | ||
return toMountPromise(parcel, true); | ||
}); | ||
var resolveUnmount, rejectUnmount; | ||
var unmountPromise = new Promise(function (resolve, reject) { | ||
resolveUnmount = resolve; | ||
rejectUnmount = reject; | ||
}); | ||
externalRepresentation = { | ||
mount: function mount() { | ||
return promiseWithoutReturnValue(Promise.resolve().then(function () { | ||
if (parcel.status !== NOT_MOUNTED) { | ||
throw Error(formatErrorMessage(13, "Cannot mount parcel '".concat(name, "' -- it is in a ").concat(parcel.status, " status"), name, parcel.status)); | ||
} // Add to owning app or parcel | ||
globalTimeoutConfig.unload = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function reasonableTime(appOrParcel, lifecycle) { | ||
var timeoutConfig = appOrParcel.timeouts[lifecycle]; | ||
var warningPeriod = timeoutConfig.warningMillis; | ||
var type = objectType(appOrParcel); | ||
return new Promise(function (resolve, reject) { | ||
var finished = false; | ||
var errored = false; | ||
appOrParcel[lifecycle](getProps(appOrParcel)).then(function (val) { | ||
finished = true; | ||
resolve(val); | ||
}).catch(function (val) { | ||
finished = true; | ||
reject(val); | ||
}); | ||
setTimeout(function () { | ||
return maybeTimingOut(1); | ||
}, warningPeriod); | ||
setTimeout(function () { | ||
return maybeTimingOut(true); | ||
}, timeoutConfig.millis); | ||
var errMsg = formatErrorMessage(31, "Lifecycle function ".concat(lifecycle, " for ").concat(type, " ").concat(toName(appOrParcel), " lifecycle did not resolve or reject for ").concat(timeoutConfig.millis, " ms."), lifecycle, type, toName(appOrParcel), timeoutConfig.millis); | ||
function maybeTimingOut(shouldError) { | ||
if (!finished) { | ||
if (shouldError === true) { | ||
errored = true; | ||
owningAppOrParcel.parcels[id] = parcel; | ||
return toMountPromise(parcel); | ||
})); | ||
}, | ||
unmount: function unmount() { | ||
return promiseWithoutReturnValue(parcel.unmountThisParcel()); | ||
}, | ||
getStatus: function getStatus() { | ||
return parcel.status; | ||
}, | ||
loadPromise: promiseWithoutReturnValue(loadPromise), | ||
bootstrapPromise: promiseWithoutReturnValue(bootstrapPromise), | ||
mountPromise: promiseWithoutReturnValue(mountPromise), | ||
unmountPromise: promiseWithoutReturnValue(unmountPromise) | ||
}; | ||
return externalRepresentation; | ||
} | ||
if (timeoutConfig.dieOnTimeout) { | ||
reject(Error(errMsg)); | ||
} else { | ||
console.error(errMsg); //don't resolve or reject, we're waiting this one out | ||
} | ||
} else if (!errored) { | ||
var numWarnings = shouldError; | ||
var numMillis = numWarnings * warningPeriod; | ||
console.warn(errMsg); | ||
function promiseWithoutReturnValue(promise) { | ||
return promise.then(function () { | ||
return null; | ||
}); | ||
} | ||
if (numMillis + warningPeriod < timeoutConfig.millis) { | ||
setTimeout(function () { | ||
return maybeTimingOut(numWarnings + 1); | ||
}, warningPeriod); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
function ensureValidAppTimeouts(timeouts) { | ||
var result = {}; | ||
function getProps(appOrParcel) { | ||
var result = assign({}, appOrParcel.customProps, { | ||
name: toName(appOrParcel), | ||
mountParcel: mountParcel.bind(appOrParcel), | ||
singleSpa: singleSpa | ||
}); | ||
for (var key in globalTimeoutConfig) { | ||
result[key] = assign({}, globalTimeoutConfig[key], timeouts && timeouts[key] || {}); | ||
} | ||
if (isParcel(appOrParcel)) { | ||
result.unmountSelf = appOrParcel.unmountThisParcel; | ||
} | ||
return result; | ||
} | ||
return result; | ||
} | ||
function toLoadPromise(app) { | ||
return Promise.resolve().then(function () { | ||
if (app.loadPromise) { | ||
return app.loadPromise; | ||
} | ||
var defaultWarningMillis = 1000; | ||
var globalTimeoutConfig = { | ||
bootstrap: { | ||
millis: 4000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
mount: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
unmount: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
unload: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
update: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
} | ||
}; | ||
function setBootstrapMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(16, "bootstrap max time must be a positive integer number of milliseconds")); | ||
} | ||
if (app.status !== NOT_LOADED && app.status !== LOAD_ERROR) { | ||
return app; | ||
} | ||
globalTimeoutConfig.bootstrap = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setMountMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(17, "mount max time must be a positive integer number of milliseconds")); | ||
} | ||
app.status = LOADING_SOURCE_CODE; | ||
var appOpts, isUserErr; | ||
return app.loadPromise = Promise.resolve().then(function () { | ||
var loadPromise = app.loadApp(getProps(app)); | ||
globalTimeoutConfig.mount = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setUnmountMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(18, "unmount max time must be a positive integer number of milliseconds")); | ||
} | ||
if (!smellsLikeAPromise(loadPromise)) { | ||
// The name of the app will be prepended to this error message inside of the handleAppError function | ||
isUserErr = true; | ||
throw Error(formatErrorMessage(33, "single-spa loading function did not return a promise. Check the second argument to registerApplication('".concat(toName(app), "', loadingFunction, activityFunction)"), toName(app))); | ||
} | ||
globalTimeoutConfig.unmount = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setUnloadMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(19, "unload max time must be a positive integer number of milliseconds")); | ||
} | ||
return loadPromise.then(function (val) { | ||
app.loadErrorTime = null; | ||
appOpts = val; | ||
var validationErrMessage, validationErrCode; | ||
globalTimeoutConfig.unload = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function reasonableTime(appOrParcel, lifecycle) { | ||
var timeoutConfig = appOrParcel.timeouts[lifecycle]; | ||
var warningPeriod = timeoutConfig.warningMillis; | ||
var type = objectType(appOrParcel); | ||
return new Promise(function (resolve, reject) { | ||
var finished = false; | ||
var errored = false; | ||
appOrParcel[lifecycle](getProps(appOrParcel)).then(function (val) { | ||
finished = true; | ||
resolve(val); | ||
}).catch(function (val) { | ||
finished = true; | ||
reject(val); | ||
}); | ||
setTimeout(function () { | ||
return maybeTimingOut(1); | ||
}, warningPeriod); | ||
setTimeout(function () { | ||
return maybeTimingOut(true); | ||
}, timeoutConfig.millis); | ||
var errMsg = formatErrorMessage(31, "Lifecycle function ".concat(lifecycle, " for ").concat(type, " ").concat(toName(appOrParcel), " lifecycle did not resolve or reject for ").concat(timeoutConfig.millis, " ms."), lifecycle, type, toName(appOrParcel), timeoutConfig.millis); | ||
if (_typeof(appOpts) !== "object") { | ||
validationErrCode = 34; | ||
function maybeTimingOut(shouldError) { | ||
if (!finished) { | ||
if (shouldError === true) { | ||
errored = true; | ||
{ | ||
validationErrMessage = "does not export anything"; | ||
} | ||
} | ||
if (timeoutConfig.dieOnTimeout) { | ||
reject(Error(errMsg)); | ||
} else { | ||
console.error(errMsg); //don't resolve or reject, we're waiting this one out | ||
} | ||
} else if (!errored) { | ||
var numWarnings = shouldError; | ||
var numMillis = numWarnings * warningPeriod; | ||
console.warn(errMsg); | ||
if (!validLifecycleFn(appOpts.bootstrap)) { | ||
validationErrCode = 35; | ||
if (numMillis + warningPeriod < timeoutConfig.millis) { | ||
setTimeout(function () { | ||
return maybeTimingOut(numWarnings + 1); | ||
}, warningPeriod); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
function ensureValidAppTimeouts(timeouts) { | ||
var result = {}; | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
for (var key in globalTimeoutConfig) { | ||
result[key] = assign({}, globalTimeoutConfig[key], timeouts && timeouts[key] || {}); | ||
} | ||
if (!validLifecycleFn(appOpts.mount)) { | ||
validationErrCode = 36; | ||
return result; | ||
} | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
function toLoadPromise(app) { | ||
return Promise.resolve().then(function () { | ||
if (app.loadPromise) { | ||
return app.loadPromise; | ||
} | ||
if (!validLifecycleFn(appOpts.unmount)) { | ||
validationErrCode = 37; | ||
if (app.status !== NOT_LOADED && app.status !== LOAD_ERROR) { | ||
return app; | ||
} | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
app.status = LOADING_SOURCE_CODE; | ||
var appOpts, isUserErr; | ||
return app.loadPromise = Promise.resolve().then(function () { | ||
var loadPromise = app.loadApp(getProps(app)); | ||
var type = objectType(appOpts); | ||
if (!smellsLikeAPromise(loadPromise)) { | ||
// The name of the app will be prepended to this error message inside of the handleAppError function | ||
isUserErr = true; | ||
throw Error(formatErrorMessage(33, "single-spa loading function did not return a promise. Check the second argument to registerApplication('".concat(toName(app), "', loadingFunction, activityFunction)"), toName(app))); | ||
} | ||
if (validationErrCode) { | ||
var appOptsStr; | ||
return loadPromise.then(function (val) { | ||
app.loadErrorTime = null; | ||
appOpts = val; | ||
var validationErrMessage, validationErrCode; | ||
try { | ||
appOptsStr = JSON.stringify(appOpts); | ||
} catch (_unused) {} | ||
if (_typeof(appOpts) !== "object") { | ||
validationErrCode = 34; | ||
console.error(formatErrorMessage(validationErrCode, "The loading function for single-spa ".concat(type, " '").concat(toName(app), "' resolved with the following, which does not have bootstrap, mount, and unmount functions"), type, toName(app), appOptsStr), appOpts); | ||
handleAppError(validationErrMessage, app, SKIP_BECAUSE_BROKEN); | ||
return app; | ||
} | ||
{ | ||
validationErrMessage = "does not export anything"; | ||
} | ||
} | ||
if (appOpts.devtools && appOpts.devtools.overlays) { | ||
app.devtools.overlays = assign({}, app.devtools.overlays, appOpts.devtools.overlays); | ||
} | ||
if (!validLifecycleFn(appOpts.bootstrap)) { | ||
validationErrCode = 35; | ||
app.status = NOT_BOOTSTRAPPED; | ||
app.bootstrap = flattenFnArray(appOpts, "bootstrap"); | ||
app.mount = flattenFnArray(appOpts, "mount"); | ||
app.unmount = flattenFnArray(appOpts, "unmount"); | ||
app.unload = flattenFnArray(appOpts, "unload"); | ||
app.timeouts = ensureValidAppTimeouts(appOpts.timeouts); | ||
delete app.loadPromise; | ||
return app; | ||
}); | ||
}).catch(function (err) { | ||
delete app.loadPromise; | ||
var newStatus; | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
if (isUserErr) { | ||
newStatus = SKIP_BECAUSE_BROKEN; | ||
} else { | ||
newStatus = LOAD_ERROR; | ||
app.loadErrorTime = new Date().getTime(); | ||
} | ||
if (!validLifecycleFn(appOpts.mount)) { | ||
validationErrCode = 36; | ||
handleAppError(err, app, newStatus); | ||
return app; | ||
}); | ||
}); | ||
} | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
var isInBrowser = typeof window !== "undefined"; | ||
if (!validLifecycleFn(appOpts.unmount)) { | ||
validationErrCode = 37; | ||
/* We capture navigation event listeners so that we can make sure | ||
* that application navigation listeners are not called until | ||
* single-spa has ensured that the correct applications are | ||
* unmounted and mounted. | ||
*/ | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
var capturedEventListeners = { | ||
hashchange: [], | ||
popstate: [] | ||
}; | ||
var routingEventsListeningTo = ["hashchange", "popstate"]; | ||
function navigateToUrl(obj) { | ||
var url; | ||
var type = objectType(appOpts); | ||
if (typeof obj === "string") { | ||
url = obj; | ||
} else if (this && this.href) { | ||
url = this.href; | ||
} else if (obj && obj.currentTarget && obj.currentTarget.href && obj.preventDefault) { | ||
url = obj.currentTarget.href; | ||
obj.preventDefault(); | ||
} else { | ||
throw Error(formatErrorMessage(14, "singleSpaNavigate/navigateToUrl must be either called with a string url, with an <a> tag as its context, or with an event whose currentTarget is an <a> tag")); | ||
} | ||
if (validationErrCode) { | ||
var appOptsStr; | ||
var current = parseUri(window.location.href); | ||
var destination = parseUri(url); | ||
try { | ||
appOptsStr = JSON.stringify(appOpts); | ||
} catch (_unused) {} | ||
if (url.indexOf("#") === 0) { | ||
window.location.hash = destination.hash; | ||
} else if (current.host !== destination.host && destination.host) { | ||
{ | ||
window.location.href = url; | ||
} | ||
} else if (destination.pathname === current.pathname && destination.search === current.pathname) { | ||
window.location.hash = destination.hash; | ||
} else { | ||
// different path, host, or query params | ||
window.history.pushState(null, null, url); | ||
} | ||
} | ||
function callCapturedEventListeners(eventArguments) { | ||
var _this = this; | ||
console.error(formatErrorMessage(validationErrCode, "The loading function for single-spa ".concat(type, " '").concat(toName(app), "' resolved with the following, which does not have bootstrap, mount, and unmount functions"), type, toName(app), appOptsStr), appOpts); | ||
handleAppError(validationErrMessage, app, SKIP_BECAUSE_BROKEN); | ||
return app; | ||
} | ||
if (eventArguments) { | ||
var eventType = eventArguments[0].type; | ||
if (appOpts.devtools && appOpts.devtools.overlays) { | ||
app.devtools.overlays = assign({}, app.devtools.overlays, appOpts.devtools.overlays); | ||
} | ||
if (routingEventsListeningTo.indexOf(eventType) >= 0) { | ||
capturedEventListeners[eventType].forEach(function (listener) { | ||
try { | ||
// The error thrown by application event listener should not break single-spa down. | ||
// Just like https://github.com/single-spa/single-spa/blob/85f5042dff960e40936f3a5069d56fc9477fac04/src/navigation/reroute.js#L140-L146 did | ||
listener.apply(_this, eventArguments); | ||
} catch (e) { | ||
setTimeout(function () { | ||
throw e; | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
var urlRerouteOnly; | ||
function setUrlRerouteOnly(val) { | ||
urlRerouteOnly = val; | ||
} | ||
app.status = NOT_BOOTSTRAPPED; | ||
app.bootstrap = flattenFnArray(appOpts, "bootstrap"); | ||
app.mount = flattenFnArray(appOpts, "mount"); | ||
app.unmount = flattenFnArray(appOpts, "unmount"); | ||
app.unload = flattenFnArray(appOpts, "unload"); | ||
app.timeouts = ensureValidAppTimeouts(appOpts.timeouts); | ||
delete app.loadPromise; | ||
return app; | ||
}); | ||
}).catch(function (err) { | ||
delete app.loadPromise; | ||
var newStatus; | ||
function urlReroute() { | ||
reroute([], arguments); | ||
} | ||
if (isUserErr) { | ||
newStatus = SKIP_BECAUSE_BROKEN; | ||
} else { | ||
newStatus = LOAD_ERROR; | ||
app.loadErrorTime = new Date().getTime(); | ||
} | ||
if (isInBrowser) { | ||
// We will trigger an app change for any routing events. | ||
window.addEventListener("hashchange", urlReroute); | ||
window.addEventListener("popstate", urlReroute); // Monkeypatch addEventListener so that we can ensure correct timing | ||
handleAppError(err, app, newStatus); | ||
return app; | ||
}); | ||
}); | ||
} | ||
var originalAddEventListener = window.addEventListener; | ||
var originalRemoveEventListener = window.removeEventListener; | ||
var isInBrowser = typeof window !== "undefined"; | ||
window.addEventListener = function (eventName, fn) { | ||
if (typeof fn === "function") { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0 && !find(capturedEventListeners[eventName], function (listener) { | ||
return listener === fn; | ||
})) { | ||
capturedEventListeners[eventName].push(fn); | ||
return; | ||
} | ||
} | ||
/* We capture navigation event listeners so that we can make sure | ||
* that application navigation listeners are not called until | ||
* single-spa has ensured that the correct applications are | ||
* unmounted and mounted. | ||
*/ | ||
return originalAddEventListener.apply(this, arguments); | ||
}; | ||
var capturedEventListeners = { | ||
hashchange: [], | ||
popstate: [] | ||
}; | ||
var routingEventsListeningTo = ["hashchange", "popstate"]; | ||
function navigateToUrl(obj) { | ||
var url; | ||
window.removeEventListener = function (eventName, listenerFn) { | ||
if (typeof listenerFn === "function") { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0) { | ||
capturedEventListeners[eventName] = capturedEventListeners[eventName].filter(function (fn) { | ||
return fn !== listenerFn; | ||
}); | ||
return; | ||
} | ||
} | ||
if (typeof obj === "string") { | ||
url = obj; | ||
} else if (this && this.href) { | ||
url = this.href; | ||
} else if (obj && obj.currentTarget && obj.currentTarget.href && obj.preventDefault) { | ||
url = obj.currentTarget.href; | ||
obj.preventDefault(); | ||
} else { | ||
throw Error(formatErrorMessage(14, "singleSpaNavigate/navigateToUrl must be either called with a string url, with an <a> tag as its context, or with an event whose currentTarget is an <a> tag")); | ||
} | ||
return originalRemoveEventListener.apply(this, arguments); | ||
}; | ||
var current = parseUri(window.location.href); | ||
var destination = parseUri(url); | ||
window.history.pushState = patchedUpdateState(window.history.pushState); | ||
window.history.replaceState = patchedUpdateState(window.history.replaceState); | ||
if (url.indexOf("#") === 0) { | ||
window.location.hash = destination.hash; | ||
} else if (current.host !== destination.host && destination.host) { | ||
{ | ||
window.location.href = url; | ||
} | ||
} else if (destination.pathname === current.pathname && destination.search === current.pathname) { | ||
window.location.hash = destination.hash; | ||
} else { | ||
// different path, host, or query params | ||
window.history.pushState(null, null, url); | ||
} | ||
} | ||
function callCapturedEventListeners(eventArguments) { | ||
var _this = this; | ||
function patchedUpdateState(updateState) { | ||
return function () { | ||
var urlBefore = window.location.href; | ||
var result = updateState.apply(this, arguments); | ||
var urlAfter = window.location.href; | ||
if (eventArguments) { | ||
var eventType = eventArguments[0].type; | ||
if (!urlRerouteOnly || urlBefore !== urlAfter) { | ||
urlReroute(createPopStateEvent(window.history.state)); | ||
} | ||
if (routingEventsListeningTo.indexOf(eventType) >= 0) { | ||
capturedEventListeners[eventType].forEach(function (listener) { | ||
try { | ||
// The error thrown by application event listener should not break single-spa down. | ||
// Just like https://github.com/single-spa/single-spa/blob/85f5042dff960e40936f3a5069d56fc9477fac04/src/navigation/reroute.js#L140-L146 did | ||
listener.apply(_this, eventArguments); | ||
} catch (e) { | ||
setTimeout(function () { | ||
throw e; | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
var urlRerouteOnly; | ||
function setUrlRerouteOnly(val) { | ||
urlRerouteOnly = val; | ||
} | ||
return result; | ||
}; | ||
} | ||
function urlReroute() { | ||
reroute([], arguments); | ||
} | ||
function createPopStateEvent(state) { | ||
// https://github.com/single-spa/single-spa/issues/224 and https://github.com/single-spa/single-spa-angular/issues/49 | ||
// We need a popstate event even though the browser doesn't do one by default when you call replaceState, so that | ||
// all the applications can reroute. | ||
try { | ||
return new PopStateEvent("popstate", { | ||
state: state | ||
}); | ||
} catch (err) { | ||
// IE 11 compatibility https://github.com/single-spa/single-spa/issues/299 | ||
// https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-html5e/bd560f47-b349-4d2c-baa8-f1560fb489dd | ||
var evt = document.createEvent("PopStateEvent"); | ||
evt.initPopStateEvent("popstate", false, false, state); | ||
return evt; | ||
} | ||
} | ||
/* For convenience in `onclick` attributes, we expose a global function for navigating to | ||
* whatever an <a> tag's href is. | ||
*/ | ||
if (isInBrowser) { | ||
// We will trigger an app change for any routing events. | ||
window.addEventListener("hashchange", urlReroute); | ||
window.addEventListener("popstate", urlReroute); // Monkeypatch addEventListener so that we can ensure correct timing | ||
var originalAddEventListener = window.addEventListener; | ||
var originalRemoveEventListener = window.removeEventListener; | ||
window.singleSpaNavigate = navigateToUrl; | ||
} | ||
window.addEventListener = function (eventName, fn) { | ||
if (typeof fn === "function") { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0 && !find(capturedEventListeners[eventName], function (listener) { | ||
return listener === fn; | ||
})) { | ||
capturedEventListeners[eventName].push(fn); | ||
return; | ||
} | ||
} | ||
function parseUri(str) { | ||
var anchor = document.createElement("a"); | ||
anchor.href = str; | ||
return anchor; | ||
} | ||
return originalAddEventListener.apply(this, arguments); | ||
}; | ||
var hasInitialized = false; | ||
function ensureJQuerySupport() { | ||
var jQuery = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.jQuery; | ||
window.removeEventListener = function (eventName, listenerFn) { | ||
if (typeof listenerFn === "function") { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0) { | ||
capturedEventListeners[eventName] = capturedEventListeners[eventName].filter(function (fn) { | ||
return fn !== listenerFn; | ||
}); | ||
return; | ||
} | ||
} | ||
if (!jQuery) { | ||
if (window.$ && window.$.fn && window.$.fn.jquery) { | ||
jQuery = window.$; | ||
} | ||
} | ||
return originalRemoveEventListener.apply(this, arguments); | ||
}; | ||
if (jQuery && !hasInitialized) { | ||
var originalJQueryOn = jQuery.fn.on; | ||
var originalJQueryOff = jQuery.fn.off; | ||
window.history.pushState = patchedUpdateState(window.history.pushState); | ||
window.history.replaceState = patchedUpdateState(window.history.replaceState); | ||
jQuery.fn.on = function (eventString, fn) { | ||
return captureRoutingEvents.call(this, originalJQueryOn, window.addEventListener, eventString, fn, arguments); | ||
}; | ||
function patchedUpdateState(updateState) { | ||
return function () { | ||
var urlBefore = window.location.href; | ||
var result = updateState.apply(this, arguments); | ||
var urlAfter = window.location.href; | ||
jQuery.fn.off = function (eventString, fn) { | ||
return captureRoutingEvents.call(this, originalJQueryOff, window.removeEventListener, eventString, fn, arguments); | ||
}; | ||
if (!urlRerouteOnly || urlBefore !== urlAfter) { | ||
urlReroute(createPopStateEvent(window.history.state)); | ||
} | ||
hasInitialized = true; | ||
} | ||
} | ||
return result; | ||
}; | ||
} | ||
function captureRoutingEvents(originalJQueryFunction, nativeFunctionToCall, eventString, fn, originalArgs) { | ||
if (typeof eventString !== "string") { | ||
return originalJQueryFunction.apply(this, originalArgs); | ||
} | ||
function createPopStateEvent(state) { | ||
// https://github.com/single-spa/single-spa/issues/224 and https://github.com/single-spa/single-spa-angular/issues/49 | ||
// We need a popstate event even though the browser doesn't do one by default when you call replaceState, so that | ||
// all the applications can reroute. | ||
try { | ||
return new PopStateEvent("popstate", { | ||
state: state | ||
}); | ||
} catch (err) { | ||
// IE 11 compatibility https://github.com/single-spa/single-spa/issues/299 | ||
// https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-html5e/bd560f47-b349-4d2c-baa8-f1560fb489dd | ||
var evt = document.createEvent("PopStateEvent"); | ||
evt.initPopStateEvent("popstate", false, false, state); | ||
return evt; | ||
} | ||
} | ||
/* For convenience in `onclick` attributes, we expose a global function for navigating to | ||
* whatever an <a> tag's href is. | ||
*/ | ||
var eventNames = eventString.split(/\s+/); | ||
eventNames.forEach(function (eventName) { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0) { | ||
nativeFunctionToCall(eventName, fn); | ||
eventString = eventString.replace(eventName, ""); | ||
} | ||
}); | ||
if (eventString.trim() === "") { | ||
return this; | ||
} else { | ||
return originalJQueryFunction.apply(this, originalArgs); | ||
} | ||
} | ||
window.singleSpaNavigate = navigateToUrl; | ||
} | ||
var appsToUnload = {}; | ||
function toUnloadPromise(app) { | ||
return Promise.resolve().then(function () { | ||
var unloadInfo = appsToUnload[toName(app)]; | ||
function parseUri(str) { | ||
var anchor = document.createElement("a"); | ||
anchor.href = str; | ||
return anchor; | ||
} | ||
if (!unloadInfo) { | ||
/* No one has called unloadApplication for this app, | ||
*/ | ||
return app; | ||
} | ||
var hasInitialized = false; | ||
function ensureJQuerySupport() { | ||
var jQuery = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.jQuery; | ||
if (app.status === NOT_LOADED) { | ||
/* This app is already unloaded. We just need to clean up | ||
* anything that still thinks we need to unload the app. | ||
*/ | ||
finishUnloadingApp(app, unloadInfo); | ||
return app; | ||
} | ||
if (!jQuery) { | ||
if (window.$ && window.$.fn && window.$.fn.jquery) { | ||
jQuery = window.$; | ||
} | ||
} | ||
if (app.status === UNLOADING) { | ||
/* Both unloadApplication and reroute want to unload this app. | ||
* It only needs to be done once, though. | ||
*/ | ||
return unloadInfo.promise.then(function () { | ||
return app; | ||
}); | ||
} | ||
if (jQuery && !hasInitialized) { | ||
var originalJQueryOn = jQuery.fn.on; | ||
var originalJQueryOff = jQuery.fn.off; | ||
if (app.status !== NOT_MOUNTED) { | ||
/* The app cannot be unloaded until it is unmounted. | ||
*/ | ||
return app; | ||
} | ||
jQuery.fn.on = function (eventString, fn) { | ||
return captureRoutingEvents.call(this, originalJQueryOn, window.addEventListener, eventString, fn, arguments); | ||
}; | ||
app.status = UNLOADING; | ||
return reasonableTime(app, "unload").then(function () { | ||
finishUnloadingApp(app, unloadInfo); | ||
return app; | ||
}).catch(function (err) { | ||
errorUnloadingApp(app, unloadInfo, err); | ||
return app; | ||
}); | ||
}); | ||
} | ||
jQuery.fn.off = function (eventString, fn) { | ||
return captureRoutingEvents.call(this, originalJQueryOff, window.removeEventListener, eventString, fn, arguments); | ||
}; | ||
function finishUnloadingApp(app, unloadInfo) { | ||
delete appsToUnload[toName(app)]; // Unloaded apps don't have lifecycles | ||
hasInitialized = true; | ||
} | ||
} | ||
delete app.bootstrap; | ||
delete app.mount; | ||
delete app.unmount; | ||
delete app.unload; | ||
app.status = NOT_LOADED; | ||
/* resolve the promise of whoever called unloadApplication. | ||
* This should be done after all other cleanup/bookkeeping | ||
*/ | ||
function captureRoutingEvents(originalJQueryFunction, nativeFunctionToCall, eventString, fn, originalArgs) { | ||
if (typeof eventString !== "string") { | ||
return originalJQueryFunction.apply(this, originalArgs); | ||
} | ||
unloadInfo.resolve(); | ||
} | ||
var eventNames = eventString.split(/\s+/); | ||
eventNames.forEach(function (eventName) { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0) { | ||
nativeFunctionToCall(eventName, fn); | ||
eventString = eventString.replace(eventName, ""); | ||
} | ||
}); | ||
function errorUnloadingApp(app, unloadInfo, err) { | ||
delete appsToUnload[toName(app)]; // Unloaded apps don't have lifecycles | ||
if (eventString.trim() === "") { | ||
return this; | ||
} else { | ||
return originalJQueryFunction.apply(this, originalArgs); | ||
} | ||
} | ||
delete app.bootstrap; | ||
delete app.mount; | ||
delete app.unmount; | ||
delete app.unload; | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
unloadInfo.reject(err); | ||
} | ||
var appsToUnload = {}; | ||
function toUnloadPromise(app) { | ||
return Promise.resolve().then(function () { | ||
var unloadInfo = appsToUnload[toName(app)]; | ||
function addAppToUnload(app, promiseGetter, resolve, reject) { | ||
appsToUnload[toName(app)] = { | ||
app: app, | ||
resolve: resolve, | ||
reject: reject | ||
}; | ||
Object.defineProperty(appsToUnload[toName(app)], "promise", { | ||
get: promiseGetter | ||
}); | ||
} | ||
function getAppUnloadInfo(appName) { | ||
return appsToUnload[appName]; | ||
} | ||
function getAppsToUnload() { | ||
return Object.keys(appsToUnload).map(function (appName) { | ||
return appsToUnload[appName].app; | ||
}).filter(isntActive); | ||
} | ||
if (!unloadInfo) { | ||
/* No one has called unloadApplication for this app, | ||
*/ | ||
return app; | ||
} | ||
var apps = []; | ||
function getMountedApps() { | ||
return apps.filter(isActive).map(toName); | ||
} | ||
function getAppNames() { | ||
return apps.map(toName); | ||
} // used in devtools, not (currently) exposed as a single-spa API | ||
if (app.status === NOT_LOADED) { | ||
/* This app is already unloaded. We just need to clean up | ||
* anything that still thinks we need to unload the app. | ||
*/ | ||
finishUnloadingApp(app, unloadInfo); | ||
return app; | ||
} | ||
function getRawAppData() { | ||
return [].concat(apps); | ||
} | ||
function getAppStatus(appName) { | ||
var app = find(apps, function (app) { | ||
return toName(app) === appName; | ||
}); | ||
return app ? app.status : null; | ||
} | ||
function registerApplication(appNameOrConfig, appOrLoadApp, activeWhen, customProps) { | ||
var registration = sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps); | ||
if (getAppNames().indexOf(registration.name) !== -1) throw Error(formatErrorMessage(21, "There is already an app registered with name ".concat(registration.name), registration.name)); | ||
apps.push(assign({ | ||
loadErrorTime: null, | ||
status: NOT_LOADED, | ||
parcels: {}, | ||
devtools: { | ||
overlays: { | ||
options: {}, | ||
selectors: [] | ||
} | ||
} | ||
}, registration)); | ||
if (app.status === UNLOADING) { | ||
/* Both unloadApplication and reroute want to unload this app. | ||
* It only needs to be done once, though. | ||
*/ | ||
return unloadInfo.promise.then(function () { | ||
return app; | ||
}); | ||
} | ||
if (isInBrowser) { | ||
ensureJQuerySupport(); | ||
reroute(); | ||
} | ||
} | ||
function checkActivityFunctions(location) { | ||
return apps.filter(function (app) { | ||
return app.activeWhen(location); | ||
}).map(toName); | ||
} | ||
function getAppsToLoad() { | ||
return apps.filter(notSkipped).filter(withoutLoadErrors).filter(isntLoaded).filter(shouldBeActive); | ||
} | ||
function getAppsToUnmount() { | ||
return apps.filter(notSkipped).filter(isActive).filter(shouldntBeActive); | ||
} | ||
function getAppsToMount() { | ||
return apps.filter(notSkipped).filter(isntActive).filter(isLoaded).filter(shouldBeActive); | ||
} | ||
function unregisterApplication(appName) { | ||
if (!apps.find(function (app) { | ||
return toName(app) === appName; | ||
})) { | ||
throw Error(formatErrorMessage(25, "Cannot unregister application '".concat(appName, "' because no such application has been registered"), appName)); | ||
} | ||
if (app.status !== NOT_MOUNTED) { | ||
/* The app cannot be unloaded until it is unmounted. | ||
*/ | ||
return app; | ||
} | ||
return unloadApplication(appName).then(function () { | ||
var appIndex = apps.findIndex(function (app) { | ||
return toName(app) === appName; | ||
}); | ||
apps.splice(appIndex, 1); | ||
}); | ||
} | ||
function unloadApplication(appName) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
waitForUnmount: false | ||
}; | ||
app.status = UNLOADING; | ||
return reasonableTime(app, "unload").then(function () { | ||
finishUnloadingApp(app, unloadInfo); | ||
return app; | ||
}).catch(function (err) { | ||
errorUnloadingApp(app, unloadInfo, err); | ||
return app; | ||
}); | ||
}); | ||
} | ||
if (typeof appName !== "string") { | ||
throw Error(formatErrorMessage(26, "unloadApplication requires a string 'appName'")); | ||
} | ||
function finishUnloadingApp(app, unloadInfo) { | ||
delete appsToUnload[toName(app)]; // Unloaded apps don't have lifecycles | ||
var app = find(apps, function (App) { | ||
return toName(App) === appName; | ||
}); | ||
delete app.bootstrap; | ||
delete app.mount; | ||
delete app.unmount; | ||
delete app.unload; | ||
app.status = NOT_LOADED; | ||
/* resolve the promise of whoever called unloadApplication. | ||
* This should be done after all other cleanup/bookkeeping | ||
*/ | ||
if (!app) { | ||
throw Error(formatErrorMessage(27, "Could not unload application '".concat(appName, "' because no such application has been registered"), appName)); | ||
} | ||
unloadInfo.resolve(); | ||
} | ||
var appUnloadInfo = getAppUnloadInfo(toName(app)); | ||
function errorUnloadingApp(app, unloadInfo, err) { | ||
delete appsToUnload[toName(app)]; // Unloaded apps don't have lifecycles | ||
if (opts && opts.waitForUnmount) { | ||
// We need to wait for unmount before unloading the app | ||
if (appUnloadInfo) { | ||
// Someone else is already waiting for this, too | ||
return appUnloadInfo.promise; | ||
} else { | ||
// We're the first ones wanting the app to be resolved. | ||
var promise = new Promise(function (resolve, reject) { | ||
addAppToUnload(app, function () { | ||
return promise; | ||
}, resolve, reject); | ||
}); | ||
return promise; | ||
} | ||
} else { | ||
/* We should unmount the app, unload it, and remount it immediately. | ||
*/ | ||
var resultPromise; | ||
delete app.bootstrap; | ||
delete app.mount; | ||
delete app.unmount; | ||
delete app.unload; | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
unloadInfo.reject(err); | ||
} | ||
if (appUnloadInfo) { | ||
// Someone else is already waiting for this app to unload | ||
resultPromise = appUnloadInfo.promise; | ||
immediatelyUnloadApp(app, appUnloadInfo.resolve, appUnloadInfo.reject); | ||
} else { | ||
// We're the first ones wanting the app to be resolved. | ||
resultPromise = new Promise(function (resolve, reject) { | ||
addAppToUnload(app, function () { | ||
return resultPromise; | ||
}, resolve, reject); | ||
immediatelyUnloadApp(app, resolve, reject); | ||
}); | ||
} | ||
function addAppToUnload(app, promiseGetter, resolve, reject) { | ||
appsToUnload[toName(app)] = { | ||
app: app, | ||
resolve: resolve, | ||
reject: reject | ||
}; | ||
Object.defineProperty(appsToUnload[toName(app)], "promise", { | ||
get: promiseGetter | ||
}); | ||
} | ||
function getAppUnloadInfo(appName) { | ||
return appsToUnload[appName]; | ||
} | ||
function getAppsToUnload() { | ||
return Object.keys(appsToUnload).map(function (appName) { | ||
return appsToUnload[appName].app; | ||
}).filter(isntActive); | ||
} | ||
return resultPromise; | ||
} | ||
} | ||
var apps = []; | ||
function getMountedApps() { | ||
return apps.filter(isActive).map(toName); | ||
} | ||
function getAppNames() { | ||
return apps.map(toName); | ||
} // used in devtools, not (currently) exposed as a single-spa API | ||
function immediatelyUnloadApp(app, resolve, reject) { | ||
toUnmountPromise(app).then(toUnloadPromise).then(function () { | ||
resolve(); | ||
setTimeout(function () { | ||
// reroute, but the unload promise is done | ||
reroute(); | ||
}); | ||
}).catch(reject); | ||
} | ||
function getRawAppData() { | ||
return [].concat(apps); | ||
} | ||
function getAppStatus(appName) { | ||
var app = find(apps, function (app) { | ||
return toName(app) === appName; | ||
}); | ||
return app ? app.status : null; | ||
} | ||
function registerApplication(appNameOrConfig, appOrLoadApp, activeWhen, customProps) { | ||
var registration = sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps); | ||
if (getAppNames().indexOf(registration.name) !== -1) throw Error(formatErrorMessage(21, "There is already an app registered with name ".concat(registration.name), registration.name)); | ||
apps.push(assign({ | ||
loadErrorTime: null, | ||
status: NOT_LOADED, | ||
parcels: {}, | ||
devtools: { | ||
overlays: { | ||
options: {}, | ||
selectors: [] | ||
} | ||
} | ||
}, registration)); | ||
function validateRegisterWithArguments(name, appOrLoadApp, activeWhen, customProps) { | ||
if (typeof name !== "string" || name.length === 0) throw Error(formatErrorMessage(20, "The 1st argument to registerApplication must be a non-empty string 'appName'")); | ||
if (!appOrLoadApp) throw Error(formatErrorMessage(23, "The 2nd argument to registerApplication must be an application or loading application function")); | ||
if (typeof activeWhen !== "function") throw Error(formatErrorMessage(24, "The 3rd argument to registerApplication must be an activeWhen function")); | ||
if (!!customProps && (_typeof(customProps) !== "object" || Array.isArray(customProps))) throw Error(formatErrorMessage(22, "The optional 4th argument is a customProps and must be an object")); | ||
} | ||
if (isInBrowser) { | ||
ensureJQuerySupport(); | ||
reroute(); | ||
} | ||
} | ||
function checkActivityFunctions(location) { | ||
return apps.filter(function (app) { | ||
return app.activeWhen(location); | ||
}).map(toName); | ||
} | ||
function getAppsToLoad() { | ||
return apps.filter(notSkipped).filter(withoutLoadErrors).filter(isntLoaded).filter(shouldBeActive); | ||
} | ||
function getAppsToUnmount() { | ||
return apps.filter(notSkipped).filter(isActive).filter(shouldntBeActive); | ||
} | ||
function getAppsToMount() { | ||
return apps.filter(notSkipped).filter(isntActive).filter(isLoaded).filter(shouldBeActive); | ||
} | ||
function unregisterApplication(appName) { | ||
if (!apps.find(function (app) { | ||
return toName(app) === appName; | ||
})) { | ||
throw Error(formatErrorMessage(25, "Cannot unregister application '".concat(appName, "' because no such application has been registered"), appName)); | ||
} | ||
function validateRegisterWithConfig(config) { | ||
if (Array.isArray(config) || config === null) throw Error(formatErrorMessage(39, "Configuration object can't be an Array or null!")); | ||
var validKeys = ["name", "app", "activeWhen", "customProps"]; | ||
var invalidKeys = Object.keys(config).reduce(function (invalidKeys, prop) { | ||
return validKeys.includes(prop) ? invalidKeys : invalidKeys.concat(prop); | ||
}, []); | ||
if (invalidKeys.length !== 0) throw Error(formatErrorMessage(38, "The configuration object accepts only: ".concat(validKeys.join(", "), ". Invalid keys: ").concat(invalidKeys.join(", "), "."), validKeys.join(", "), invalidKeys.join(", "))); | ||
if (typeof config.name !== "string" || config.name.length === 0) throw Error(formatErrorMessage(20, "The config.name on registerApplication must be a non-empty string")); | ||
if (_typeof(config.app) !== "object" && typeof config.app !== "function") throw Error(formatErrorMessage(20, "The config.app on registerApplication must be an application or a loading function")); | ||
return unloadApplication(appName).then(function () { | ||
var appIndex = apps.findIndex(function (app) { | ||
return toName(app) === appName; | ||
}); | ||
apps.splice(appIndex, 1); | ||
}); | ||
} | ||
function unloadApplication(appName) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
waitForUnmount: false | ||
}; | ||
var allowsStringAndFunction = function allowsStringAndFunction(activeWhen) { | ||
return typeof activeWhen === "string" || typeof activeWhen === "function"; | ||
}; | ||
if (typeof appName !== "string") { | ||
throw Error(formatErrorMessage(26, "unloadApplication requires a string 'appName'")); | ||
} | ||
if (!allowsStringAndFunction(config.activeWhen) && !(Array.isArray(config.activeWhen) && config.activeWhen.every(allowsStringAndFunction))) throw Error(formatErrorMessage(24, "The config.activeWhen on registerApplication must be a string, function or an array with both")); | ||
if (!(!config.customProps || _typeof(config.customProps) === "object" && !Array.isArray(config.customProps))) throw Error(formatErrorMessage(22, "The optional config.customProps must be an object")); | ||
} | ||
var app = find(apps, function (App) { | ||
return toName(App) === appName; | ||
}); | ||
function sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps) { | ||
var usingObjectAPI = _typeof(appNameOrConfig) === "object"; | ||
var registration = { | ||
name: null, | ||
loadApp: null, | ||
activeWhen: null, | ||
customProps: null | ||
}; | ||
if (!app) { | ||
throw Error(formatErrorMessage(27, "Could not unload application '".concat(appName, "' because no such application has been registered"), appName)); | ||
} | ||
if (usingObjectAPI) { | ||
validateRegisterWithConfig(appNameOrConfig); | ||
registration.name = appNameOrConfig.name; | ||
registration.loadApp = appNameOrConfig.app; | ||
registration.activeWhen = appNameOrConfig.activeWhen; | ||
registration.customProps = appNameOrConfig.customProps; | ||
} else { | ||
validateRegisterWithArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps); | ||
registration.name = appNameOrConfig; | ||
registration.loadApp = appOrLoadApp; | ||
registration.activeWhen = activeWhen; | ||
registration.customProps = customProps; | ||
} | ||
var appUnloadInfo = getAppUnloadInfo(toName(app)); | ||
registration.loadApp = sanitizeLoadApp(registration.loadApp); | ||
registration.customProps = sanitizeCustomProps(registration.customProps); | ||
registration.activeWhen = sanitizeActiveWhen(registration.activeWhen); | ||
return registration; | ||
} | ||
if (opts && opts.waitForUnmount) { | ||
// We need to wait for unmount before unloading the app | ||
if (appUnloadInfo) { | ||
// Someone else is already waiting for this, too | ||
return appUnloadInfo.promise; | ||
} else { | ||
// We're the first ones wanting the app to be resolved. | ||
var promise = new Promise(function (resolve, reject) { | ||
addAppToUnload(app, function () { | ||
return promise; | ||
}, resolve, reject); | ||
}); | ||
return promise; | ||
} | ||
} else { | ||
/* We should unmount the app, unload it, and remount it immediately. | ||
*/ | ||
var resultPromise; | ||
function sanitizeLoadApp(loadApp) { | ||
if (typeof loadApp !== "function") { | ||
return function () { | ||
return Promise.resolve(loadApp); | ||
}; | ||
} | ||
if (appUnloadInfo) { | ||
// Someone else is already waiting for this app to unload | ||
resultPromise = appUnloadInfo.promise; | ||
immediatelyUnloadApp(app, appUnloadInfo.resolve, appUnloadInfo.reject); | ||
} else { | ||
// We're the first ones wanting the app to be resolved. | ||
resultPromise = new Promise(function (resolve, reject) { | ||
addAppToUnload(app, function () { | ||
return resultPromise; | ||
}, resolve, reject); | ||
immediatelyUnloadApp(app, resolve, reject); | ||
}); | ||
} | ||
return loadApp; | ||
} | ||
return resultPromise; | ||
} | ||
} | ||
function sanitizeCustomProps(customProps) { | ||
return customProps ? customProps : {}; | ||
} | ||
function immediatelyUnloadApp(app, resolve, reject) { | ||
toUnmountPromise(app).then(toUnloadPromise).then(function () { | ||
resolve(); | ||
setTimeout(function () { | ||
// reroute, but the unload promise is done | ||
reroute(); | ||
}); | ||
}).catch(reject); | ||
} | ||
function sanitizeActiveWhen(activeWhen) { | ||
var activeWhenArray = Array.isArray(activeWhen) ? activeWhen : [activeWhen]; | ||
activeWhenArray = activeWhenArray.map(function (activeWhenOrPath) { | ||
return typeof activeWhenOrPath === "function" ? activeWhenOrPath : pathToActiveWhen(activeWhenOrPath); | ||
}); | ||
return function (location) { | ||
return activeWhenArray.some(function (activeWhen) { | ||
return activeWhen(location); | ||
}); | ||
}; | ||
} | ||
function validateRegisterWithArguments(name, appOrLoadApp, activeWhen, customProps) { | ||
if (typeof name !== "string" || name.length === 0) throw Error(formatErrorMessage(20, "The 1st argument to registerApplication must be a non-empty string 'appName'")); | ||
if (!appOrLoadApp) throw Error(formatErrorMessage(23, "The 2nd argument to registerApplication must be an application or loading application function")); | ||
if (typeof activeWhen !== "function") throw Error(formatErrorMessage(24, "The 3rd argument to registerApplication must be an activeWhen function")); | ||
if (!!customProps && (_typeof(customProps) !== "object" || Array.isArray(customProps))) throw Error(formatErrorMessage(22, "The optional 4th argument is a customProps and must be an object")); | ||
} | ||
function pathToActiveWhen(path) { | ||
var regex = toDynamicPathValidatorRegex(path); | ||
return function (location) { | ||
var route = location.href.replace(location.origin, ""); | ||
return regex.test(route); | ||
}; | ||
} | ||
function validateRegisterWithConfig(config) { | ||
if (Array.isArray(config) || config === null) throw Error(formatErrorMessage(39, "Configuration object can't be an Array or null!")); | ||
var validKeys = ["name", "app", "activeWhen", "customProps"]; | ||
var invalidKeys = Object.keys(config).reduce(function (invalidKeys, prop) { | ||
return validKeys.includes(prop) ? invalidKeys : invalidKeys.concat(prop); | ||
}, []); | ||
if (invalidKeys.length !== 0) throw Error(formatErrorMessage(38, "The configuration object accepts only: ".concat(validKeys.join(", "), ". Invalid keys: ").concat(invalidKeys.join(", "), "."), validKeys.join(", "), invalidKeys.join(", "))); | ||
if (typeof config.name !== "string" || config.name.length === 0) throw Error(formatErrorMessage(20, "The config.name on registerApplication must be a non-empty string")); | ||
if (_typeof(config.app) !== "object" && typeof config.app !== "function") throw Error(formatErrorMessage(20, "The config.app on registerApplication must be an application or a loading function")); | ||
function toDynamicPathValidatorRegex(path) { | ||
var lastIndex = 0, | ||
inDynamic = false, | ||
regexStr = "^"; | ||
var allowsStringAndFunction = function allowsStringAndFunction(activeWhen) { | ||
return typeof activeWhen === "string" || typeof activeWhen === "function"; | ||
}; | ||
for (var charIndex = 0; charIndex < path.length; charIndex++) { | ||
var char = path[charIndex]; | ||
var startOfDynamic = !inDynamic && char === ":"; | ||
var endOfDynamic = inDynamic && char === "/"; | ||
if (!allowsStringAndFunction(config.activeWhen) && !(Array.isArray(config.activeWhen) && config.activeWhen.every(allowsStringAndFunction))) throw Error(formatErrorMessage(24, "The config.activeWhen on registerApplication must be a string, function or an array with both")); | ||
if (!(!config.customProps || _typeof(config.customProps) === "object" && !Array.isArray(config.customProps))) throw Error(formatErrorMessage(22, "The optional config.customProps must be an object")); | ||
} | ||
if (startOfDynamic || endOfDynamic) { | ||
appendToRegex(charIndex); | ||
} | ||
} | ||
function sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps) { | ||
var usingObjectAPI = _typeof(appNameOrConfig) === "object"; | ||
var registration = { | ||
name: null, | ||
loadApp: null, | ||
activeWhen: null, | ||
customProps: null | ||
}; | ||
appendToRegex(path.length); | ||
return new RegExp(regexStr, "i"); | ||
if (usingObjectAPI) { | ||
validateRegisterWithConfig(appNameOrConfig); | ||
registration.name = appNameOrConfig.name; | ||
registration.loadApp = appNameOrConfig.app; | ||
registration.activeWhen = appNameOrConfig.activeWhen; | ||
registration.customProps = appNameOrConfig.customProps; | ||
} else { | ||
validateRegisterWithArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps); | ||
registration.name = appNameOrConfig; | ||
registration.loadApp = appOrLoadApp; | ||
registration.activeWhen = activeWhen; | ||
registration.customProps = customProps; | ||
} | ||
function appendToRegex(index) { | ||
var anyCharMaybeTrailingSlashRegex = "[^/]+/?"; | ||
var commonStringSubPath = escapeStrRegex(path.slice(lastIndex, index)); | ||
regexStr += inDynamic ? anyCharMaybeTrailingSlashRegex : commonStringSubPath; | ||
inDynamic = !inDynamic; | ||
lastIndex = index; | ||
} | ||
registration.loadApp = sanitizeLoadApp(registration.loadApp); | ||
registration.customProps = sanitizeCustomProps(registration.customProps); | ||
registration.activeWhen = sanitizeActiveWhen(registration.activeWhen); | ||
return registration; | ||
} | ||
function escapeStrRegex(str) { | ||
// borrowed from https://github.com/sindresorhus/escape-string-regexp/blob/master/index.js | ||
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&"); | ||
} | ||
} | ||
function sanitizeLoadApp(loadApp) { | ||
if (typeof loadApp !== "function") { | ||
return function () { | ||
return Promise.resolve(loadApp); | ||
}; | ||
} | ||
var appChangeUnderway = false, | ||
peopleWaitingOnAppChange = []; | ||
function triggerAppChange() { | ||
// Call reroute with no arguments, intentionally | ||
return reroute(); | ||
} | ||
function reroute() { | ||
var pendingPromises = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var eventArguments = arguments.length > 1 ? arguments[1] : undefined; | ||
return loadApp; | ||
} | ||
if (appChangeUnderway) { | ||
return new Promise(function (resolve, reject) { | ||
peopleWaitingOnAppChange.push({ | ||
resolve: resolve, | ||
reject: reject, | ||
eventArguments: eventArguments | ||
}); | ||
}); | ||
} | ||
function sanitizeCustomProps(customProps) { | ||
return customProps ? customProps : {}; | ||
} | ||
var wasNoOp = true; | ||
function sanitizeActiveWhen(activeWhen) { | ||
var activeWhenArray = Array.isArray(activeWhen) ? activeWhen : [activeWhen]; | ||
activeWhenArray = activeWhenArray.map(function (activeWhenOrPath) { | ||
return typeof activeWhenOrPath === "function" ? activeWhenOrPath : pathToActiveWhen(activeWhenOrPath); | ||
}); | ||
return function (location) { | ||
return activeWhenArray.some(function (activeWhen) { | ||
return activeWhen(location); | ||
}); | ||
}; | ||
} | ||
if (isStarted()) { | ||
appChangeUnderway = true; | ||
return performAppChanges(); | ||
} else { | ||
return loadApps(); | ||
} | ||
function pathToActiveWhen(path) { | ||
var regex = toDynamicPathValidatorRegex(path); | ||
return function (location) { | ||
var route = location.href.replace(location.origin, ""); | ||
return regex.test(route); | ||
}; | ||
} | ||
function loadApps() { | ||
return Promise.resolve().then(function () { | ||
var loadPromises = getAppsToLoad().map(toLoadPromise); | ||
function toDynamicPathValidatorRegex(path) { | ||
var lastIndex = 0, | ||
inDynamic = false, | ||
regexStr = "^"; | ||
if (loadPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
for (var charIndex = 0; charIndex < path.length; charIndex++) { | ||
var char = path[charIndex]; | ||
var startOfDynamic = !inDynamic && char === ":"; | ||
var endOfDynamic = inDynamic && char === "/"; | ||
return Promise.all(loadPromises).then(callAllEventListeners) // there are no mounted apps, before start() is called, so we always return [] | ||
.then(function () { | ||
return []; | ||
}).catch(function (err) { | ||
callAllEventListeners(); | ||
throw err; | ||
}); | ||
}); | ||
} | ||
if (startOfDynamic || endOfDynamic) { | ||
appendToRegex(charIndex); | ||
} | ||
} | ||
function performAppChanges() { | ||
return Promise.resolve().then(function () { | ||
window.dispatchEvent(new customEvent("single-spa:before-routing-event", getCustomEventDetail())); | ||
var unloadPromises = getAppsToUnload().map(toUnloadPromise); | ||
var unmountUnloadPromises = getAppsToUnmount().map(toUnmountPromise).map(function (unmountPromise) { | ||
return unmountPromise.then(toUnloadPromise); | ||
}); | ||
var allUnmountPromises = unmountUnloadPromises.concat(unloadPromises); | ||
appendToRegex(path.length); | ||
return new RegExp(regexStr, "i"); | ||
if (allUnmountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
function appendToRegex(index) { | ||
var anyCharMaybeTrailingSlashRegex = "[^/]+/?"; | ||
var commonStringSubPath = escapeStrRegex(path.slice(lastIndex, index)); | ||
regexStr += inDynamic ? anyCharMaybeTrailingSlashRegex : commonStringSubPath; | ||
inDynamic = !inDynamic; | ||
lastIndex = index; | ||
} | ||
var unmountAllPromise = Promise.all(allUnmountPromises); | ||
var appsToLoad = getAppsToLoad(); | ||
/* We load and bootstrap apps while other apps are unmounting, but we | ||
* wait to mount the app until all apps are finishing unmounting | ||
*/ | ||
function escapeStrRegex(str) { | ||
// borrowed from https://github.com/sindresorhus/escape-string-regexp/blob/master/index.js | ||
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&"); | ||
} | ||
} | ||
var loadThenMountPromises = appsToLoad.map(function (app) { | ||
return toLoadPromise(app).then(toBootstrapPromise).then(function (app) { | ||
return unmountAllPromise.then(function () { | ||
return toMountPromise(app); | ||
}); | ||
}); | ||
}); | ||
var appChangeUnderway = false, | ||
peopleWaitingOnAppChange = []; | ||
function triggerAppChange() { | ||
// Call reroute with no arguments, intentionally | ||
return reroute(); | ||
} | ||
function reroute() { | ||
var pendingPromises = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var eventArguments = arguments.length > 1 ? arguments[1] : undefined; | ||
if (loadThenMountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
/* These are the apps that are already bootstrapped and just need | ||
* to be mounted. They each wait for all unmounting apps to finish up | ||
* before they mount. | ||
*/ | ||
if (appChangeUnderway) { | ||
return new Promise(function (resolve, reject) { | ||
peopleWaitingOnAppChange.push({ | ||
resolve: resolve, | ||
reject: reject, | ||
eventArguments: eventArguments | ||
}); | ||
}); | ||
} | ||
var appsThatChanged = []; | ||
var mountPromises = getAppsToMount().filter(function (appToMount) { | ||
return appsToLoad.indexOf(appToMount) < 0; | ||
}).map(function (appToMount) { | ||
return toBootstrapPromise(appToMount).then(function () { | ||
return unmountAllPromise; | ||
}).then(function () { | ||
return toMountPromise(appToMount); | ||
}); | ||
}); | ||
if (isStarted()) { | ||
appChangeUnderway = true; | ||
return performAppChanges(); | ||
} else { | ||
return loadApps(); | ||
} | ||
if (mountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
function addChangedApps(apps) { | ||
appsThatChanged.push.apply(appsThatChanged, _toConsumableArray(apps)); | ||
return apps; | ||
} | ||
return unmountAllPromise.catch(function (err) { | ||
callAllEventListeners(); | ||
throw err; | ||
}).then(function () { | ||
/* Now that the apps that needed to be unmounted are unmounted, their DOM navigation | ||
* events (like hashchange or popstate) should have been cleaned up. So it's safe | ||
* to let the remaining captured event listeners to handle about the DOM event. | ||
*/ | ||
callAllEventListeners(); | ||
return Promise.all(loadThenMountPromises.concat(mountPromises)).catch(function (err) { | ||
pendingPromises.forEach(function (promise) { | ||
return promise.reject(err); | ||
}); | ||
throw err; | ||
}).then(finishUpAndReturn); | ||
}); | ||
}); | ||
} | ||
function loadApps() { | ||
return Promise.resolve().then(function () { | ||
var loadPromises = addChangedApps(getAppsToLoad()).map(toLoadPromise); | ||
return Promise.all(loadPromises).then(callAllEventListeners) // there are no mounted apps, before start() is called, so we always return [] | ||
.then(function () { | ||
return []; | ||
}).catch(function (err) { | ||
callAllEventListeners(); | ||
throw err; | ||
}); | ||
}); | ||
} | ||
function finishUpAndReturn() { | ||
var returnValue = getMountedApps(); | ||
pendingPromises.forEach(function (promise) { | ||
return promise.resolve(returnValue); | ||
}); | ||
function performAppChanges() { | ||
return Promise.resolve().then(function () { | ||
window.dispatchEvent(new customEvent("single-spa:before-routing-event", getCustomEventDetail())); | ||
var unloadPromises = addChangedApps(getAppsToUnload()).map(toUnloadPromise); | ||
var unmountUnloadPromises = addChangedApps(getAppsToUnmount()).map(toUnmountPromise).map(function (unmountPromise) { | ||
return unmountPromise.then(toUnloadPromise); | ||
}); | ||
var allUnmountPromises = unmountUnloadPromises.concat(unloadPromises); | ||
var unmountAllPromise = Promise.all(allUnmountPromises); | ||
var appsToLoad = addChangedApps(getAppsToLoad()); | ||
/* We load and bootstrap apps while other apps are unmounting, but we | ||
* wait to mount the app until all apps are finishing unmounting | ||
*/ | ||
try { | ||
var appChangeEventName = wasNoOp ? "single-spa:no-app-change" : "single-spa:app-change"; | ||
window.dispatchEvent(new customEvent(appChangeEventName, getCustomEventDetail())); | ||
window.dispatchEvent(new customEvent("single-spa:routing-event", getCustomEventDetail())); | ||
} catch (err) { | ||
/* We use a setTimeout because if someone else's event handler throws an error, single-spa | ||
* needs to carry on. If a listener to the event throws an error, it's their own fault, not | ||
* single-spa's. | ||
*/ | ||
setTimeout(function () { | ||
throw err; | ||
}); | ||
} | ||
/* Setting this allows for subsequent calls to reroute() to actually perform | ||
* a reroute instead of just getting queued behind the current reroute call. | ||
* We want to do this after the mounting/unmounting is done but before we | ||
* resolve the promise for the `reroute` function. | ||
*/ | ||
var loadThenMountPromises = appsToLoad.map(function (app) { | ||
return toLoadPromise(app).then(toBootstrapPromise).then(function (app) { | ||
return unmountAllPromise.then(function () { | ||
return toMountPromise(app); | ||
}); | ||
}); | ||
}); | ||
/* These are the apps that are already bootstrapped and just need | ||
* to be mounted. They each wait for all unmounting apps to finish up | ||
* before they mount. | ||
*/ | ||
var mountPromises = getAppsToMount().filter(function (appToMount) { | ||
return appsToLoad.indexOf(appToMount) < 0; | ||
}).map(function (appToMount) { | ||
appsThatChanged.push(appToMount); | ||
return toBootstrapPromise(appToMount).then(function () { | ||
return unmountAllPromise; | ||
}).then(function () { | ||
return toMountPromise(appToMount); | ||
}); | ||
}); | ||
return unmountAllPromise.catch(function (err) { | ||
callAllEventListeners(); | ||
throw err; | ||
}).then(function () { | ||
/* Now that the apps that needed to be unmounted are unmounted, their DOM navigation | ||
* events (like hashchange or popstate) should have been cleaned up. So it's safe | ||
* to let the remaining captured event listeners to handle about the DOM event. | ||
*/ | ||
callAllEventListeners(); | ||
return Promise.all(loadThenMountPromises.concat(mountPromises)).catch(function (err) { | ||
pendingPromises.forEach(function (promise) { | ||
return promise.reject(err); | ||
}); | ||
throw err; | ||
}).then(finishUpAndReturn); | ||
}); | ||
}); | ||
} | ||
appChangeUnderway = false; | ||
function finishUpAndReturn() { | ||
var returnValue = getMountedApps(); | ||
pendingPromises.forEach(function (promise) { | ||
return promise.resolve(returnValue); | ||
}); | ||
if (peopleWaitingOnAppChange.length > 0) { | ||
/* While we were rerouting, someone else triggered another reroute that got queued. | ||
* So we need reroute again. | ||
*/ | ||
var nextPendingPromises = peopleWaitingOnAppChange; | ||
peopleWaitingOnAppChange = []; | ||
reroute(nextPendingPromises); | ||
} | ||
try { | ||
var appChangeEventName = appsThatChanged.length === 0 ? "single-spa:no-app-change" : "single-spa:app-change"; | ||
window.dispatchEvent(new customEvent(appChangeEventName, getCustomEventDetail())); | ||
window.dispatchEvent(new customEvent("single-spa:routing-event", getCustomEventDetail())); | ||
} catch (err) { | ||
/* We use a setTimeout because if someone else's event handler throws an error, single-spa | ||
* needs to carry on. If a listener to the event throws an error, it's their own fault, not | ||
* single-spa's. | ||
*/ | ||
setTimeout(function () { | ||
throw err; | ||
}); | ||
} | ||
/* Setting this allows for subsequent calls to reroute() to actually perform | ||
* a reroute instead of just getting queued behind the current reroute call. | ||
* We want to do this after the mounting/unmounting is done but before we | ||
* resolve the promise for the `reroute` function. | ||
*/ | ||
return returnValue; | ||
} | ||
/* We need to call all event listeners that have been delayed because they were | ||
* waiting on single-spa. This includes haschange and popstate events for both | ||
* the current run of performAppChanges(), but also all of the queued event listeners. | ||
* We want to call the listeners in the same order as if they had not been delayed by | ||
* single-spa, which means queued ones first and then the most recent one. | ||
*/ | ||
appChangeUnderway = false; | ||
function callAllEventListeners() { | ||
pendingPromises.forEach(function (pendingPromise) { | ||
callCapturedEventListeners(pendingPromise.eventArguments); | ||
}); | ||
callCapturedEventListeners(eventArguments); | ||
} | ||
if (peopleWaitingOnAppChange.length > 0) { | ||
/* While we were rerouting, someone else triggered another reroute that got queued. | ||
* So we need reroute again. | ||
*/ | ||
var nextPendingPromises = peopleWaitingOnAppChange; | ||
peopleWaitingOnAppChange = []; | ||
reroute(nextPendingPromises); | ||
} | ||
function getCustomEventDetail() { | ||
var result = { | ||
detail: {} | ||
}; | ||
return returnValue; | ||
} | ||
/* We need to call all event listeners that have been delayed because they were | ||
* waiting on single-spa. This includes haschange and popstate events for both | ||
* the current run of performAppChanges(), but also all of the queued event listeners. | ||
* We want to call the listeners in the same order as if they had not been delayed by | ||
* single-spa, which means queued ones first and then the most recent one. | ||
*/ | ||
if (eventArguments && eventArguments[0]) { | ||
result.detail.originalEvent = eventArguments[0]; | ||
} | ||
return result; | ||
} | ||
} | ||
function callAllEventListeners() { | ||
pendingPromises.forEach(function (pendingPromise) { | ||
callCapturedEventListeners(pendingPromise.eventArguments); | ||
}); | ||
callCapturedEventListeners(eventArguments); | ||
} | ||
var started = false; | ||
function start(opts) { | ||
started = true; | ||
function getCustomEventDetail() { | ||
var _appsByNewStatus; | ||
if (opts && opts.urlRerouteOnly) { | ||
setUrlRerouteOnly(opts.urlRerouteOnly); | ||
} | ||
var newAppStatuses = {}; | ||
var appsByNewStatus = (_appsByNewStatus = {}, _defineProperty(_appsByNewStatus, MOUNTED, []), _defineProperty(_appsByNewStatus, NOT_MOUNTED, []), _defineProperty(_appsByNewStatus, NOT_LOADED, []), _defineProperty(_appsByNewStatus, SKIP_BECAUSE_BROKEN, []), _appsByNewStatus); | ||
appsThatChanged.forEach(function (app) { | ||
var appName = toName(app); | ||
var status = getAppStatus(appName); | ||
newAppStatuses[appName] = status; | ||
var statusArr = appsByNewStatus[status] = appsByNewStatus[status] || []; | ||
statusArr.push(appName); | ||
}); | ||
return { | ||
detail: { | ||
newAppStatuses: newAppStatuses, | ||
appsByNewStatus: appsByNewStatus, | ||
totalAppChanges: appsThatChanged.length, | ||
originalEvent: eventArguments === null || eventArguments === void 0 ? void 0 : eventArguments[0] | ||
} | ||
}; | ||
} | ||
} | ||
if (isInBrowser) { | ||
reroute(); | ||
} | ||
} | ||
function isStarted() { | ||
return started; | ||
} | ||
var started = false; | ||
function start(opts) { | ||
started = true; | ||
if (isInBrowser) { | ||
setTimeout(function () { | ||
if (!started) { | ||
console.warn(formatErrorMessage(1, "singleSpa.start() has not been called, 5000ms after single-spa was loaded. Before start() is called, apps can be declared and loaded, but not bootstrapped or mounted.")); | ||
} | ||
}, 5000); | ||
} | ||
if (opts && opts.urlRerouteOnly) { | ||
setUrlRerouteOnly(opts.urlRerouteOnly); | ||
} | ||
var devtools = { | ||
getRawAppData: getRawAppData, | ||
reroute: reroute, | ||
NOT_LOADED: NOT_LOADED, | ||
toLoadPromise: toLoadPromise, | ||
toBootstrapPromise: toBootstrapPromise, | ||
unregisterApplication: unregisterApplication | ||
}; | ||
if (isInBrowser) { | ||
reroute(); | ||
} | ||
} | ||
function isStarted() { | ||
return started; | ||
} | ||
if (isInBrowser && window.__SINGLE_SPA_DEVTOOLS__) { | ||
window.__SINGLE_SPA_DEVTOOLS__.exposedMethods = devtools; | ||
} | ||
if (isInBrowser) { | ||
setTimeout(function () { | ||
if (!started) { | ||
console.warn(formatErrorMessage(1, "singleSpa.start() has not been called, 5000ms after single-spa was loaded. Before start() is called, apps can be declared and loaded, but not bootstrapped or mounted.")); | ||
} | ||
}, 5000); | ||
} | ||
} | ||
}; | ||
var devtools = { | ||
getRawAppData: getRawAppData, | ||
reroute: reroute, | ||
NOT_LOADED: NOT_LOADED, | ||
toLoadPromise: toLoadPromise, | ||
toBootstrapPromise: toBootstrapPromise, | ||
unregisterApplication: unregisterApplication | ||
}; | ||
if (isInBrowser && window.__SINGLE_SPA_DEVTOOLS__) { | ||
window.__SINGLE_SPA_DEVTOOLS__.exposedMethods = devtools; | ||
} | ||
} | ||
}; | ||
}); | ||
//# sourceMappingURL=single-spa.dev.js.map |
@@ -1,3 +0,3 @@ | ||
/* single-spa@5.3.1 - SystemJS - prod */ | ||
System.register([],(function(t){return{execute:function(){t({addErrorHandler:a,checkActivityFunctions:Dt,ensureJQuerySupport:vt,getAppNames:Nt,getAppStatus:St,getMountedApps:bt,mountRootParcel:H,navigateToUrl:at,registerApplication:_t,removeErrorHandler:c,setBootstrapMaxTime:z,setMountMaxTime:X,setUnloadMaxTime:Z,setUnmountMaxTime:Y,start:Wt,triggerAppChange:Gt,unloadApplication:jt});var n=Object.freeze({__proto__:null,get start(){return Wt},get ensureJQuerySupport(){return vt},get setBootstrapMaxTime(){return z},get setMountMaxTime(){return X},get setUnmountMaxTime(){return Y},get setUnloadMaxTime(){return Z},get registerApplication(){return _t},get getMountedApps(){return bt},get getAppStatus(){return St},get unloadApplication(){return jt},get checkActivityFunctions(){return Dt},get getAppNames(){return Nt},get navigateToUrl(){return at},get triggerAppChange(){return Gt},get addErrorHandler(){return a},get removeErrorHandler(){return c},get mountRootParcel(){return H},get NOT_LOADED(){return l},get LOADING_SOURCE_CODE(){return p},get NOT_BOOTSTRAPPED(){return h},get BOOTSTRAPPING(){return m},get NOT_MOUNTED(){return d},get MOUNTING(){return v},get UPDATING(){return g},get LOAD_ERROR(){return y},get MOUNTED(){return w},get UNMOUNTING(){return E},get SKIP_BECAUSE_BROKEN(){return O}}),r=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{}).CustomEvent,e=function(){try{var t=new r("cat",{detail:{foo:"bar"}});return"cat"===t.type&&"bar"===t.detail.foo}catch(t){}return!1}()?r:"undefined"!=typeof document&&"function"==typeof document.createEvent?function(t,n){var r=document.createEvent("CustomEvent");return n?r.initCustomEvent(t,n.bubbles,n.cancelable,n.detail):r.initCustomEvent(t,!1,!1,void 0),r}:function(t,n){var r=document.createEventObject();return r.type=t,n?(r.bubbles=Boolean(n.bubbles),r.cancelable=Boolean(n.cancelable),r.detail=n.detail):(r.bubbles=!1,r.cancelable=!1,r.detail=void 0),r};function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=[];function u(t,n,r){var e=f(t,n,r);i.length?i.forEach((function(t){return t(e)})):setTimeout((function(){throw e}))}function a(t){if("function"!=typeof t)throw Error(s(28,!1));i.push(t)}function c(t){if("function"!=typeof t)throw Error(s(29,!1));var n=!1;return i=i.filter((function(r){var e=r===t;return n=n||e,!e})),n}function s(t,n){for(var r=arguments.length,e=new Array(r>2?r-2:0),o=2;o<r;o++)e[o-2]=arguments[o];return"single-spa minified message #".concat(t,": ").concat(n?n+" ":"","See https://single-spa.js.org/error/?code=").concat(t).concat(e.length?"&arg=".concat(e.join("&arg=")):"")}function f(t,n,r){var e,o="".concat(R(n)," '").concat(M(n),"' died in status ").concat(n.status,": ");if(t instanceof Error){try{t.message=o+t.message}catch(t){}e=t}else{console.warn(s(30,!1,n.status,M(n)));try{e=Error(o+JSON.stringify(t))}catch(n){e=t}}return e.appOrParcelName=M(n),n.status=r,e}var l=t("NOT_LOADED","NOT_LOADED"),p=t("LOADING_SOURCE_CODE","LOADING_SOURCE_CODE"),h=t("NOT_BOOTSTRAPPED","NOT_BOOTSTRAPPED"),m=t("BOOTSTRAPPING","BOOTSTRAPPING"),d=t("NOT_MOUNTED","NOT_MOUNTED"),v=t("MOUNTING","MOUNTING"),w=t("MOUNTED","MOUNTED"),g=t("UPDATING","UPDATING"),E=t("UNMOUNTING","UNMOUNTING"),y=t("LOAD_ERROR","LOAD_ERROR"),O=t("SKIP_BECAUSE_BROKEN","SKIP_BECAUSE_BROKEN");function T(t){return t.status===w}function P(t){return!T(t)}function A(t){return t.status!==l&&t.status!==p&&t.status!==y}function b(t){return!A(t)}function N(t){try{return t.activeWhen(window.location)}catch(n){u(n,t,O)}}function S(t){try{return!N(t)}catch(n){u(n,t,O)}}function _(t){return t!==O&&(!t||t.status!==O)}function D(t){return t.status!==y||(new Date).getTime()-t.loadErrorTime>=200}function M(t){return t.name}function U(t){return Boolean(t.unmountThisParcel)}function R(t){return U(t)?"parcel":"application"}function j(){for(var t=arguments.length-1;t>0;t--)for(var n in arguments[t])"__proto__"!==n&&(arguments[t-1][n]=arguments[t][n]);return arguments[0]}function L(t,n){for(var r=0;r<t.length;r++)if(n(t[r]))return t[r];return null}function I(t){return t&&("function"==typeof t||(n=t,Array.isArray(n)&&!L(n,(function(t){return"function"!=typeof t}))));var n}function x(t,n){var r=t[n]||[];0===(r=Array.isArray(r)?r:[r]).length&&(r=[function(){return Promise.resolve()}]);var e=R(t),o=M(t);return function(t){return r.reduce((function(r,i,u){return r.then((function(){var r=i(t);return G(r)?r:Promise.reject(s(15,!1,e,o,n,u))}))}),Promise.resolve())}}function G(t){return t&&"function"==typeof t.then&&"function"==typeof t.catch}function B(t,n){return Promise.resolve().then((function(){return t.status!==h?t:(t.status=m,tt(t,"bootstrap").then((function(){return t.status=d,t})).catch((function(r){if(n)throw f(r,t,O);return u(r,t,O),t})))}))}function C(t,n){return Promise.resolve().then((function(){if(t.status!==w)return t;t.status=E;var r=Object.keys(t.parcels).map((function(n){return t.parcels[n].unmountThisParcel()}));return Promise.all(r).then(e,(function(r){return e().then((function(){var e=Error(r.message);if(n)throw f(e,t,O);u(e,t,O)}))})).then((function(){return t}));function e(){return tt(t,"unmount").then((function(){t.status=d})).catch((function(r){if(n)throw f(r,t,O);u(r,t,O)}))}}))}var W=!1,K=!1;function $(t,n){return Promise.resolve().then((function(){return t.status!==d?t:(W||(window.dispatchEvent(new e("single-spa:before-first-mount")),W=!0),tt(t,"mount").then((function(){return t.status=w,K||(window.dispatchEvent(new e("single-spa:first-mount")),K=!0),t})).catch((function(r){return t.status=w,C(t,!0).then(e,e);function e(){if(n)throw f(r,t,O);return u(r,t,O),t}})))}))}var k=0,F={parcels:{}};function H(){return J.apply(F,arguments)}function J(t,n){var r=this;if(!t||"object"!==o(t)&&"function"!=typeof t)throw Error(s(2,!1));if(t.name&&"string"!=typeof t.name)throw Error(s(3,!1,o(t.name)));if("object"!==o(n))throw Error(s(4,!1,name,o(n)));if(!n.domElement)throw Error(s(5,!1,name));var e,i=k++,u="function"==typeof t,a=u?t:function(){return Promise.resolve(t)},c={id:i,parcels:{},status:u?p:h,customProps:n,parentName:M(r),unmountThisParcel:function(){if(c.status!==w)throw Error(s(6,!1,name,c.status));return C(c,!0).then((function(t){return c.parentName&&delete r.parcels[c.id],t})).then((function(t){return m(t),t})).catch((function(t){throw c.status=O,v(t),t}))}};r.parcels[i]=c;var l=a();if(!l||"function"!=typeof l.then)throw Error(s(7,!1));var m,v,E=(l=l.then((function(t){if(!t)throw Error(s(8,!1));var n=t.name||"parcel-".concat(i);if(!I(t.bootstrap))throw Error(s(9,!1,n));if(!I(t.mount))throw Error(s(10,!1,n));if(!I(t.unmount))throw Error(s(11,!1,n));if(t.update&&!I(t.update))throw Error(s(12,!1,n));var r=x(t,"bootstrap"),o=x(t,"mount"),u=x(t,"unmount");c.status=h,c.name=n,c.bootstrap=r,c.mount=o,c.unmount=u,c.timeouts=nt(t.timeouts),t.update&&(c.update=x(t,"update"),e.update=function(t){return c.customProps=t,Q(function(t){return Promise.resolve().then((function(){if(t.status!==w)throw Error(s(32,!1,M(t)));return t.status=g,tt(t,"update").then((function(){return t.status=w,t})).catch((function(n){throw f(n,t,O)}))}))}(c))})}))).then((function(){return B(c,!0)})),y=E.then((function(){return $(c,!0)})),T=new Promise((function(t,n){m=t,v=n}));return e={mount:function(){return Q(Promise.resolve().then((function(){if(c.status!==d)throw Error(s(13,!1,name,c.status));return r.parcels[i]=c,$(c)})))},unmount:function(){return Q(c.unmountThisParcel())},getStatus:function(){return c.status},loadPromise:Q(l),bootstrapPromise:Q(E),mountPromise:Q(y),unmountPromise:Q(T)}}function Q(t){return t.then((function(){return null}))}function V(t){var r=j({},t.customProps,{name:M(t),mountParcel:J.bind(t),singleSpa:n});return U(t)&&(r.unmountSelf=t.unmountThisParcel),r}var q={bootstrap:{millis:4e3,dieOnTimeout:!1,warningMillis:1e3},mount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unmount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unload:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},update:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3}};function z(t,n,r){if("number"!=typeof t||t<=0)throw Error(s(16,!1));q.bootstrap={millis:t,dieOnTimeout:n,warningMillis:r||1e3}}function X(t,n,r){if("number"!=typeof t||t<=0)throw Error(s(17,!1));q.mount={millis:t,dieOnTimeout:n,warningMillis:r||1e3}}function Y(t,n,r){if("number"!=typeof t||t<=0)throw Error(s(18,!1));q.unmount={millis:t,dieOnTimeout:n,warningMillis:r||1e3}}function Z(t,n,r){if("number"!=typeof t||t<=0)throw Error(s(19,!1));q.unload={millis:t,dieOnTimeout:n,warningMillis:r||1e3}}function tt(t,n){var r=t.timeouts[n],e=r.warningMillis,o=R(t);return new Promise((function(i,u){var a=!1,c=!1;t[n](V(t)).then((function(t){a=!0,i(t)})).catch((function(t){a=!0,u(t)})),setTimeout((function(){return l(1)}),e),setTimeout((function(){return l(!0)}),r.millis);var f=s(31,!1,n,o,M(t),r.millis);function l(t){if(!a)if(!0===t)c=!0,r.dieOnTimeout?u(Error(f)):console.error(f);else if(!c){var n=t,o=n*e;console.warn(f),o+e<r.millis&&setTimeout((function(){return l(n+1)}),e)}}}))}function nt(t){var n={};for(var r in q)n[r]=j({},q[r],t&&t[r]||{});return n}function rt(t){return Promise.resolve().then((function(){return t.loadPromise?t.loadPromise:t.status!==l&&t.status!==y?t:(t.status=p,t.loadPromise=Promise.resolve().then((function(){var e=t.loadApp(V(t));if(!G(e))throw r=!0,Error(s(33,!1,M(t)));return e.then((function(r){var e;t.loadErrorTime=null,"object"!==o(n=r)&&(e=34),I(n.bootstrap)||(e=35),I(n.mount)||(e=36),I(n.unmount)||(e=37);var i=R(n);if(e){var a;try{a=JSON.stringify(n)}catch(t){}return console.error(s(e,!1,i,M(t),a),n),u(void 0,t,O),t}return n.devtools&&n.devtools.overlays&&(t.devtools.overlays=j({},t.devtools.overlays,n.devtools.overlays)),t.status=h,t.bootstrap=x(n,"bootstrap"),t.mount=x(n,"mount"),t.unmount=x(n,"unmount"),t.unload=x(n,"unload"),t.timeouts=nt(n.timeouts),delete t.loadPromise,t}))})).catch((function(n){var e;return delete t.loadPromise,r?e=O:(e=y,t.loadErrorTime=(new Date).getTime()),u(n,t,e),t})));var n,r}))}var et,ot="undefined"!=typeof window,it={hashchange:[],popstate:[]},ut=["hashchange","popstate"];function at(t){var n;if("string"==typeof t)n=t;else if(this&&this.href)n=this.href;else{if(!(t&&t.currentTarget&&t.currentTarget.href&&t.preventDefault))throw Error(s(14,!1));n=t.currentTarget.href,t.preventDefault()}var r=mt(window.location.href),e=mt(n);0===n.indexOf("#")?window.location.hash=e.hash:r.host!==e.host&&e.host?window.location.href=n:e.pathname===r.pathname&&e.search===r.pathname?window.location.hash=e.hash:window.history.pushState(null,null,n)}function ct(t){var n=this;if(t){var r=t[0].type;ut.indexOf(r)>=0&&it[r].forEach((function(r){try{r.apply(n,t)}catch(t){setTimeout((function(){throw t}))}}))}}function st(){Bt([],arguments)}if(ot){window.addEventListener("hashchange",st),window.addEventListener("popstate",st);var ft=window.addEventListener,lt=window.removeEventListener;function pt(t){return function(){var n=window.location.href,r=t.apply(this,arguments),e=window.location.href;return et&&n===e||st(ht(window.history.state)),r}}function ht(t){try{return new PopStateEvent("popstate",{state:t})}catch(r){var n=document.createEvent("PopStateEvent");return n.initPopStateEvent("popstate",!1,!1,t),n}}window.addEventListener=function(t,n){if(!("function"==typeof n&&ut.indexOf(t)>=0)||L(it[t],(function(t){return t===n})))return ft.apply(this,arguments);it[t].push(n)},window.removeEventListener=function(t,n){if(!("function"==typeof n&&ut.indexOf(t)>=0))return lt.apply(this,arguments);it[t]=it[t].filter((function(t){return t!==n}))},window.history.pushState=pt(window.history.pushState),window.history.replaceState=pt(window.history.replaceState),window.singleSpaNavigate=at}function mt(t){var n=document.createElement("a");return n.href=t,n}var dt=!1;function vt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.jQuery;if(t||window.$&&window.$.fn&&window.$.fn.jquery&&(t=window.$),t&&!dt){var n=t.fn.on,r=t.fn.off;t.fn.on=function(t,r){return wt.call(this,n,window.addEventListener,t,r,arguments)},t.fn.off=function(t,n){return wt.call(this,r,window.removeEventListener,t,n,arguments)},dt=!0}}function wt(t,n,r,e,o){return"string"!=typeof r?t.apply(this,o):(r.split(/\s+/).forEach((function(t){ut.indexOf(t)>=0&&(n(t,e),r=r.replace(t,""))})),""===r.trim()?this:t.apply(this,o))}var gt={};function Et(t){return Promise.resolve().then((function(){var n=gt[M(t)];return n?t.status===l?(yt(t,n),t):"UNLOADING"===t.status?n.promise.then((function(){return t})):t.status!==d?t:(t.status="UNLOADING",tt(t,"unload").then((function(){return yt(t,n),t})).catch((function(r){return function(t,n,r){delete gt[M(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,u(r,t,O),n.reject(r)}(t,n,r),t}))):t}))}function yt(t,n){delete gt[M(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,t.status=l,n.resolve()}function Ot(t,n,r,e){gt[M(t)]={app:t,resolve:r,reject:e},Object.defineProperty(gt[M(t)],"promise",{get:n})}function Tt(t){return gt[t]}function Pt(){return Object.keys(gt).map((function(t){return gt[t].app})).filter(P)}var At=[];function bt(){return At.filter(T).map(M)}function Nt(){return At.map(M)}function St(t){var n=L(At,(function(n){return M(n)===t}));return n?n.status:null}function _t(t,n,r,e){var i=function(t,n,r,e){var i,u={name:null,loadApp:null,activeWhen:null,customProps:null};return"object"===o(t)?(function(t){if(Array.isArray(t)||null===t)throw Error(s(39,!1));var n=["name","app","activeWhen","customProps"],r=Object.keys(t).reduce((function(t,r){return n.includes(r)?t:t.concat(r)}),[]);if(0!==r.length)throw Error(s(38,!1,n.join(", "),r.join(", ")));if("string"!=typeof t.name||0===t.name.length)throw Error(s(20,!1));if("object"!==o(t.app)&&"function"!=typeof t.app)throw Error(s(20,!1));var e=function(t){return"string"==typeof t||"function"==typeof t};if(!(e(t.activeWhen)||Array.isArray(t.activeWhen)&&t.activeWhen.every(e)))throw Error(s(24,!1));if(t.customProps&&("object"!==o(t.customProps)||Array.isArray(t.customProps)))throw Error(s(22,!1))}(t),u.name=t.name,u.loadApp=t.app,u.activeWhen=t.activeWhen,u.customProps=t.customProps):(function(t,n,r,e){if("string"!=typeof t||0===t.length)throw Error(s(20,!1));if(!n)throw Error(s(23,!1));if("function"!=typeof r)throw Error(s(24,!1));if(e&&("object"!==o(e)||Array.isArray(e)))throw Error(s(22,!1))}(t,n,r,e),u.name=t,u.loadApp=n,u.activeWhen=r,u.customProps=e),u.loadApp="function"!=typeof(i=u.loadApp)?function(){return Promise.resolve(i)}:i,u.customProps=function(t){return t||{}}(u.customProps),u.activeWhen=function(t){var n=Array.isArray(t)?t:[t];return n=n.map((function(t){return"function"==typeof t?t:(n=function(t){for(var n=0,r=!1,e="^",o=0;o<t.length;o++){var i=t[o];(!r&&":"===i||r&&"/"===i)&&u(o)}return u(t.length),new RegExp(e,"i");function u(o){var i=t.slice(n,o).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&");e+=r?"[^/]+/?":i,r=!r,n=o}}(t),function(t){var r=t.href.replace(t.origin,"");return n.test(r)});var n})),function(t){return n.some((function(n){return n(t)}))}}(u.activeWhen),u}(t,n,r,e);if(-1!==Nt().indexOf(i.name))throw Error(s(21,!1,i.name));At.push(j({loadErrorTime:null,status:l,parcels:{},devtools:{overlays:{options:{},selectors:[]}}},i)),ot&&(vt(),Bt())}function Dt(t){return At.filter((function(n){return n.activeWhen(t)})).map(M)}function Mt(){return At.filter(_).filter(D).filter(b).filter(N)}function Ut(){return At.filter(_).filter(T).filter(S)}function Rt(){return At.filter(_).filter(P).filter(A).filter(N)}function jt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{waitForUnmount:!1};if("string"!=typeof t)throw Error(s(26,!1));var r=L(At,(function(n){return M(n)===t}));if(!r)throw Error(s(27,!1,t));var e,o=Tt(M(r));if(n&&n.waitForUnmount){if(o)return o.promise;var i=new Promise((function(t,n){Ot(r,(function(){return i}),t,n)}));return i}return o?(e=o.promise,Lt(r,o.resolve,o.reject)):e=new Promise((function(t,n){Ot(r,(function(){return e}),t,n),Lt(r,t,n)})),e}function Lt(t,n,r){C(t).then(Et).then((function(){n(),setTimeout((function(){Bt()}))})).catch(r)}var It=!1,xt=[];function Gt(){return Bt()}function Bt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0;if(It)return new Promise((function(t,r){xt.push({resolve:t,reject:r,eventArguments:n})}));var r=!0;return Kt()?(It=!0,i()):o();function o(){return Promise.resolve().then((function(){var t=Mt().map(rt);return t.length>0&&(r=!1),Promise.all(t).then(a).then((function(){return[]})).catch((function(t){throw a(),t}))}))}function i(){return Promise.resolve().then((function(){window.dispatchEvent(new e("single-spa:before-routing-event",c()));var n=Pt().map(Et),o=Ut().map(C).map((function(t){return t.then(Et)})).concat(n);o.length>0&&(r=!1);var i=Promise.all(o),s=Mt(),f=s.map((function(t){return rt(t).then(B).then((function(t){return i.then((function(){return $(t)}))}))}));f.length>0&&(r=!1);var l=Rt().filter((function(t){return s.indexOf(t)<0})).map((function(t){return B(t).then((function(){return i})).then((function(){return $(t)}))}));return l.length>0&&(r=!1),i.catch((function(t){throw a(),t})).then((function(){return a(),Promise.all(f.concat(l)).catch((function(n){throw t.forEach((function(t){return t.reject(n)})),n})).then(u)}))}))}function u(){var n=bt();t.forEach((function(t){return t.resolve(n)}));try{var o=r?"single-spa:no-app-change":"single-spa:app-change";window.dispatchEvent(new e(o,c())),window.dispatchEvent(new e("single-spa:routing-event",c()))}catch(t){setTimeout((function(){throw t}))}if(It=!1,xt.length>0){var i=xt;xt=[],Bt(i)}return n}function a(){t.forEach((function(t){ct(t.eventArguments)})),ct(n)}function c(){var t={detail:{}};return n&&n[0]&&(t.detail.originalEvent=n[0]),t}}var Ct=!1;function Wt(t){var n;Ct=!0,t&&t.urlRerouteOnly&&(n=t.urlRerouteOnly,et=n),ot&&Bt()}function Kt(){return Ct}ot&&setTimeout((function(){Ct||console.warn(s(1,!1))}),5e3);var $t={getRawAppData:function(){return[].concat(At)},reroute:Bt,NOT_LOADED:l,toLoadPromise:rt,toBootstrapPromise:B,unregisterApplication:function(t){if(!At.find((function(n){return M(n)===t})))throw Error(s(25,!1,t));return jt(t).then((function(){var n=At.findIndex((function(n){return M(n)===t}));At.splice(n,1)}))}};ot&&window.__SINGLE_SPA_DEVTOOLS__&&(window.__SINGLE_SPA_DEVTOOLS__.exposedMethods=$t)}}})); | ||
/* single-spa@5.3.2 - SystemJS - prod */ | ||
System.register([],(function(t){"use strict";return{execute:function(){t({addErrorHandler:f,checkActivityFunctions:jt,ensureJQuerySupport:yt,getAppNames:Dt,getAppStatus:Mt,getMountedApps:_t,mountRootParcel:V,navigateToUrl:ft,registerApplication:Ut,removeErrorHandler:l,setBootstrapMaxTime:Z,setMountMaxTime:tt,setUnloadMaxTime:rt,setUnmountMaxTime:nt,start:kt,triggerAppChange:Wt,unloadApplication:xt});var n=Object.freeze({__proto__:null,get start(){return kt},get ensureJQuerySupport(){return yt},get setBootstrapMaxTime(){return Z},get setMountMaxTime(){return tt},get setUnmountMaxTime(){return nt},get setUnloadMaxTime(){return rt},get registerApplication(){return Ut},get getMountedApps(){return _t},get getAppStatus(){return Mt},get unloadApplication(){return xt},get checkActivityFunctions(){return jt},get getAppNames(){return Dt},get navigateToUrl(){return ft},get triggerAppChange(){return Wt},get addErrorHandler(){return f},get removeErrorHandler(){return l},get mountRootParcel(){return V},get NOT_LOADED(){return m},get LOADING_SOURCE_CODE(){return d},get NOT_BOOTSTRAPPED(){return v},get BOOTSTRAPPING(){return w},get NOT_MOUNTED(){return g},get MOUNTING(){return y},get UPDATING(){return O},get LOAD_ERROR(){return P},get MOUNTED(){return E},get UNMOUNTING(){return T},get SKIP_BECAUSE_BROKEN(){return b}});function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function e(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}function o(t){return function(t){if(Array.isArray(t))return i(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,n){if(t){if("string"==typeof t)return i(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,void 0):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=new Array(n);r<n;r++)e[r]=t[r];return e}var u=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{}).CustomEvent,a=function(){try{var t=new u("cat",{detail:{foo:"bar"}});return"cat"===t.type&&"bar"===t.detail.foo}catch(t){}return!1}()?u:"undefined"!=typeof document&&"function"==typeof document.createEvent?function(t,n){var r=document.createEvent("CustomEvent");return n?r.initCustomEvent(t,n.bubbles,n.cancelable,n.detail):r.initCustomEvent(t,!1,!1,void 0),r}:function(t,n){var r=document.createEventObject();return r.type=t,n?(r.bubbles=Boolean(n.bubbles),r.cancelable=Boolean(n.cancelable),r.detail=n.detail):(r.bubbles=!1,r.cancelable=!1,r.detail=void 0),r},c=[];function s(t,n,r){var e=h(t,n,r);c.length?c.forEach((function(t){return t(e)})):setTimeout((function(){throw e}))}function f(t){if("function"!=typeof t)throw Error(p(28,!1));c.push(t)}function l(t){if("function"!=typeof t)throw Error(p(29,!1));var n=!1;return c=c.filter((function(r){var e=r===t;return n=n||e,!e})),n}function p(t,n){for(var r=arguments.length,e=new Array(r>2?r-2:0),o=2;o<r;o++)e[o-2]=arguments[o];return"single-spa minified message #".concat(t,": ").concat(n?n+" ":"","See https://single-spa.js.org/error/?code=").concat(t).concat(e.length?"&arg=".concat(e.join("&arg=")):"")}function h(t,n,r){var e,o="".concat(L(n)," '").concat(R(n),"' died in status ").concat(n.status,": ");if(t instanceof Error){try{t.message=o+t.message}catch(t){}e=t}else{console.warn(p(30,!1,n.status,R(n)));try{e=Error(o+JSON.stringify(t))}catch(n){e=t}}return e.appOrParcelName=R(n),n.status=r,e}var m=t("NOT_LOADED","NOT_LOADED"),d=t("LOADING_SOURCE_CODE","LOADING_SOURCE_CODE"),v=t("NOT_BOOTSTRAPPED","NOT_BOOTSTRAPPED"),w=t("BOOTSTRAPPING","BOOTSTRAPPING"),g=t("NOT_MOUNTED","NOT_MOUNTED"),y=t("MOUNTING","MOUNTING"),E=t("MOUNTED","MOUNTED"),O=t("UPDATING","UPDATING"),T=t("UNMOUNTING","UNMOUNTING"),P=t("LOAD_ERROR","LOAD_ERROR"),b=t("SKIP_BECAUSE_BROKEN","SKIP_BECAUSE_BROKEN");function A(t){return t.status===E}function N(t){return!A(t)}function S(t){return t.status!==m&&t.status!==d&&t.status!==P}function _(t){return!S(t)}function D(t){try{return t.activeWhen(window.location)}catch(n){s(n,t,b)}}function M(t){try{return!D(t)}catch(n){s(n,t,b)}}function U(t){return t!==b&&(!t||t.status!==b)}function j(t){return t.status!==P||(new Date).getTime()-t.loadErrorTime>=200}function R(t){return t.name}function I(t){return Boolean(t.unmountThisParcel)}function L(t){return I(t)?"parcel":"application"}function x(){for(var t=arguments.length-1;t>0;t--)for(var n in arguments[t])"__proto__"!==n&&(arguments[t-1][n]=arguments[t][n]);return arguments[0]}function B(t,n){for(var r=0;r<t.length;r++)if(n(t[r]))return t[r];return null}function G(t){return t&&("function"==typeof t||(n=t,Array.isArray(n)&&!B(n,(function(t){return"function"!=typeof t}))));var n}function C(t,n){var r=t[n]||[];0===(r=Array.isArray(r)?r:[r]).length&&(r=[function(){return Promise.resolve()}]);var e=L(t),o=R(t);return function(t){return r.reduce((function(r,i,u){return r.then((function(){var r=i(t);return W(r)?r:Promise.reject(p(15,!1,e,o,n,u))}))}),Promise.resolve())}}function W(t){return t&&"function"==typeof t.then&&"function"==typeof t.catch}function $(t,n){return Promise.resolve().then((function(){return t.status!==v?t:(t.status=w,et(t,"bootstrap").then((function(){return t.status=g,t})).catch((function(r){if(n)throw h(r,t,b);return s(r,t,b),t})))}))}function K(t,n){return Promise.resolve().then((function(){if(t.status!==E)return t;t.status=T;var r=Object.keys(t.parcels).map((function(n){return t.parcels[n].unmountThisParcel()}));return Promise.all(r).then(e,(function(r){return e().then((function(){var e=Error(r.message);if(n)throw h(e,t,b);s(e,t,b)}))})).then((function(){return t}));function e(){return et(t,"unmount").then((function(){t.status=g})).catch((function(r){if(n)throw h(r,t,b);s(r,t,b)}))}}))}var k=!1,F=!1;function H(t,n){return Promise.resolve().then((function(){return t.status!==g?t:(k||(window.dispatchEvent(new a("single-spa:before-first-mount")),k=!0),et(t,"mount").then((function(){return t.status=E,F||(window.dispatchEvent(new a("single-spa:first-mount")),F=!0),t})).catch((function(r){return t.status=E,K(t,!0).then(e,e);function e(){if(n)throw h(r,t,b);return s(r,t,b),t}})))}))}var J=0,Q={parcels:{}};function V(){return q.apply(Q,arguments)}function q(t,n){var e=this;if(!t||"object"!==r(t)&&"function"!=typeof t)throw Error(p(2,!1));if(t.name&&"string"!=typeof t.name)throw Error(p(3,!1,r(t.name)));if("object"!==r(n))throw Error(p(4,!1,name,r(n)));if(!n.domElement)throw Error(p(5,!1,name));var o,i=J++,u="function"==typeof t,a=u?t:function(){return Promise.resolve(t)},c={id:i,parcels:{},status:u?d:v,customProps:n,parentName:R(e),unmountThisParcel:function(){if(c.status!==E)throw Error(p(6,!1,name,c.status));return K(c,!0).then((function(t){return c.parentName&&delete e.parcels[c.id],t})).then((function(t){return f(t),t})).catch((function(t){throw c.status=b,l(t),t}))}};e.parcels[i]=c;var s=a();if(!s||"function"!=typeof s.then)throw Error(p(7,!1));var f,l,m=(s=s.then((function(t){if(!t)throw Error(p(8,!1));var n=t.name||"parcel-".concat(i);if(!G(t.bootstrap))throw Error(p(9,!1,n));if(!G(t.mount))throw Error(p(10,!1,n));if(!G(t.unmount))throw Error(p(11,!1,n));if(t.update&&!G(t.update))throw Error(p(12,!1,n));var r=C(t,"bootstrap"),e=C(t,"mount"),u=C(t,"unmount");c.status=v,c.name=n,c.bootstrap=r,c.mount=e,c.unmount=u,c.timeouts=ot(t.timeouts),t.update&&(c.update=C(t,"update"),o.update=function(t){return c.customProps=t,z(function(t){return Promise.resolve().then((function(){if(t.status!==E)throw Error(p(32,!1,R(t)));return t.status=O,et(t,"update").then((function(){return t.status=E,t})).catch((function(n){throw h(n,t,b)}))}))}(c))})}))).then((function(){return $(c,!0)})),w=m.then((function(){return H(c,!0)})),y=new Promise((function(t,n){f=t,l=n}));return o={mount:function(){return z(Promise.resolve().then((function(){if(c.status!==g)throw Error(p(13,!1,name,c.status));return e.parcels[i]=c,H(c)})))},unmount:function(){return z(c.unmountThisParcel())},getStatus:function(){return c.status},loadPromise:z(s),bootstrapPromise:z(m),mountPromise:z(w),unmountPromise:z(y)}}function z(t){return t.then((function(){return null}))}function X(t){var r=x({},t.customProps,{name:R(t),mountParcel:q.bind(t),singleSpa:n});return I(t)&&(r.unmountSelf=t.unmountThisParcel),r}var Y={bootstrap:{millis:4e3,dieOnTimeout:!1,warningMillis:1e3},mount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unmount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unload:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},update:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3}};function Z(t,n,r){if("number"!=typeof t||t<=0)throw Error(p(16,!1));Y.bootstrap={millis:t,dieOnTimeout:n,warningMillis:r||1e3}}function tt(t,n,r){if("number"!=typeof t||t<=0)throw Error(p(17,!1));Y.mount={millis:t,dieOnTimeout:n,warningMillis:r||1e3}}function nt(t,n,r){if("number"!=typeof t||t<=0)throw Error(p(18,!1));Y.unmount={millis:t,dieOnTimeout:n,warningMillis:r||1e3}}function rt(t,n,r){if("number"!=typeof t||t<=0)throw Error(p(19,!1));Y.unload={millis:t,dieOnTimeout:n,warningMillis:r||1e3}}function et(t,n){var r=t.timeouts[n],e=r.warningMillis,o=L(t);return new Promise((function(i,u){var a=!1,c=!1;t[n](X(t)).then((function(t){a=!0,i(t)})).catch((function(t){a=!0,u(t)})),setTimeout((function(){return f(1)}),e),setTimeout((function(){return f(!0)}),r.millis);var s=p(31,!1,n,o,R(t),r.millis);function f(t){if(!a)if(!0===t)c=!0,r.dieOnTimeout?u(Error(s)):console.error(s);else if(!c){var n=t,o=n*e;console.warn(s),o+e<r.millis&&setTimeout((function(){return f(n+1)}),e)}}}))}function ot(t){var n={};for(var r in Y)n[r]=x({},Y[r],t&&t[r]||{});return n}function it(t){return Promise.resolve().then((function(){return t.loadPromise?t.loadPromise:t.status!==m&&t.status!==P?t:(t.status=d,t.loadPromise=Promise.resolve().then((function(){var o=t.loadApp(X(t));if(!W(o))throw e=!0,Error(p(33,!1,R(t)));return o.then((function(e){var o;t.loadErrorTime=null,"object"!==r(n=e)&&(o=34),G(n.bootstrap)||(o=35),G(n.mount)||(o=36),G(n.unmount)||(o=37);var i=L(n);if(o){var u;try{u=JSON.stringify(n)}catch(t){}return console.error(p(o,!1,i,R(t),u),n),s(void 0,t,b),t}return n.devtools&&n.devtools.overlays&&(t.devtools.overlays=x({},t.devtools.overlays,n.devtools.overlays)),t.status=v,t.bootstrap=C(n,"bootstrap"),t.mount=C(n,"mount"),t.unmount=C(n,"unmount"),t.unload=C(n,"unload"),t.timeouts=ot(n.timeouts),delete t.loadPromise,t}))})).catch((function(n){var r;return delete t.loadPromise,e?r=b:(r=P,t.loadErrorTime=(new Date).getTime()),s(n,t,r),t})));var n,e}))}var ut,at="undefined"!=typeof window,ct={hashchange:[],popstate:[]},st=["hashchange","popstate"];function ft(t){var n;if("string"==typeof t)n=t;else if(this&&this.href)n=this.href;else{if(!(t&&t.currentTarget&&t.currentTarget.href&&t.preventDefault))throw Error(p(14,!1));n=t.currentTarget.href,t.preventDefault()}var r=wt(window.location.href),e=wt(n);0===n.indexOf("#")?window.location.hash=e.hash:r.host!==e.host&&e.host?window.location.href=n:e.pathname===r.pathname&&e.search===r.pathname?window.location.hash=e.hash:window.history.pushState(null,null,n)}function lt(t){var n=this;if(t){var r=t[0].type;st.indexOf(r)>=0&&ct[r].forEach((function(r){try{r.apply(n,t)}catch(t){setTimeout((function(){throw t}))}}))}}function pt(){$t([],arguments)}if(at){window.addEventListener("hashchange",pt),window.addEventListener("popstate",pt);var ht=window.addEventListener,mt=window.removeEventListener;function dt(t){return function(){var n=window.location.href,r=t.apply(this,arguments),e=window.location.href;return ut&&n===e||pt(vt(window.history.state)),r}}function vt(t){try{return new PopStateEvent("popstate",{state:t})}catch(r){var n=document.createEvent("PopStateEvent");return n.initPopStateEvent("popstate",!1,!1,t),n}}window.addEventListener=function(t,n){if(!("function"==typeof n&&st.indexOf(t)>=0)||B(ct[t],(function(t){return t===n})))return ht.apply(this,arguments);ct[t].push(n)},window.removeEventListener=function(t,n){if(!("function"==typeof n&&st.indexOf(t)>=0))return mt.apply(this,arguments);ct[t]=ct[t].filter((function(t){return t!==n}))},window.history.pushState=dt(window.history.pushState),window.history.replaceState=dt(window.history.replaceState),window.singleSpaNavigate=ft}function wt(t){var n=document.createElement("a");return n.href=t,n}var gt=!1;function yt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.jQuery;if(t||window.$&&window.$.fn&&window.$.fn.jquery&&(t=window.$),t&&!gt){var n=t.fn.on,r=t.fn.off;t.fn.on=function(t,r){return Et.call(this,n,window.addEventListener,t,r,arguments)},t.fn.off=function(t,n){return Et.call(this,r,window.removeEventListener,t,n,arguments)},gt=!0}}function Et(t,n,r,e,o){return"string"!=typeof r?t.apply(this,o):(r.split(/\s+/).forEach((function(t){st.indexOf(t)>=0&&(n(t,e),r=r.replace(t,""))})),""===r.trim()?this:t.apply(this,o))}var Ot={};function Tt(t){return Promise.resolve().then((function(){var n=Ot[R(t)];return n?t.status===m?(Pt(t,n),t):"UNLOADING"===t.status?n.promise.then((function(){return t})):t.status!==g?t:(t.status="UNLOADING",et(t,"unload").then((function(){return Pt(t,n),t})).catch((function(r){return function(t,n,r){delete Ot[R(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,s(r,t,b),n.reject(r)}(t,n,r),t}))):t}))}function Pt(t,n){delete Ot[R(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,t.status=m,n.resolve()}function bt(t,n,r,e){Ot[R(t)]={app:t,resolve:r,reject:e},Object.defineProperty(Ot[R(t)],"promise",{get:n})}function At(t){return Ot[t]}function Nt(){return Object.keys(Ot).map((function(t){return Ot[t].app})).filter(N)}var St=[];function _t(){return St.filter(A).map(R)}function Dt(){return St.map(R)}function Mt(t){var n=B(St,(function(n){return R(n)===t}));return n?n.status:null}function Ut(t,n,e,o){var i=function(t,n,e,o){var i,u={name:null,loadApp:null,activeWhen:null,customProps:null};return"object"===r(t)?(function(t){if(Array.isArray(t)||null===t)throw Error(p(39,!1));var n=["name","app","activeWhen","customProps"],e=Object.keys(t).reduce((function(t,r){return n.includes(r)?t:t.concat(r)}),[]);if(0!==e.length)throw Error(p(38,!1,n.join(", "),e.join(", ")));if("string"!=typeof t.name||0===t.name.length)throw Error(p(20,!1));if("object"!==r(t.app)&&"function"!=typeof t.app)throw Error(p(20,!1));var o=function(t){return"string"==typeof t||"function"==typeof t};if(!(o(t.activeWhen)||Array.isArray(t.activeWhen)&&t.activeWhen.every(o)))throw Error(p(24,!1));if(t.customProps&&("object"!==r(t.customProps)||Array.isArray(t.customProps)))throw Error(p(22,!1))}(t),u.name=t.name,u.loadApp=t.app,u.activeWhen=t.activeWhen,u.customProps=t.customProps):(function(t,n,e,o){if("string"!=typeof t||0===t.length)throw Error(p(20,!1));if(!n)throw Error(p(23,!1));if("function"!=typeof e)throw Error(p(24,!1));if(o&&("object"!==r(o)||Array.isArray(o)))throw Error(p(22,!1))}(t,n,e,o),u.name=t,u.loadApp=n,u.activeWhen=e,u.customProps=o),u.loadApp="function"!=typeof(i=u.loadApp)?function(){return Promise.resolve(i)}:i,u.customProps=function(t){return t||{}}(u.customProps),u.activeWhen=function(t){var n=Array.isArray(t)?t:[t];return n=n.map((function(t){return"function"==typeof t?t:(n=function(t){for(var n=0,r=!1,e="^",o=0;o<t.length;o++){var i=t[o];(!r&&":"===i||r&&"/"===i)&&u(o)}return u(t.length),new RegExp(e,"i");function u(o){var i=t.slice(n,o).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&");e+=r?"[^/]+/?":i,r=!r,n=o}}(t),function(t){var r=t.href.replace(t.origin,"");return n.test(r)});var n})),function(t){return n.some((function(n){return n(t)}))}}(u.activeWhen),u}(t,n,e,o);if(-1!==Dt().indexOf(i.name))throw Error(p(21,!1,i.name));St.push(x({loadErrorTime:null,status:m,parcels:{},devtools:{overlays:{options:{},selectors:[]}}},i)),at&&(yt(),$t())}function jt(t){return St.filter((function(n){return n.activeWhen(t)})).map(R)}function Rt(){return St.filter(U).filter(j).filter(_).filter(D)}function It(){return St.filter(U).filter(A).filter(M)}function Lt(){return St.filter(U).filter(N).filter(S).filter(D)}function xt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{waitForUnmount:!1};if("string"!=typeof t)throw Error(p(26,!1));var r=B(St,(function(n){return R(n)===t}));if(!r)throw Error(p(27,!1,t));var e,o=At(R(r));if(n&&n.waitForUnmount){if(o)return o.promise;var i=new Promise((function(t,n){bt(r,(function(){return i}),t,n)}));return i}return o?(e=o.promise,Bt(r,o.resolve,o.reject)):e=new Promise((function(t,n){bt(r,(function(){return e}),t,n),Bt(r,t,n)})),e}function Bt(t,n,r){K(t).then(Tt).then((function(){n(),setTimeout((function(){$t()}))})).catch(r)}var Gt=!1,Ct=[];function Wt(){return $t()}function $t(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0;if(Gt)return new Promise((function(t,r){Ct.push({resolve:t,reject:r,eventArguments:n})}));var r=[];return Ft()?(Gt=!0,c()):u();function i(t){return r.push.apply(r,o(t)),t}function u(){return Promise.resolve().then((function(){var t=i(Rt()).map(it);return Promise.all(t).then(f).then((function(){return[]})).catch((function(t){throw f(),t}))}))}function c(){return Promise.resolve().then((function(){window.dispatchEvent(new a("single-spa:before-routing-event",l()));var n=i(Nt()).map(Tt),e=i(It()).map(K).map((function(t){return t.then(Tt)})).concat(n),o=Promise.all(e),u=i(Rt()),c=u.map((function(t){return it(t).then($).then((function(t){return o.then((function(){return H(t)}))}))})),p=Lt().filter((function(t){return u.indexOf(t)<0})).map((function(t){return r.push(t),$(t).then((function(){return o})).then((function(){return H(t)}))}));return o.catch((function(t){throw f(),t})).then((function(){return f(),Promise.all(c.concat(p)).catch((function(n){throw t.forEach((function(t){return t.reject(n)})),n})).then(s)}))}))}function s(){var n=_t();t.forEach((function(t){return t.resolve(n)}));try{var e=0===r.length?"single-spa:no-app-change":"single-spa:app-change";window.dispatchEvent(new a(e,l())),window.dispatchEvent(new a("single-spa:routing-event",l()))}catch(t){setTimeout((function(){throw t}))}if(Gt=!1,Ct.length>0){var o=Ct;Ct=[],$t(o)}return n}function f(){t.forEach((function(t){lt(t.eventArguments)})),lt(n)}function l(){var t,o={},i=(e(t={},E,[]),e(t,g,[]),e(t,m,[]),e(t,b,[]),t);return r.forEach((function(t){var n=R(t),r=Mt(n);o[n]=r,(i[r]=i[r]||[]).push(n)})),{detail:{newAppStatuses:o,appsByNewStatus:i,totalAppChanges:r.length,originalEvent:null==n?void 0:n[0]}}}}var Kt=!1;function kt(t){var n;Kt=!0,t&&t.urlRerouteOnly&&(n=t.urlRerouteOnly,ut=n),at&&$t()}function Ft(){return Kt}at&&setTimeout((function(){Kt||console.warn(p(1,!1))}),5e3);var Ht={getRawAppData:function(){return[].concat(St)},reroute:$t,NOT_LOADED:m,toLoadPromise:it,toBootstrapPromise:$,unregisterApplication:function(t){if(!St.find((function(n){return R(n)===t})))throw Error(p(25,!1,t));return xt(t).then((function(){var n=St.findIndex((function(n){return R(n)===t}));St.splice(n,1)}))}};at&&window.__SINGLE_SPA_DEVTOOLS__&&(window.__SINGLE_SPA_DEVTOOLS__.exposedMethods=Ht)}}})); | ||
//# sourceMappingURL=single-spa.min.js.map |
@@ -1,1613 +0,1657 @@ | ||
/* single-spa@5.3.1 - UMD - dev */ | ||
/* single-spa@5.3.2 - UMD - dev */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.singleSpa = {})); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.singleSpa = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
var singleSpa = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
get start () { return start; }, | ||
get ensureJQuerySupport () { return ensureJQuerySupport; }, | ||
get setBootstrapMaxTime () { return setBootstrapMaxTime; }, | ||
get setMountMaxTime () { return setMountMaxTime; }, | ||
get setUnmountMaxTime () { return setUnmountMaxTime; }, | ||
get setUnloadMaxTime () { return setUnloadMaxTime; }, | ||
get registerApplication () { return registerApplication; }, | ||
get getMountedApps () { return getMountedApps; }, | ||
get getAppStatus () { return getAppStatus; }, | ||
get unloadApplication () { return unloadApplication; }, | ||
get checkActivityFunctions () { return checkActivityFunctions; }, | ||
get getAppNames () { return getAppNames; }, | ||
get navigateToUrl () { return navigateToUrl; }, | ||
get triggerAppChange () { return triggerAppChange; }, | ||
get addErrorHandler () { return addErrorHandler; }, | ||
get removeErrorHandler () { return removeErrorHandler; }, | ||
get mountRootParcel () { return mountRootParcel; }, | ||
get NOT_LOADED () { return NOT_LOADED; }, | ||
get LOADING_SOURCE_CODE () { return LOADING_SOURCE_CODE; }, | ||
get NOT_BOOTSTRAPPED () { return NOT_BOOTSTRAPPED; }, | ||
get BOOTSTRAPPING () { return BOOTSTRAPPING; }, | ||
get NOT_MOUNTED () { return NOT_MOUNTED; }, | ||
get MOUNTING () { return MOUNTING; }, | ||
get UPDATING () { return UPDATING; }, | ||
get LOAD_ERROR () { return LOAD_ERROR; }, | ||
get MOUNTED () { return MOUNTED; }, | ||
get UNMOUNTING () { return UNMOUNTING; }, | ||
get SKIP_BECAUSE_BROKEN () { return SKIP_BECAUSE_BROKEN; } | ||
}); | ||
var singleSpa = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
get start () { return start; }, | ||
get ensureJQuerySupport () { return ensureJQuerySupport; }, | ||
get setBootstrapMaxTime () { return setBootstrapMaxTime; }, | ||
get setMountMaxTime () { return setMountMaxTime; }, | ||
get setUnmountMaxTime () { return setUnmountMaxTime; }, | ||
get setUnloadMaxTime () { return setUnloadMaxTime; }, | ||
get registerApplication () { return registerApplication; }, | ||
get getMountedApps () { return getMountedApps; }, | ||
get getAppStatus () { return getAppStatus; }, | ||
get unloadApplication () { return unloadApplication; }, | ||
get checkActivityFunctions () { return checkActivityFunctions; }, | ||
get getAppNames () { return getAppNames; }, | ||
get navigateToUrl () { return navigateToUrl; }, | ||
get triggerAppChange () { return triggerAppChange; }, | ||
get addErrorHandler () { return addErrorHandler; }, | ||
get removeErrorHandler () { return removeErrorHandler; }, | ||
get mountRootParcel () { return mountRootParcel; }, | ||
get NOT_LOADED () { return NOT_LOADED; }, | ||
get LOADING_SOURCE_CODE () { return LOADING_SOURCE_CODE; }, | ||
get NOT_BOOTSTRAPPED () { return NOT_BOOTSTRAPPED; }, | ||
get BOOTSTRAPPING () { return BOOTSTRAPPING; }, | ||
get NOT_MOUNTED () { return NOT_MOUNTED; }, | ||
get MOUNTING () { return MOUNTING; }, | ||
get UPDATING () { return UPDATING; }, | ||
get LOAD_ERROR () { return LOAD_ERROR; }, | ||
get MOUNTED () { return MOUNTED; }, | ||
get UNMOUNTING () { return UNMOUNTING; }, | ||
get SKIP_BECAUSE_BROKEN () { return SKIP_BECAUSE_BROKEN; } | ||
}); | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
var NativeCustomEvent = commonjsGlobal.CustomEvent; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
function useNative () { | ||
try { | ||
var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } }); | ||
return 'cat' === p.type && 'bar' === p.detail.foo; | ||
} catch (e) { | ||
} | ||
return false; | ||
} | ||
return _typeof(obj); | ||
} | ||
/** | ||
* Cross-browser `CustomEvent` constructor. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent | ||
* | ||
* @public | ||
*/ | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
var customEvent = useNative() ? NativeCustomEvent : | ||
return obj; | ||
} | ||
// IE >= 9 | ||
'undefined' !== typeof document && 'function' === typeof document.createEvent ? function CustomEvent (type, params) { | ||
var e = document.createEvent('CustomEvent'); | ||
if (params) { | ||
e.initCustomEvent(type, params.bubbles, params.cancelable, params.detail); | ||
} else { | ||
e.initCustomEvent(type, false, false, void 0); | ||
} | ||
return e; | ||
} : | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
// IE <= 8 | ||
function CustomEvent (type, params) { | ||
var e = document.createEventObject(); | ||
e.type = type; | ||
if (params) { | ||
e.bubbles = Boolean(params.bubbles); | ||
e.cancelable = Boolean(params.cancelable); | ||
e.detail = params.detail; | ||
} else { | ||
e.bubbles = false; | ||
e.cancelable = false; | ||
e.detail = void 0; | ||
} | ||
return e; | ||
}; | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(n); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
return _typeof(obj); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
var errorHandlers = []; | ||
function handleAppError(err, app, newStatus) { | ||
var transformedErr = transformErr(err, app, newStatus); | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
if (errorHandlers.length) { | ||
errorHandlers.forEach(function (handler) { | ||
return handler(transformedErr); | ||
}); | ||
} else { | ||
setTimeout(function () { | ||
throw transformedErr; | ||
}); | ||
} | ||
} | ||
function addErrorHandler(handler) { | ||
if (typeof handler !== "function") { | ||
throw Error(formatErrorMessage(28, "a single-spa error handler must be a function")); | ||
} | ||
return arr2; | ||
} | ||
errorHandlers.push(handler); | ||
} | ||
function removeErrorHandler(handler) { | ||
if (typeof handler !== "function") { | ||
throw Error(formatErrorMessage(29, "a single-spa error handler must be a function")); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var removedSomething = false; | ||
errorHandlers = errorHandlers.filter(function (h) { | ||
var isHandler = h === handler; | ||
removedSomething = removedSomething || isHandler; | ||
return !isHandler; | ||
}); | ||
return removedSomething; | ||
} | ||
function formatErrorMessage(code, msg) { | ||
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
return "single-spa minified message #".concat(code, ": ").concat(msg ? msg + " " : "", "See https://single-spa.js.org/error/?code=").concat(code).concat(args.length ? "&arg=".concat(args.join("&arg=")) : ""); | ||
} | ||
function transformErr(ogErr, appOrParcel, newStatus) { | ||
var errPrefix = "".concat(objectType(appOrParcel), " '").concat(toName(appOrParcel), "' died in status ").concat(appOrParcel.status, ": "); | ||
var result; | ||
var NativeCustomEvent = commonjsGlobal.CustomEvent; | ||
if (ogErr instanceof Error) { | ||
try { | ||
ogErr.message = errPrefix + ogErr.message; | ||
} catch (err) { | ||
/* Some errors have read-only message properties, in which case there is nothing | ||
* that we can do. | ||
*/ | ||
} | ||
function useNative () { | ||
try { | ||
var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } }); | ||
return 'cat' === p.type && 'bar' === p.detail.foo; | ||
} catch (e) { | ||
} | ||
return false; | ||
} | ||
result = ogErr; | ||
} else { | ||
console.warn(formatErrorMessage(30, "While ".concat(appOrParcel.status, ", '").concat(toName(appOrParcel), "' rejected its lifecycle function promise with a non-Error. This will cause stack traces to not be accurate."), appOrParcel.status, toName(appOrParcel))); | ||
/** | ||
* Cross-browser `CustomEvent` constructor. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent | ||
* | ||
* @public | ||
*/ | ||
try { | ||
result = Error(errPrefix + JSON.stringify(ogErr)); | ||
} catch (err) { | ||
// If it's not an Error and you can't stringify it, then what else can you even do to it? | ||
result = ogErr; | ||
} | ||
} | ||
var customEvent = useNative() ? NativeCustomEvent : | ||
result.appOrParcelName = toName(appOrParcel); // We set the status after transforming the error so that the error message | ||
// references the state the application was in before the status change. | ||
// IE >= 9 | ||
'undefined' !== typeof document && 'function' === typeof document.createEvent ? function CustomEvent (type, params) { | ||
var e = document.createEvent('CustomEvent'); | ||
if (params) { | ||
e.initCustomEvent(type, params.bubbles, params.cancelable, params.detail); | ||
} else { | ||
e.initCustomEvent(type, false, false, void 0); | ||
} | ||
return e; | ||
} : | ||
appOrParcel.status = newStatus; | ||
return result; | ||
} | ||
// IE <= 8 | ||
function CustomEvent (type, params) { | ||
var e = document.createEventObject(); | ||
e.type = type; | ||
if (params) { | ||
e.bubbles = Boolean(params.bubbles); | ||
e.cancelable = Boolean(params.cancelable); | ||
e.detail = params.detail; | ||
} else { | ||
e.bubbles = false; | ||
e.cancelable = false; | ||
e.detail = void 0; | ||
} | ||
return e; | ||
}; | ||
var NOT_LOADED = "NOT_LOADED"; | ||
var LOADING_SOURCE_CODE = "LOADING_SOURCE_CODE"; | ||
var NOT_BOOTSTRAPPED = "NOT_BOOTSTRAPPED"; | ||
var BOOTSTRAPPING = "BOOTSTRAPPING"; | ||
var NOT_MOUNTED = "NOT_MOUNTED"; | ||
var MOUNTING = "MOUNTING"; | ||
var MOUNTED = "MOUNTED"; | ||
var UPDATING = "UPDATING"; | ||
var UNMOUNTING = "UNMOUNTING"; | ||
var UNLOADING = "UNLOADING"; | ||
var LOAD_ERROR = "LOAD_ERROR"; | ||
var SKIP_BECAUSE_BROKEN = "SKIP_BECAUSE_BROKEN"; | ||
function isActive(app) { | ||
return app.status === MOUNTED; | ||
} | ||
function isntActive(app) { | ||
return !isActive(app); | ||
} | ||
function isLoaded(app) { | ||
return app.status !== NOT_LOADED && app.status !== LOADING_SOURCE_CODE && app.status !== LOAD_ERROR; | ||
} | ||
function isntLoaded(app) { | ||
return !isLoaded(app); | ||
} | ||
function shouldBeActive(app) { | ||
try { | ||
return app.activeWhen(window.location); | ||
} catch (err) { | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
function shouldntBeActive(app) { | ||
try { | ||
return !shouldBeActive(app); | ||
} catch (err) { | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
function notSkipped(item) { | ||
return item !== SKIP_BECAUSE_BROKEN && (!item || item.status !== SKIP_BECAUSE_BROKEN); | ||
} | ||
function withoutLoadErrors(app) { | ||
return app.status === LOAD_ERROR ? new Date().getTime() - app.loadErrorTime >= 200 : true; | ||
} | ||
function toName(app) { | ||
return app.name; | ||
} | ||
function isParcel(appOrParcel) { | ||
return Boolean(appOrParcel.unmountThisParcel); | ||
} | ||
function objectType(appOrParcel) { | ||
return isParcel(appOrParcel) ? "parcel" : "application"; | ||
} | ||
var errorHandlers = []; | ||
function handleAppError(err, app, newStatus) { | ||
var transformedErr = transformErr(err, app, newStatus); | ||
// Object.assign() is not available in IE11. And the babel compiled output for object spread | ||
// syntax checks a bunch of Symbol stuff and is almost a kb. So this function is the smaller replacement. | ||
function assign() { | ||
for (var i = arguments.length - 1; i > 0; i--) { | ||
for (var key in arguments[i]) { | ||
if (key === "__proto__") { | ||
continue; | ||
} | ||
if (errorHandlers.length) { | ||
errorHandlers.forEach(function (handler) { | ||
return handler(transformedErr); | ||
}); | ||
} else { | ||
setTimeout(function () { | ||
throw transformedErr; | ||
}); | ||
} | ||
} | ||
function addErrorHandler(handler) { | ||
if (typeof handler !== "function") { | ||
throw Error(formatErrorMessage(28, "a single-spa error handler must be a function")); | ||
} | ||
arguments[i - 1][key] = arguments[i][key]; | ||
} | ||
} | ||
errorHandlers.push(handler); | ||
} | ||
function removeErrorHandler(handler) { | ||
if (typeof handler !== "function") { | ||
throw Error(formatErrorMessage(29, "a single-spa error handler must be a function")); | ||
} | ||
return arguments[0]; | ||
} | ||
var removedSomething = false; | ||
errorHandlers = errorHandlers.filter(function (h) { | ||
var isHandler = h === handler; | ||
removedSomething = removedSomething || isHandler; | ||
return !isHandler; | ||
}); | ||
return removedSomething; | ||
} | ||
function formatErrorMessage(code, msg) { | ||
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
/* the array.prototype.find polyfill on npmjs.com is ~20kb (not worth it) | ||
* and lodash is ~200kb (not worth it) | ||
*/ | ||
function find(arr, func) { | ||
for (var i = 0; i < arr.length; i++) { | ||
if (func(arr[i])) { | ||
return arr[i]; | ||
} | ||
} | ||
return "single-spa minified message #".concat(code, ": ").concat(msg ? msg + " " : "", "See https://single-spa.js.org/error/?code=").concat(code).concat(args.length ? "&arg=".concat(args.join("&arg=")) : ""); | ||
} | ||
function transformErr(ogErr, appOrParcel, newStatus) { | ||
var errPrefix = "".concat(objectType(appOrParcel), " '").concat(toName(appOrParcel), "' died in status ").concat(appOrParcel.status, ": "); | ||
var result; | ||
return null; | ||
} | ||
if (ogErr instanceof Error) { | ||
try { | ||
ogErr.message = errPrefix + ogErr.message; | ||
} catch (err) { | ||
/* Some errors have read-only message properties, in which case there is nothing | ||
* that we can do. | ||
*/ | ||
} | ||
function validLifecycleFn(fn) { | ||
return fn && (typeof fn === "function" || isArrayOfFns(fn)); | ||
result = ogErr; | ||
} else { | ||
console.warn(formatErrorMessage(30, "While ".concat(appOrParcel.status, ", '").concat(toName(appOrParcel), "' rejected its lifecycle function promise with a non-Error. This will cause stack traces to not be accurate."), appOrParcel.status, toName(appOrParcel))); | ||
function isArrayOfFns(arr) { | ||
return Array.isArray(arr) && !find(arr, function (item) { | ||
return typeof item !== "function"; | ||
}); | ||
} | ||
} | ||
function flattenFnArray(appOrParcel, lifecycle) { | ||
var fns = appOrParcel[lifecycle] || []; | ||
fns = Array.isArray(fns) ? fns : [fns]; | ||
try { | ||
result = Error(errPrefix + JSON.stringify(ogErr)); | ||
} catch (err) { | ||
// If it's not an Error and you can't stringify it, then what else can you even do to it? | ||
result = ogErr; | ||
} | ||
} | ||
if (fns.length === 0) { | ||
fns = [function () { | ||
return Promise.resolve(); | ||
}]; | ||
} | ||
result.appOrParcelName = toName(appOrParcel); // We set the status after transforming the error so that the error message | ||
// references the state the application was in before the status change. | ||
var type = objectType(appOrParcel); | ||
var name = toName(appOrParcel); | ||
return function (props) { | ||
return fns.reduce(function (resultPromise, fn, index) { | ||
return resultPromise.then(function () { | ||
var thisPromise = fn(props); | ||
return smellsLikeAPromise(thisPromise) ? thisPromise : Promise.reject(formatErrorMessage(15, "Within ".concat(type, " ").concat(name, ", the lifecycle function ").concat(lifecycle, " at array index ").concat(index, " did not return a promise"), type, name, lifecycle, index)); | ||
}); | ||
}, Promise.resolve()); | ||
}; | ||
} | ||
function smellsLikeAPromise(promise) { | ||
return promise && typeof promise.then === "function" && typeof promise.catch === "function"; | ||
} | ||
appOrParcel.status = newStatus; | ||
return result; | ||
} | ||
function toBootstrapPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== NOT_BOOTSTRAPPED) { | ||
return appOrParcel; | ||
} | ||
var NOT_LOADED = "NOT_LOADED"; | ||
var LOADING_SOURCE_CODE = "LOADING_SOURCE_CODE"; | ||
var NOT_BOOTSTRAPPED = "NOT_BOOTSTRAPPED"; | ||
var BOOTSTRAPPING = "BOOTSTRAPPING"; | ||
var NOT_MOUNTED = "NOT_MOUNTED"; | ||
var MOUNTING = "MOUNTING"; | ||
var MOUNTED = "MOUNTED"; | ||
var UPDATING = "UPDATING"; | ||
var UNMOUNTING = "UNMOUNTING"; | ||
var UNLOADING = "UNLOADING"; | ||
var LOAD_ERROR = "LOAD_ERROR"; | ||
var SKIP_BECAUSE_BROKEN = "SKIP_BECAUSE_BROKEN"; | ||
function isActive(app) { | ||
return app.status === MOUNTED; | ||
} | ||
function isntActive(app) { | ||
return !isActive(app); | ||
} | ||
function isLoaded(app) { | ||
return app.status !== NOT_LOADED && app.status !== LOADING_SOURCE_CODE && app.status !== LOAD_ERROR; | ||
} | ||
function isntLoaded(app) { | ||
return !isLoaded(app); | ||
} | ||
function shouldBeActive(app) { | ||
try { | ||
return app.activeWhen(window.location); | ||
} catch (err) { | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
function shouldntBeActive(app) { | ||
try { | ||
return !shouldBeActive(app); | ||
} catch (err) { | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
function notSkipped(item) { | ||
return item !== SKIP_BECAUSE_BROKEN && (!item || item.status !== SKIP_BECAUSE_BROKEN); | ||
} | ||
function withoutLoadErrors(app) { | ||
return app.status === LOAD_ERROR ? new Date().getTime() - app.loadErrorTime >= 200 : true; | ||
} | ||
function toName(app) { | ||
return app.name; | ||
} | ||
function isParcel(appOrParcel) { | ||
return Boolean(appOrParcel.unmountThisParcel); | ||
} | ||
function objectType(appOrParcel) { | ||
return isParcel(appOrParcel) ? "parcel" : "application"; | ||
} | ||
appOrParcel.status = BOOTSTRAPPING; | ||
return reasonableTime(appOrParcel, "bootstrap").then(function () { | ||
appOrParcel.status = NOT_MOUNTED; | ||
return appOrParcel; | ||
}).catch(function (err) { | ||
if (hardFail) { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
return appOrParcel; | ||
} | ||
}); | ||
}); | ||
} | ||
// Object.assign() is not available in IE11. And the babel compiled output for object spread | ||
// syntax checks a bunch of Symbol stuff and is almost a kb. So this function is the smaller replacement. | ||
function assign() { | ||
for (var i = arguments.length - 1; i > 0; i--) { | ||
for (var key in arguments[i]) { | ||
if (key === "__proto__") { | ||
continue; | ||
} | ||
function toUnmountPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== MOUNTED) { | ||
return appOrParcel; | ||
} | ||
arguments[i - 1][key] = arguments[i][key]; | ||
} | ||
} | ||
appOrParcel.status = UNMOUNTING; | ||
var unmountChildrenParcels = Object.keys(appOrParcel.parcels).map(function (parcelId) { | ||
return appOrParcel.parcels[parcelId].unmountThisParcel(); | ||
}); | ||
return Promise.all(unmountChildrenParcels).then(unmountAppOrParcel, function (parcelError) { | ||
// There is a parcel unmount error | ||
return unmountAppOrParcel().then(function () { | ||
// Unmounting the app/parcel succeeded, but unmounting its children parcels did not | ||
var parentError = Error(parcelError.message); | ||
return arguments[0]; | ||
} | ||
if (hardFail) { | ||
throw transformErr(parentError, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(parentError, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
}); | ||
}).then(function () { | ||
return appOrParcel; | ||
}); | ||
/* the array.prototype.find polyfill on npmjs.com is ~20kb (not worth it) | ||
* and lodash is ~200kb (not worth it) | ||
*/ | ||
function find(arr, func) { | ||
for (var i = 0; i < arr.length; i++) { | ||
if (func(arr[i])) { | ||
return arr[i]; | ||
} | ||
} | ||
function unmountAppOrParcel() { | ||
// We always try to unmount the appOrParcel, even if the children parcels failed to unmount. | ||
return reasonableTime(appOrParcel, "unmount").then(function () { | ||
// The appOrParcel needs to stay in a broken status if its children parcels fail to unmount | ||
{ | ||
appOrParcel.status = NOT_MOUNTED; | ||
} | ||
}).catch(function (err) { | ||
if (hardFail) { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
return null; | ||
} | ||
var beforeFirstMountFired = false; | ||
var firstMountFired = false; | ||
function toMountPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== NOT_MOUNTED) { | ||
return appOrParcel; | ||
} | ||
function validLifecycleFn(fn) { | ||
return fn && (typeof fn === "function" || isArrayOfFns(fn)); | ||
if (!beforeFirstMountFired) { | ||
window.dispatchEvent(new customEvent("single-spa:before-first-mount")); | ||
beforeFirstMountFired = true; | ||
} | ||
function isArrayOfFns(arr) { | ||
return Array.isArray(arr) && !find(arr, function (item) { | ||
return typeof item !== "function"; | ||
}); | ||
} | ||
} | ||
function flattenFnArray(appOrParcel, lifecycle) { | ||
var fns = appOrParcel[lifecycle] || []; | ||
fns = Array.isArray(fns) ? fns : [fns]; | ||
return reasonableTime(appOrParcel, "mount").then(function () { | ||
appOrParcel.status = MOUNTED; | ||
if (fns.length === 0) { | ||
fns = [function () { | ||
return Promise.resolve(); | ||
}]; | ||
} | ||
if (!firstMountFired) { | ||
window.dispatchEvent(new customEvent("single-spa:first-mount")); | ||
firstMountFired = true; | ||
} | ||
var type = objectType(appOrParcel); | ||
var name = toName(appOrParcel); | ||
return function (props) { | ||
return fns.reduce(function (resultPromise, fn, index) { | ||
return resultPromise.then(function () { | ||
var thisPromise = fn(props); | ||
return smellsLikeAPromise(thisPromise) ? thisPromise : Promise.reject(formatErrorMessage(15, "Within ".concat(type, " ").concat(name, ", the lifecycle function ").concat(lifecycle, " at array index ").concat(index, " did not return a promise"), type, name, lifecycle, index)); | ||
}); | ||
}, Promise.resolve()); | ||
}; | ||
} | ||
function smellsLikeAPromise(promise) { | ||
return promise && typeof promise.then === "function" && typeof promise.catch === "function"; | ||
} | ||
return appOrParcel; | ||
}).catch(function (err) { | ||
// If we fail to mount the appOrParcel, we should attempt to unmount it before putting in SKIP_BECAUSE_BROKEN | ||
// We temporarily put the appOrParcel into MOUNTED status so that toUnmountPromise actually attempts to unmount it | ||
// instead of just doing a no-op. | ||
appOrParcel.status = MOUNTED; | ||
return toUnmountPromise(appOrParcel, true).then(setSkipBecauseBroken, setSkipBecauseBroken); | ||
function toBootstrapPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== NOT_BOOTSTRAPPED) { | ||
return appOrParcel; | ||
} | ||
function setSkipBecauseBroken() { | ||
if (!hardFail) { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
return appOrParcel; | ||
} else { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
appOrParcel.status = BOOTSTRAPPING; | ||
return reasonableTime(appOrParcel, "bootstrap").then(function () { | ||
appOrParcel.status = NOT_MOUNTED; | ||
return appOrParcel; | ||
}).catch(function (err) { | ||
if (hardFail) { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
return appOrParcel; | ||
} | ||
}); | ||
}); | ||
} | ||
function toUpdatePromise(parcel) { | ||
return Promise.resolve().then(function () { | ||
if (parcel.status !== MOUNTED) { | ||
throw Error(formatErrorMessage(32, "Cannot update parcel '".concat(toName(parcel), "' because it is not mounted"), toName(parcel))); | ||
} | ||
function toUnmountPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== MOUNTED) { | ||
return appOrParcel; | ||
} | ||
parcel.status = UPDATING; | ||
return reasonableTime(parcel, "update").then(function () { | ||
parcel.status = MOUNTED; | ||
return parcel; | ||
}).catch(function (err) { | ||
throw transformErr(err, parcel, SKIP_BECAUSE_BROKEN); | ||
}); | ||
}); | ||
} | ||
appOrParcel.status = UNMOUNTING; | ||
var unmountChildrenParcels = Object.keys(appOrParcel.parcels).map(function (parcelId) { | ||
return appOrParcel.parcels[parcelId].unmountThisParcel(); | ||
}); | ||
return Promise.all(unmountChildrenParcels).then(unmountAppOrParcel, function (parcelError) { | ||
// There is a parcel unmount error | ||
return unmountAppOrParcel().then(function () { | ||
// Unmounting the app/parcel succeeded, but unmounting its children parcels did not | ||
var parentError = Error(parcelError.message); | ||
var parcelCount = 0; | ||
var rootParcels = { | ||
parcels: {} | ||
}; // This is a public api, exported to users of single-spa | ||
if (hardFail) { | ||
throw transformErr(parentError, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(parentError, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
}); | ||
}).then(function () { | ||
return appOrParcel; | ||
}); | ||
function mountRootParcel() { | ||
return mountParcel.apply(rootParcels, arguments); | ||
} | ||
function mountParcel(config, customProps) { | ||
var owningAppOrParcel = this; // Validate inputs | ||
function unmountAppOrParcel() { | ||
// We always try to unmount the appOrParcel, even if the children parcels failed to unmount. | ||
return reasonableTime(appOrParcel, "unmount").then(function () { | ||
// The appOrParcel needs to stay in a broken status if its children parcels fail to unmount | ||
{ | ||
appOrParcel.status = NOT_MOUNTED; | ||
} | ||
}).catch(function (err) { | ||
if (hardFail) { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} else { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
if (!config || _typeof(config) !== "object" && typeof config !== "function") { | ||
throw Error(formatErrorMessage(2, "Cannot mount parcel without a config object or config loading function")); | ||
} | ||
var beforeFirstMountFired = false; | ||
var firstMountFired = false; | ||
function toMountPromise(appOrParcel, hardFail) { | ||
return Promise.resolve().then(function () { | ||
if (appOrParcel.status !== NOT_MOUNTED) { | ||
return appOrParcel; | ||
} | ||
if (config.name && typeof config.name !== "string") { | ||
throw Error(formatErrorMessage(3, "Parcel name must be a string, if provided. Was given ".concat(_typeof(config.name)), _typeof(config.name))); | ||
} | ||
if (!beforeFirstMountFired) { | ||
window.dispatchEvent(new customEvent("single-spa:before-first-mount")); | ||
beforeFirstMountFired = true; | ||
} | ||
if (_typeof(customProps) !== "object") { | ||
throw Error(formatErrorMessage(4, "Parcel ".concat(name, " has invalid customProps -- must be an object but was given ").concat(_typeof(customProps)), name, _typeof(customProps))); | ||
} | ||
return reasonableTime(appOrParcel, "mount").then(function () { | ||
appOrParcel.status = MOUNTED; | ||
if (!customProps.domElement) { | ||
throw Error(formatErrorMessage(5, "Parcel ".concat(name, " cannot be mounted without a domElement provided as a prop"), name)); | ||
} | ||
if (!firstMountFired) { | ||
window.dispatchEvent(new customEvent("single-spa:first-mount")); | ||
firstMountFired = true; | ||
} | ||
var id = parcelCount++; | ||
var passedConfigLoadingFunction = typeof config === "function"; | ||
var configLoadingFunction = passedConfigLoadingFunction ? config : function () { | ||
return Promise.resolve(config); | ||
}; // Internal representation | ||
return appOrParcel; | ||
}).catch(function (err) { | ||
// If we fail to mount the appOrParcel, we should attempt to unmount it before putting in SKIP_BECAUSE_BROKEN | ||
// We temporarily put the appOrParcel into MOUNTED status so that toUnmountPromise actually attempts to unmount it | ||
// instead of just doing a no-op. | ||
appOrParcel.status = MOUNTED; | ||
return toUnmountPromise(appOrParcel, true).then(setSkipBecauseBroken, setSkipBecauseBroken); | ||
var parcel = { | ||
id: id, | ||
parcels: {}, | ||
status: passedConfigLoadingFunction ? LOADING_SOURCE_CODE : NOT_BOOTSTRAPPED, | ||
customProps: customProps, | ||
parentName: toName(owningAppOrParcel), | ||
unmountThisParcel: function unmountThisParcel() { | ||
if (parcel.status !== MOUNTED) { | ||
throw Error(formatErrorMessage(6, "Cannot unmount parcel '".concat(name, "' -- it is in a ").concat(parcel.status, " status"), name, parcel.status)); | ||
} | ||
function setSkipBecauseBroken() { | ||
if (!hardFail) { | ||
handleAppError(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
return appOrParcel; | ||
} else { | ||
throw transformErr(err, appOrParcel, SKIP_BECAUSE_BROKEN); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
return toUnmountPromise(parcel, true).then(function (value) { | ||
if (parcel.parentName) { | ||
delete owningAppOrParcel.parcels[parcel.id]; | ||
} | ||
function toUpdatePromise(parcel) { | ||
return Promise.resolve().then(function () { | ||
if (parcel.status !== MOUNTED) { | ||
throw Error(formatErrorMessage(32, "Cannot update parcel '".concat(toName(parcel), "' because it is not mounted"), toName(parcel))); | ||
} | ||
return value; | ||
}).then(function (value) { | ||
resolveUnmount(value); | ||
return value; | ||
}).catch(function (err) { | ||
parcel.status = SKIP_BECAUSE_BROKEN; | ||
rejectUnmount(err); | ||
throw err; | ||
}); | ||
} | ||
}; // We return an external representation | ||
parcel.status = UPDATING; | ||
return reasonableTime(parcel, "update").then(function () { | ||
parcel.status = MOUNTED; | ||
return parcel; | ||
}).catch(function (err) { | ||
throw transformErr(err, parcel, SKIP_BECAUSE_BROKEN); | ||
}); | ||
}); | ||
} | ||
var externalRepresentation; // Add to owning app or parcel | ||
var parcelCount = 0; | ||
var rootParcels = { | ||
parcels: {} | ||
}; // This is a public api, exported to users of single-spa | ||
owningAppOrParcel.parcels[id] = parcel; | ||
var loadPromise = configLoadingFunction(); | ||
function mountRootParcel() { | ||
return mountParcel.apply(rootParcels, arguments); | ||
} | ||
function mountParcel(config, customProps) { | ||
var owningAppOrParcel = this; // Validate inputs | ||
if (!loadPromise || typeof loadPromise.then !== "function") { | ||
throw Error(formatErrorMessage(7, "When mounting a parcel, the config loading function must return a promise that resolves with the parcel config")); | ||
} | ||
if (!config || _typeof(config) !== "object" && typeof config !== "function") { | ||
throw Error(formatErrorMessage(2, "Cannot mount parcel without a config object or config loading function")); | ||
} | ||
loadPromise = loadPromise.then(function (config) { | ||
if (!config) { | ||
throw Error(formatErrorMessage(8, "When mounting a parcel, the config loading function returned a promise that did not resolve with a parcel config")); | ||
} | ||
if (config.name && typeof config.name !== "string") { | ||
throw Error(formatErrorMessage(3, "Parcel name must be a string, if provided. Was given ".concat(_typeof(config.name)), _typeof(config.name))); | ||
} | ||
var name = config.name || "parcel-".concat(id); | ||
if (_typeof(customProps) !== "object") { | ||
throw Error(formatErrorMessage(4, "Parcel ".concat(name, " has invalid customProps -- must be an object but was given ").concat(_typeof(customProps)), name, _typeof(customProps))); | ||
} | ||
if (!validLifecycleFn(config.bootstrap)) { | ||
throw Error(formatErrorMessage(9, "Parcel ".concat(name, " must have a valid bootstrap function"), name)); | ||
} | ||
if (!customProps.domElement) { | ||
throw Error(formatErrorMessage(5, "Parcel ".concat(name, " cannot be mounted without a domElement provided as a prop"), name)); | ||
} | ||
if (!validLifecycleFn(config.mount)) { | ||
throw Error(formatErrorMessage(10, "Parcel ".concat(name, " must have a valid mount function"), name)); | ||
} | ||
var id = parcelCount++; | ||
var passedConfigLoadingFunction = typeof config === "function"; | ||
var configLoadingFunction = passedConfigLoadingFunction ? config : function () { | ||
return Promise.resolve(config); | ||
}; // Internal representation | ||
if (!validLifecycleFn(config.unmount)) { | ||
throw Error(formatErrorMessage(11, "Parcel ".concat(name, " must have a valid unmount function"), name)); | ||
} | ||
var parcel = { | ||
id: id, | ||
parcels: {}, | ||
status: passedConfigLoadingFunction ? LOADING_SOURCE_CODE : NOT_BOOTSTRAPPED, | ||
customProps: customProps, | ||
parentName: toName(owningAppOrParcel), | ||
unmountThisParcel: function unmountThisParcel() { | ||
if (parcel.status !== MOUNTED) { | ||
throw Error(formatErrorMessage(6, "Cannot unmount parcel '".concat(name, "' -- it is in a ").concat(parcel.status, " status"), name, parcel.status)); | ||
} | ||
if (config.update && !validLifecycleFn(config.update)) { | ||
throw Error(formatErrorMessage(12, "Parcel ".concat(name, " provided an invalid update function"), name)); | ||
} | ||
return toUnmountPromise(parcel, true).then(function (value) { | ||
if (parcel.parentName) { | ||
delete owningAppOrParcel.parcels[parcel.id]; | ||
} | ||
var bootstrap = flattenFnArray(config, "bootstrap"); | ||
var mount = flattenFnArray(config, "mount"); | ||
var unmount = flattenFnArray(config, "unmount"); | ||
parcel.status = NOT_BOOTSTRAPPED; | ||
parcel.name = name; | ||
parcel.bootstrap = bootstrap; | ||
parcel.mount = mount; | ||
parcel.unmount = unmount; | ||
parcel.timeouts = ensureValidAppTimeouts(config.timeouts); | ||
return value; | ||
}).then(function (value) { | ||
resolveUnmount(value); | ||
return value; | ||
}).catch(function (err) { | ||
parcel.status = SKIP_BECAUSE_BROKEN; | ||
rejectUnmount(err); | ||
throw err; | ||
}); | ||
} | ||
}; // We return an external representation | ||
if (config.update) { | ||
parcel.update = flattenFnArray(config, "update"); | ||
var externalRepresentation; // Add to owning app or parcel | ||
externalRepresentation.update = function (customProps) { | ||
parcel.customProps = customProps; | ||
return promiseWithoutReturnValue(toUpdatePromise(parcel)); | ||
}; | ||
} | ||
}); // Start bootstrapping and mounting | ||
// The .then() causes the work to be put on the event loop instead of happening immediately | ||
owningAppOrParcel.parcels[id] = parcel; | ||
var loadPromise = configLoadingFunction(); | ||
var bootstrapPromise = loadPromise.then(function () { | ||
return toBootstrapPromise(parcel, true); | ||
}); | ||
var mountPromise = bootstrapPromise.then(function () { | ||
return toMountPromise(parcel, true); | ||
}); | ||
var resolveUnmount, rejectUnmount; | ||
var unmountPromise = new Promise(function (resolve, reject) { | ||
resolveUnmount = resolve; | ||
rejectUnmount = reject; | ||
}); | ||
externalRepresentation = { | ||
mount: function mount() { | ||
return promiseWithoutReturnValue(Promise.resolve().then(function () { | ||
if (parcel.status !== NOT_MOUNTED) { | ||
throw Error(formatErrorMessage(13, "Cannot mount parcel '".concat(name, "' -- it is in a ").concat(parcel.status, " status"), name, parcel.status)); | ||
} // Add to owning app or parcel | ||
if (!loadPromise || typeof loadPromise.then !== "function") { | ||
throw Error(formatErrorMessage(7, "When mounting a parcel, the config loading function must return a promise that resolves with the parcel config")); | ||
} | ||
loadPromise = loadPromise.then(function (config) { | ||
if (!config) { | ||
throw Error(formatErrorMessage(8, "When mounting a parcel, the config loading function returned a promise that did not resolve with a parcel config")); | ||
} | ||
owningAppOrParcel.parcels[id] = parcel; | ||
return toMountPromise(parcel); | ||
})); | ||
}, | ||
unmount: function unmount() { | ||
return promiseWithoutReturnValue(parcel.unmountThisParcel()); | ||
}, | ||
getStatus: function getStatus() { | ||
return parcel.status; | ||
}, | ||
loadPromise: promiseWithoutReturnValue(loadPromise), | ||
bootstrapPromise: promiseWithoutReturnValue(bootstrapPromise), | ||
mountPromise: promiseWithoutReturnValue(mountPromise), | ||
unmountPromise: promiseWithoutReturnValue(unmountPromise) | ||
}; | ||
return externalRepresentation; | ||
} | ||
var name = config.name || "parcel-".concat(id); | ||
function promiseWithoutReturnValue(promise) { | ||
return promise.then(function () { | ||
return null; | ||
}); | ||
} | ||
if (!validLifecycleFn(config.bootstrap)) { | ||
throw Error(formatErrorMessage(9, "Parcel ".concat(name, " must have a valid bootstrap function"), name)); | ||
} | ||
function getProps(appOrParcel) { | ||
var result = assign({}, appOrParcel.customProps, { | ||
name: toName(appOrParcel), | ||
mountParcel: mountParcel.bind(appOrParcel), | ||
singleSpa: singleSpa | ||
}); | ||
if (!validLifecycleFn(config.mount)) { | ||
throw Error(formatErrorMessage(10, "Parcel ".concat(name, " must have a valid mount function"), name)); | ||
} | ||
if (isParcel(appOrParcel)) { | ||
result.unmountSelf = appOrParcel.unmountThisParcel; | ||
} | ||
if (!validLifecycleFn(config.unmount)) { | ||
throw Error(formatErrorMessage(11, "Parcel ".concat(name, " must have a valid unmount function"), name)); | ||
} | ||
return result; | ||
} | ||
if (config.update && !validLifecycleFn(config.update)) { | ||
throw Error(formatErrorMessage(12, "Parcel ".concat(name, " provided an invalid update function"), name)); | ||
} | ||
var defaultWarningMillis = 1000; | ||
var globalTimeoutConfig = { | ||
bootstrap: { | ||
millis: 4000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
mount: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
unmount: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
unload: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
update: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
} | ||
}; | ||
function setBootstrapMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(16, "bootstrap max time must be a positive integer number of milliseconds")); | ||
} | ||
var bootstrap = flattenFnArray(config, "bootstrap"); | ||
var mount = flattenFnArray(config, "mount"); | ||
var unmount = flattenFnArray(config, "unmount"); | ||
parcel.status = NOT_BOOTSTRAPPED; | ||
parcel.name = name; | ||
parcel.bootstrap = bootstrap; | ||
parcel.mount = mount; | ||
parcel.unmount = unmount; | ||
parcel.timeouts = ensureValidAppTimeouts(config.timeouts); | ||
globalTimeoutConfig.bootstrap = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setMountMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(17, "mount max time must be a positive integer number of milliseconds")); | ||
} | ||
if (config.update) { | ||
parcel.update = flattenFnArray(config, "update"); | ||
globalTimeoutConfig.mount = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setUnmountMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(18, "unmount max time must be a positive integer number of milliseconds")); | ||
} | ||
externalRepresentation.update = function (customProps) { | ||
parcel.customProps = customProps; | ||
return promiseWithoutReturnValue(toUpdatePromise(parcel)); | ||
}; | ||
} | ||
}); // Start bootstrapping and mounting | ||
// The .then() causes the work to be put on the event loop instead of happening immediately | ||
globalTimeoutConfig.unmount = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setUnloadMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(19, "unload max time must be a positive integer number of milliseconds")); | ||
} | ||
var bootstrapPromise = loadPromise.then(function () { | ||
return toBootstrapPromise(parcel, true); | ||
}); | ||
var mountPromise = bootstrapPromise.then(function () { | ||
return toMountPromise(parcel, true); | ||
}); | ||
var resolveUnmount, rejectUnmount; | ||
var unmountPromise = new Promise(function (resolve, reject) { | ||
resolveUnmount = resolve; | ||
rejectUnmount = reject; | ||
}); | ||
externalRepresentation = { | ||
mount: function mount() { | ||
return promiseWithoutReturnValue(Promise.resolve().then(function () { | ||
if (parcel.status !== NOT_MOUNTED) { | ||
throw Error(formatErrorMessage(13, "Cannot mount parcel '".concat(name, "' -- it is in a ").concat(parcel.status, " status"), name, parcel.status)); | ||
} // Add to owning app or parcel | ||
globalTimeoutConfig.unload = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function reasonableTime(appOrParcel, lifecycle) { | ||
var timeoutConfig = appOrParcel.timeouts[lifecycle]; | ||
var warningPeriod = timeoutConfig.warningMillis; | ||
var type = objectType(appOrParcel); | ||
return new Promise(function (resolve, reject) { | ||
var finished = false; | ||
var errored = false; | ||
appOrParcel[lifecycle](getProps(appOrParcel)).then(function (val) { | ||
finished = true; | ||
resolve(val); | ||
}).catch(function (val) { | ||
finished = true; | ||
reject(val); | ||
}); | ||
setTimeout(function () { | ||
return maybeTimingOut(1); | ||
}, warningPeriod); | ||
setTimeout(function () { | ||
return maybeTimingOut(true); | ||
}, timeoutConfig.millis); | ||
var errMsg = formatErrorMessage(31, "Lifecycle function ".concat(lifecycle, " for ").concat(type, " ").concat(toName(appOrParcel), " lifecycle did not resolve or reject for ").concat(timeoutConfig.millis, " ms."), lifecycle, type, toName(appOrParcel), timeoutConfig.millis); | ||
function maybeTimingOut(shouldError) { | ||
if (!finished) { | ||
if (shouldError === true) { | ||
errored = true; | ||
owningAppOrParcel.parcels[id] = parcel; | ||
return toMountPromise(parcel); | ||
})); | ||
}, | ||
unmount: function unmount() { | ||
return promiseWithoutReturnValue(parcel.unmountThisParcel()); | ||
}, | ||
getStatus: function getStatus() { | ||
return parcel.status; | ||
}, | ||
loadPromise: promiseWithoutReturnValue(loadPromise), | ||
bootstrapPromise: promiseWithoutReturnValue(bootstrapPromise), | ||
mountPromise: promiseWithoutReturnValue(mountPromise), | ||
unmountPromise: promiseWithoutReturnValue(unmountPromise) | ||
}; | ||
return externalRepresentation; | ||
} | ||
if (timeoutConfig.dieOnTimeout) { | ||
reject(Error(errMsg)); | ||
} else { | ||
console.error(errMsg); //don't resolve or reject, we're waiting this one out | ||
} | ||
} else if (!errored) { | ||
var numWarnings = shouldError; | ||
var numMillis = numWarnings * warningPeriod; | ||
console.warn(errMsg); | ||
function promiseWithoutReturnValue(promise) { | ||
return promise.then(function () { | ||
return null; | ||
}); | ||
} | ||
if (numMillis + warningPeriod < timeoutConfig.millis) { | ||
setTimeout(function () { | ||
return maybeTimingOut(numWarnings + 1); | ||
}, warningPeriod); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
function ensureValidAppTimeouts(timeouts) { | ||
var result = {}; | ||
function getProps(appOrParcel) { | ||
var result = assign({}, appOrParcel.customProps, { | ||
name: toName(appOrParcel), | ||
mountParcel: mountParcel.bind(appOrParcel), | ||
singleSpa: singleSpa | ||
}); | ||
for (var key in globalTimeoutConfig) { | ||
result[key] = assign({}, globalTimeoutConfig[key], timeouts && timeouts[key] || {}); | ||
} | ||
if (isParcel(appOrParcel)) { | ||
result.unmountSelf = appOrParcel.unmountThisParcel; | ||
} | ||
return result; | ||
} | ||
return result; | ||
} | ||
function toLoadPromise(app) { | ||
return Promise.resolve().then(function () { | ||
if (app.loadPromise) { | ||
return app.loadPromise; | ||
} | ||
var defaultWarningMillis = 1000; | ||
var globalTimeoutConfig = { | ||
bootstrap: { | ||
millis: 4000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
mount: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
unmount: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
unload: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
}, | ||
update: { | ||
millis: 3000, | ||
dieOnTimeout: false, | ||
warningMillis: defaultWarningMillis | ||
} | ||
}; | ||
function setBootstrapMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(16, "bootstrap max time must be a positive integer number of milliseconds")); | ||
} | ||
if (app.status !== NOT_LOADED && app.status !== LOAD_ERROR) { | ||
return app; | ||
} | ||
globalTimeoutConfig.bootstrap = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setMountMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(17, "mount max time must be a positive integer number of milliseconds")); | ||
} | ||
app.status = LOADING_SOURCE_CODE; | ||
var appOpts, isUserErr; | ||
return app.loadPromise = Promise.resolve().then(function () { | ||
var loadPromise = app.loadApp(getProps(app)); | ||
globalTimeoutConfig.mount = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setUnmountMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(18, "unmount max time must be a positive integer number of milliseconds")); | ||
} | ||
if (!smellsLikeAPromise(loadPromise)) { | ||
// The name of the app will be prepended to this error message inside of the handleAppError function | ||
isUserErr = true; | ||
throw Error(formatErrorMessage(33, "single-spa loading function did not return a promise. Check the second argument to registerApplication('".concat(toName(app), "', loadingFunction, activityFunction)"), toName(app))); | ||
} | ||
globalTimeoutConfig.unmount = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function setUnloadMaxTime(time, dieOnTimeout, warningMillis) { | ||
if (typeof time !== "number" || time <= 0) { | ||
throw Error(formatErrorMessage(19, "unload max time must be a positive integer number of milliseconds")); | ||
} | ||
return loadPromise.then(function (val) { | ||
app.loadErrorTime = null; | ||
appOpts = val; | ||
var validationErrMessage, validationErrCode; | ||
globalTimeoutConfig.unload = { | ||
millis: time, | ||
dieOnTimeout: dieOnTimeout, | ||
warningMillis: warningMillis || defaultWarningMillis | ||
}; | ||
} | ||
function reasonableTime(appOrParcel, lifecycle) { | ||
var timeoutConfig = appOrParcel.timeouts[lifecycle]; | ||
var warningPeriod = timeoutConfig.warningMillis; | ||
var type = objectType(appOrParcel); | ||
return new Promise(function (resolve, reject) { | ||
var finished = false; | ||
var errored = false; | ||
appOrParcel[lifecycle](getProps(appOrParcel)).then(function (val) { | ||
finished = true; | ||
resolve(val); | ||
}).catch(function (val) { | ||
finished = true; | ||
reject(val); | ||
}); | ||
setTimeout(function () { | ||
return maybeTimingOut(1); | ||
}, warningPeriod); | ||
setTimeout(function () { | ||
return maybeTimingOut(true); | ||
}, timeoutConfig.millis); | ||
var errMsg = formatErrorMessage(31, "Lifecycle function ".concat(lifecycle, " for ").concat(type, " ").concat(toName(appOrParcel), " lifecycle did not resolve or reject for ").concat(timeoutConfig.millis, " ms."), lifecycle, type, toName(appOrParcel), timeoutConfig.millis); | ||
if (_typeof(appOpts) !== "object") { | ||
validationErrCode = 34; | ||
function maybeTimingOut(shouldError) { | ||
if (!finished) { | ||
if (shouldError === true) { | ||
errored = true; | ||
{ | ||
validationErrMessage = "does not export anything"; | ||
} | ||
} | ||
if (timeoutConfig.dieOnTimeout) { | ||
reject(Error(errMsg)); | ||
} else { | ||
console.error(errMsg); //don't resolve or reject, we're waiting this one out | ||
} | ||
} else if (!errored) { | ||
var numWarnings = shouldError; | ||
var numMillis = numWarnings * warningPeriod; | ||
console.warn(errMsg); | ||
if (!validLifecycleFn(appOpts.bootstrap)) { | ||
validationErrCode = 35; | ||
if (numMillis + warningPeriod < timeoutConfig.millis) { | ||
setTimeout(function () { | ||
return maybeTimingOut(numWarnings + 1); | ||
}, warningPeriod); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
function ensureValidAppTimeouts(timeouts) { | ||
var result = {}; | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
for (var key in globalTimeoutConfig) { | ||
result[key] = assign({}, globalTimeoutConfig[key], timeouts && timeouts[key] || {}); | ||
} | ||
if (!validLifecycleFn(appOpts.mount)) { | ||
validationErrCode = 36; | ||
return result; | ||
} | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
function toLoadPromise(app) { | ||
return Promise.resolve().then(function () { | ||
if (app.loadPromise) { | ||
return app.loadPromise; | ||
} | ||
if (!validLifecycleFn(appOpts.unmount)) { | ||
validationErrCode = 37; | ||
if (app.status !== NOT_LOADED && app.status !== LOAD_ERROR) { | ||
return app; | ||
} | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
app.status = LOADING_SOURCE_CODE; | ||
var appOpts, isUserErr; | ||
return app.loadPromise = Promise.resolve().then(function () { | ||
var loadPromise = app.loadApp(getProps(app)); | ||
var type = objectType(appOpts); | ||
if (!smellsLikeAPromise(loadPromise)) { | ||
// The name of the app will be prepended to this error message inside of the handleAppError function | ||
isUserErr = true; | ||
throw Error(formatErrorMessage(33, "single-spa loading function did not return a promise. Check the second argument to registerApplication('".concat(toName(app), "', loadingFunction, activityFunction)"), toName(app))); | ||
} | ||
if (validationErrCode) { | ||
var appOptsStr; | ||
return loadPromise.then(function (val) { | ||
app.loadErrorTime = null; | ||
appOpts = val; | ||
var validationErrMessage, validationErrCode; | ||
try { | ||
appOptsStr = JSON.stringify(appOpts); | ||
} catch (_unused) {} | ||
if (_typeof(appOpts) !== "object") { | ||
validationErrCode = 34; | ||
console.error(formatErrorMessage(validationErrCode, "The loading function for single-spa ".concat(type, " '").concat(toName(app), "' resolved with the following, which does not have bootstrap, mount, and unmount functions"), type, toName(app), appOptsStr), appOpts); | ||
handleAppError(validationErrMessage, app, SKIP_BECAUSE_BROKEN); | ||
return app; | ||
} | ||
{ | ||
validationErrMessage = "does not export anything"; | ||
} | ||
} | ||
if (appOpts.devtools && appOpts.devtools.overlays) { | ||
app.devtools.overlays = assign({}, app.devtools.overlays, appOpts.devtools.overlays); | ||
} | ||
if (!validLifecycleFn(appOpts.bootstrap)) { | ||
validationErrCode = 35; | ||
app.status = NOT_BOOTSTRAPPED; | ||
app.bootstrap = flattenFnArray(appOpts, "bootstrap"); | ||
app.mount = flattenFnArray(appOpts, "mount"); | ||
app.unmount = flattenFnArray(appOpts, "unmount"); | ||
app.unload = flattenFnArray(appOpts, "unload"); | ||
app.timeouts = ensureValidAppTimeouts(appOpts.timeouts); | ||
delete app.loadPromise; | ||
return app; | ||
}); | ||
}).catch(function (err) { | ||
delete app.loadPromise; | ||
var newStatus; | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
if (isUserErr) { | ||
newStatus = SKIP_BECAUSE_BROKEN; | ||
} else { | ||
newStatus = LOAD_ERROR; | ||
app.loadErrorTime = new Date().getTime(); | ||
} | ||
if (!validLifecycleFn(appOpts.mount)) { | ||
validationErrCode = 36; | ||
handleAppError(err, app, newStatus); | ||
return app; | ||
}); | ||
}); | ||
} | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
var isInBrowser = typeof window !== "undefined"; | ||
if (!validLifecycleFn(appOpts.unmount)) { | ||
validationErrCode = 37; | ||
/* We capture navigation event listeners so that we can make sure | ||
* that application navigation listeners are not called until | ||
* single-spa has ensured that the correct applications are | ||
* unmounted and mounted. | ||
*/ | ||
{ | ||
validationErrMessage = "does not export a bootstrap function or array of functions"; | ||
} | ||
} | ||
var capturedEventListeners = { | ||
hashchange: [], | ||
popstate: [] | ||
}; | ||
var routingEventsListeningTo = ["hashchange", "popstate"]; | ||
function navigateToUrl(obj) { | ||
var url; | ||
var type = objectType(appOpts); | ||
if (typeof obj === "string") { | ||
url = obj; | ||
} else if (this && this.href) { | ||
url = this.href; | ||
} else if (obj && obj.currentTarget && obj.currentTarget.href && obj.preventDefault) { | ||
url = obj.currentTarget.href; | ||
obj.preventDefault(); | ||
} else { | ||
throw Error(formatErrorMessage(14, "singleSpaNavigate/navigateToUrl must be either called with a string url, with an <a> tag as its context, or with an event whose currentTarget is an <a> tag")); | ||
} | ||
if (validationErrCode) { | ||
var appOptsStr; | ||
var current = parseUri(window.location.href); | ||
var destination = parseUri(url); | ||
try { | ||
appOptsStr = JSON.stringify(appOpts); | ||
} catch (_unused) {} | ||
if (url.indexOf("#") === 0) { | ||
window.location.hash = destination.hash; | ||
} else if (current.host !== destination.host && destination.host) { | ||
{ | ||
window.location.href = url; | ||
} | ||
} else if (destination.pathname === current.pathname && destination.search === current.pathname) { | ||
window.location.hash = destination.hash; | ||
} else { | ||
// different path, host, or query params | ||
window.history.pushState(null, null, url); | ||
} | ||
} | ||
function callCapturedEventListeners(eventArguments) { | ||
var _this = this; | ||
console.error(formatErrorMessage(validationErrCode, "The loading function for single-spa ".concat(type, " '").concat(toName(app), "' resolved with the following, which does not have bootstrap, mount, and unmount functions"), type, toName(app), appOptsStr), appOpts); | ||
handleAppError(validationErrMessage, app, SKIP_BECAUSE_BROKEN); | ||
return app; | ||
} | ||
if (eventArguments) { | ||
var eventType = eventArguments[0].type; | ||
if (appOpts.devtools && appOpts.devtools.overlays) { | ||
app.devtools.overlays = assign({}, app.devtools.overlays, appOpts.devtools.overlays); | ||
} | ||
if (routingEventsListeningTo.indexOf(eventType) >= 0) { | ||
capturedEventListeners[eventType].forEach(function (listener) { | ||
try { | ||
// The error thrown by application event listener should not break single-spa down. | ||
// Just like https://github.com/single-spa/single-spa/blob/85f5042dff960e40936f3a5069d56fc9477fac04/src/navigation/reroute.js#L140-L146 did | ||
listener.apply(_this, eventArguments); | ||
} catch (e) { | ||
setTimeout(function () { | ||
throw e; | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
var urlRerouteOnly; | ||
function setUrlRerouteOnly(val) { | ||
urlRerouteOnly = val; | ||
} | ||
app.status = NOT_BOOTSTRAPPED; | ||
app.bootstrap = flattenFnArray(appOpts, "bootstrap"); | ||
app.mount = flattenFnArray(appOpts, "mount"); | ||
app.unmount = flattenFnArray(appOpts, "unmount"); | ||
app.unload = flattenFnArray(appOpts, "unload"); | ||
app.timeouts = ensureValidAppTimeouts(appOpts.timeouts); | ||
delete app.loadPromise; | ||
return app; | ||
}); | ||
}).catch(function (err) { | ||
delete app.loadPromise; | ||
var newStatus; | ||
function urlReroute() { | ||
reroute([], arguments); | ||
} | ||
if (isUserErr) { | ||
newStatus = SKIP_BECAUSE_BROKEN; | ||
} else { | ||
newStatus = LOAD_ERROR; | ||
app.loadErrorTime = new Date().getTime(); | ||
} | ||
if (isInBrowser) { | ||
// We will trigger an app change for any routing events. | ||
window.addEventListener("hashchange", urlReroute); | ||
window.addEventListener("popstate", urlReroute); // Monkeypatch addEventListener so that we can ensure correct timing | ||
handleAppError(err, app, newStatus); | ||
return app; | ||
}); | ||
}); | ||
} | ||
var originalAddEventListener = window.addEventListener; | ||
var originalRemoveEventListener = window.removeEventListener; | ||
var isInBrowser = typeof window !== "undefined"; | ||
window.addEventListener = function (eventName, fn) { | ||
if (typeof fn === "function") { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0 && !find(capturedEventListeners[eventName], function (listener) { | ||
return listener === fn; | ||
})) { | ||
capturedEventListeners[eventName].push(fn); | ||
return; | ||
} | ||
} | ||
/* We capture navigation event listeners so that we can make sure | ||
* that application navigation listeners are not called until | ||
* single-spa has ensured that the correct applications are | ||
* unmounted and mounted. | ||
*/ | ||
return originalAddEventListener.apply(this, arguments); | ||
}; | ||
var capturedEventListeners = { | ||
hashchange: [], | ||
popstate: [] | ||
}; | ||
var routingEventsListeningTo = ["hashchange", "popstate"]; | ||
function navigateToUrl(obj) { | ||
var url; | ||
window.removeEventListener = function (eventName, listenerFn) { | ||
if (typeof listenerFn === "function") { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0) { | ||
capturedEventListeners[eventName] = capturedEventListeners[eventName].filter(function (fn) { | ||
return fn !== listenerFn; | ||
}); | ||
return; | ||
} | ||
} | ||
if (typeof obj === "string") { | ||
url = obj; | ||
} else if (this && this.href) { | ||
url = this.href; | ||
} else if (obj && obj.currentTarget && obj.currentTarget.href && obj.preventDefault) { | ||
url = obj.currentTarget.href; | ||
obj.preventDefault(); | ||
} else { | ||
throw Error(formatErrorMessage(14, "singleSpaNavigate/navigateToUrl must be either called with a string url, with an <a> tag as its context, or with an event whose currentTarget is an <a> tag")); | ||
} | ||
return originalRemoveEventListener.apply(this, arguments); | ||
}; | ||
var current = parseUri(window.location.href); | ||
var destination = parseUri(url); | ||
window.history.pushState = patchedUpdateState(window.history.pushState); | ||
window.history.replaceState = patchedUpdateState(window.history.replaceState); | ||
if (url.indexOf("#") === 0) { | ||
window.location.hash = destination.hash; | ||
} else if (current.host !== destination.host && destination.host) { | ||
{ | ||
window.location.href = url; | ||
} | ||
} else if (destination.pathname === current.pathname && destination.search === current.pathname) { | ||
window.location.hash = destination.hash; | ||
} else { | ||
// different path, host, or query params | ||
window.history.pushState(null, null, url); | ||
} | ||
} | ||
function callCapturedEventListeners(eventArguments) { | ||
var _this = this; | ||
function patchedUpdateState(updateState) { | ||
return function () { | ||
var urlBefore = window.location.href; | ||
var result = updateState.apply(this, arguments); | ||
var urlAfter = window.location.href; | ||
if (eventArguments) { | ||
var eventType = eventArguments[0].type; | ||
if (!urlRerouteOnly || urlBefore !== urlAfter) { | ||
urlReroute(createPopStateEvent(window.history.state)); | ||
} | ||
if (routingEventsListeningTo.indexOf(eventType) >= 0) { | ||
capturedEventListeners[eventType].forEach(function (listener) { | ||
try { | ||
// The error thrown by application event listener should not break single-spa down. | ||
// Just like https://github.com/single-spa/single-spa/blob/85f5042dff960e40936f3a5069d56fc9477fac04/src/navigation/reroute.js#L140-L146 did | ||
listener.apply(_this, eventArguments); | ||
} catch (e) { | ||
setTimeout(function () { | ||
throw e; | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
var urlRerouteOnly; | ||
function setUrlRerouteOnly(val) { | ||
urlRerouteOnly = val; | ||
} | ||
return result; | ||
}; | ||
} | ||
function urlReroute() { | ||
reroute([], arguments); | ||
} | ||
function createPopStateEvent(state) { | ||
// https://github.com/single-spa/single-spa/issues/224 and https://github.com/single-spa/single-spa-angular/issues/49 | ||
// We need a popstate event even though the browser doesn't do one by default when you call replaceState, so that | ||
// all the applications can reroute. | ||
try { | ||
return new PopStateEvent("popstate", { | ||
state: state | ||
}); | ||
} catch (err) { | ||
// IE 11 compatibility https://github.com/single-spa/single-spa/issues/299 | ||
// https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-html5e/bd560f47-b349-4d2c-baa8-f1560fb489dd | ||
var evt = document.createEvent("PopStateEvent"); | ||
evt.initPopStateEvent("popstate", false, false, state); | ||
return evt; | ||
} | ||
} | ||
/* For convenience in `onclick` attributes, we expose a global function for navigating to | ||
* whatever an <a> tag's href is. | ||
*/ | ||
if (isInBrowser) { | ||
// We will trigger an app change for any routing events. | ||
window.addEventListener("hashchange", urlReroute); | ||
window.addEventListener("popstate", urlReroute); // Monkeypatch addEventListener so that we can ensure correct timing | ||
var originalAddEventListener = window.addEventListener; | ||
var originalRemoveEventListener = window.removeEventListener; | ||
window.singleSpaNavigate = navigateToUrl; | ||
} | ||
window.addEventListener = function (eventName, fn) { | ||
if (typeof fn === "function") { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0 && !find(capturedEventListeners[eventName], function (listener) { | ||
return listener === fn; | ||
})) { | ||
capturedEventListeners[eventName].push(fn); | ||
return; | ||
} | ||
} | ||
function parseUri(str) { | ||
var anchor = document.createElement("a"); | ||
anchor.href = str; | ||
return anchor; | ||
} | ||
return originalAddEventListener.apply(this, arguments); | ||
}; | ||
var hasInitialized = false; | ||
function ensureJQuerySupport() { | ||
var jQuery = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.jQuery; | ||
window.removeEventListener = function (eventName, listenerFn) { | ||
if (typeof listenerFn === "function") { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0) { | ||
capturedEventListeners[eventName] = capturedEventListeners[eventName].filter(function (fn) { | ||
return fn !== listenerFn; | ||
}); | ||
return; | ||
} | ||
} | ||
if (!jQuery) { | ||
if (window.$ && window.$.fn && window.$.fn.jquery) { | ||
jQuery = window.$; | ||
} | ||
} | ||
return originalRemoveEventListener.apply(this, arguments); | ||
}; | ||
if (jQuery && !hasInitialized) { | ||
var originalJQueryOn = jQuery.fn.on; | ||
var originalJQueryOff = jQuery.fn.off; | ||
window.history.pushState = patchedUpdateState(window.history.pushState); | ||
window.history.replaceState = patchedUpdateState(window.history.replaceState); | ||
jQuery.fn.on = function (eventString, fn) { | ||
return captureRoutingEvents.call(this, originalJQueryOn, window.addEventListener, eventString, fn, arguments); | ||
}; | ||
function patchedUpdateState(updateState) { | ||
return function () { | ||
var urlBefore = window.location.href; | ||
var result = updateState.apply(this, arguments); | ||
var urlAfter = window.location.href; | ||
jQuery.fn.off = function (eventString, fn) { | ||
return captureRoutingEvents.call(this, originalJQueryOff, window.removeEventListener, eventString, fn, arguments); | ||
}; | ||
if (!urlRerouteOnly || urlBefore !== urlAfter) { | ||
urlReroute(createPopStateEvent(window.history.state)); | ||
} | ||
hasInitialized = true; | ||
} | ||
} | ||
return result; | ||
}; | ||
} | ||
function captureRoutingEvents(originalJQueryFunction, nativeFunctionToCall, eventString, fn, originalArgs) { | ||
if (typeof eventString !== "string") { | ||
return originalJQueryFunction.apply(this, originalArgs); | ||
} | ||
function createPopStateEvent(state) { | ||
// https://github.com/single-spa/single-spa/issues/224 and https://github.com/single-spa/single-spa-angular/issues/49 | ||
// We need a popstate event even though the browser doesn't do one by default when you call replaceState, so that | ||
// all the applications can reroute. | ||
try { | ||
return new PopStateEvent("popstate", { | ||
state: state | ||
}); | ||
} catch (err) { | ||
// IE 11 compatibility https://github.com/single-spa/single-spa/issues/299 | ||
// https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-html5e/bd560f47-b349-4d2c-baa8-f1560fb489dd | ||
var evt = document.createEvent("PopStateEvent"); | ||
evt.initPopStateEvent("popstate", false, false, state); | ||
return evt; | ||
} | ||
} | ||
/* For convenience in `onclick` attributes, we expose a global function for navigating to | ||
* whatever an <a> tag's href is. | ||
*/ | ||
var eventNames = eventString.split(/\s+/); | ||
eventNames.forEach(function (eventName) { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0) { | ||
nativeFunctionToCall(eventName, fn); | ||
eventString = eventString.replace(eventName, ""); | ||
} | ||
}); | ||
if (eventString.trim() === "") { | ||
return this; | ||
} else { | ||
return originalJQueryFunction.apply(this, originalArgs); | ||
} | ||
} | ||
window.singleSpaNavigate = navigateToUrl; | ||
} | ||
var appsToUnload = {}; | ||
function toUnloadPromise(app) { | ||
return Promise.resolve().then(function () { | ||
var unloadInfo = appsToUnload[toName(app)]; | ||
function parseUri(str) { | ||
var anchor = document.createElement("a"); | ||
anchor.href = str; | ||
return anchor; | ||
} | ||
if (!unloadInfo) { | ||
/* No one has called unloadApplication for this app, | ||
*/ | ||
return app; | ||
} | ||
var hasInitialized = false; | ||
function ensureJQuerySupport() { | ||
var jQuery = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.jQuery; | ||
if (app.status === NOT_LOADED) { | ||
/* This app is already unloaded. We just need to clean up | ||
* anything that still thinks we need to unload the app. | ||
*/ | ||
finishUnloadingApp(app, unloadInfo); | ||
return app; | ||
} | ||
if (!jQuery) { | ||
if (window.$ && window.$.fn && window.$.fn.jquery) { | ||
jQuery = window.$; | ||
} | ||
} | ||
if (app.status === UNLOADING) { | ||
/* Both unloadApplication and reroute want to unload this app. | ||
* It only needs to be done once, though. | ||
*/ | ||
return unloadInfo.promise.then(function () { | ||
return app; | ||
}); | ||
} | ||
if (jQuery && !hasInitialized) { | ||
var originalJQueryOn = jQuery.fn.on; | ||
var originalJQueryOff = jQuery.fn.off; | ||
if (app.status !== NOT_MOUNTED) { | ||
/* The app cannot be unloaded until it is unmounted. | ||
*/ | ||
return app; | ||
} | ||
jQuery.fn.on = function (eventString, fn) { | ||
return captureRoutingEvents.call(this, originalJQueryOn, window.addEventListener, eventString, fn, arguments); | ||
}; | ||
app.status = UNLOADING; | ||
return reasonableTime(app, "unload").then(function () { | ||
finishUnloadingApp(app, unloadInfo); | ||
return app; | ||
}).catch(function (err) { | ||
errorUnloadingApp(app, unloadInfo, err); | ||
return app; | ||
}); | ||
}); | ||
} | ||
jQuery.fn.off = function (eventString, fn) { | ||
return captureRoutingEvents.call(this, originalJQueryOff, window.removeEventListener, eventString, fn, arguments); | ||
}; | ||
function finishUnloadingApp(app, unloadInfo) { | ||
delete appsToUnload[toName(app)]; // Unloaded apps don't have lifecycles | ||
hasInitialized = true; | ||
} | ||
} | ||
delete app.bootstrap; | ||
delete app.mount; | ||
delete app.unmount; | ||
delete app.unload; | ||
app.status = NOT_LOADED; | ||
/* resolve the promise of whoever called unloadApplication. | ||
* This should be done after all other cleanup/bookkeeping | ||
*/ | ||
function captureRoutingEvents(originalJQueryFunction, nativeFunctionToCall, eventString, fn, originalArgs) { | ||
if (typeof eventString !== "string") { | ||
return originalJQueryFunction.apply(this, originalArgs); | ||
} | ||
unloadInfo.resolve(); | ||
} | ||
var eventNames = eventString.split(/\s+/); | ||
eventNames.forEach(function (eventName) { | ||
if (routingEventsListeningTo.indexOf(eventName) >= 0) { | ||
nativeFunctionToCall(eventName, fn); | ||
eventString = eventString.replace(eventName, ""); | ||
} | ||
}); | ||
function errorUnloadingApp(app, unloadInfo, err) { | ||
delete appsToUnload[toName(app)]; // Unloaded apps don't have lifecycles | ||
if (eventString.trim() === "") { | ||
return this; | ||
} else { | ||
return originalJQueryFunction.apply(this, originalArgs); | ||
} | ||
} | ||
delete app.bootstrap; | ||
delete app.mount; | ||
delete app.unmount; | ||
delete app.unload; | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
unloadInfo.reject(err); | ||
} | ||
var appsToUnload = {}; | ||
function toUnloadPromise(app) { | ||
return Promise.resolve().then(function () { | ||
var unloadInfo = appsToUnload[toName(app)]; | ||
function addAppToUnload(app, promiseGetter, resolve, reject) { | ||
appsToUnload[toName(app)] = { | ||
app: app, | ||
resolve: resolve, | ||
reject: reject | ||
}; | ||
Object.defineProperty(appsToUnload[toName(app)], "promise", { | ||
get: promiseGetter | ||
}); | ||
} | ||
function getAppUnloadInfo(appName) { | ||
return appsToUnload[appName]; | ||
} | ||
function getAppsToUnload() { | ||
return Object.keys(appsToUnload).map(function (appName) { | ||
return appsToUnload[appName].app; | ||
}).filter(isntActive); | ||
} | ||
if (!unloadInfo) { | ||
/* No one has called unloadApplication for this app, | ||
*/ | ||
return app; | ||
} | ||
var apps = []; | ||
function getMountedApps() { | ||
return apps.filter(isActive).map(toName); | ||
} | ||
function getAppNames() { | ||
return apps.map(toName); | ||
} // used in devtools, not (currently) exposed as a single-spa API | ||
if (app.status === NOT_LOADED) { | ||
/* This app is already unloaded. We just need to clean up | ||
* anything that still thinks we need to unload the app. | ||
*/ | ||
finishUnloadingApp(app, unloadInfo); | ||
return app; | ||
} | ||
function getRawAppData() { | ||
return [].concat(apps); | ||
} | ||
function getAppStatus(appName) { | ||
var app = find(apps, function (app) { | ||
return toName(app) === appName; | ||
}); | ||
return app ? app.status : null; | ||
} | ||
function registerApplication(appNameOrConfig, appOrLoadApp, activeWhen, customProps) { | ||
var registration = sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps); | ||
if (getAppNames().indexOf(registration.name) !== -1) throw Error(formatErrorMessage(21, "There is already an app registered with name ".concat(registration.name), registration.name)); | ||
apps.push(assign({ | ||
loadErrorTime: null, | ||
status: NOT_LOADED, | ||
parcels: {}, | ||
devtools: { | ||
overlays: { | ||
options: {}, | ||
selectors: [] | ||
} | ||
} | ||
}, registration)); | ||
if (app.status === UNLOADING) { | ||
/* Both unloadApplication and reroute want to unload this app. | ||
* It only needs to be done once, though. | ||
*/ | ||
return unloadInfo.promise.then(function () { | ||
return app; | ||
}); | ||
} | ||
if (isInBrowser) { | ||
ensureJQuerySupport(); | ||
reroute(); | ||
} | ||
} | ||
function checkActivityFunctions(location) { | ||
return apps.filter(function (app) { | ||
return app.activeWhen(location); | ||
}).map(toName); | ||
} | ||
function getAppsToLoad() { | ||
return apps.filter(notSkipped).filter(withoutLoadErrors).filter(isntLoaded).filter(shouldBeActive); | ||
} | ||
function getAppsToUnmount() { | ||
return apps.filter(notSkipped).filter(isActive).filter(shouldntBeActive); | ||
} | ||
function getAppsToMount() { | ||
return apps.filter(notSkipped).filter(isntActive).filter(isLoaded).filter(shouldBeActive); | ||
} | ||
function unregisterApplication(appName) { | ||
if (!apps.find(function (app) { | ||
return toName(app) === appName; | ||
})) { | ||
throw Error(formatErrorMessage(25, "Cannot unregister application '".concat(appName, "' because no such application has been registered"), appName)); | ||
} | ||
if (app.status !== NOT_MOUNTED) { | ||
/* The app cannot be unloaded until it is unmounted. | ||
*/ | ||
return app; | ||
} | ||
return unloadApplication(appName).then(function () { | ||
var appIndex = apps.findIndex(function (app) { | ||
return toName(app) === appName; | ||
}); | ||
apps.splice(appIndex, 1); | ||
}); | ||
} | ||
function unloadApplication(appName) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
waitForUnmount: false | ||
}; | ||
app.status = UNLOADING; | ||
return reasonableTime(app, "unload").then(function () { | ||
finishUnloadingApp(app, unloadInfo); | ||
return app; | ||
}).catch(function (err) { | ||
errorUnloadingApp(app, unloadInfo, err); | ||
return app; | ||
}); | ||
}); | ||
} | ||
if (typeof appName !== "string") { | ||
throw Error(formatErrorMessage(26, "unloadApplication requires a string 'appName'")); | ||
} | ||
function finishUnloadingApp(app, unloadInfo) { | ||
delete appsToUnload[toName(app)]; // Unloaded apps don't have lifecycles | ||
var app = find(apps, function (App) { | ||
return toName(App) === appName; | ||
}); | ||
delete app.bootstrap; | ||
delete app.mount; | ||
delete app.unmount; | ||
delete app.unload; | ||
app.status = NOT_LOADED; | ||
/* resolve the promise of whoever called unloadApplication. | ||
* This should be done after all other cleanup/bookkeeping | ||
*/ | ||
if (!app) { | ||
throw Error(formatErrorMessage(27, "Could not unload application '".concat(appName, "' because no such application has been registered"), appName)); | ||
} | ||
unloadInfo.resolve(); | ||
} | ||
var appUnloadInfo = getAppUnloadInfo(toName(app)); | ||
function errorUnloadingApp(app, unloadInfo, err) { | ||
delete appsToUnload[toName(app)]; // Unloaded apps don't have lifecycles | ||
if (opts && opts.waitForUnmount) { | ||
// We need to wait for unmount before unloading the app | ||
if (appUnloadInfo) { | ||
// Someone else is already waiting for this, too | ||
return appUnloadInfo.promise; | ||
} else { | ||
// We're the first ones wanting the app to be resolved. | ||
var promise = new Promise(function (resolve, reject) { | ||
addAppToUnload(app, function () { | ||
return promise; | ||
}, resolve, reject); | ||
}); | ||
return promise; | ||
} | ||
} else { | ||
/* We should unmount the app, unload it, and remount it immediately. | ||
*/ | ||
var resultPromise; | ||
delete app.bootstrap; | ||
delete app.mount; | ||
delete app.unmount; | ||
delete app.unload; | ||
handleAppError(err, app, SKIP_BECAUSE_BROKEN); | ||
unloadInfo.reject(err); | ||
} | ||
if (appUnloadInfo) { | ||
// Someone else is already waiting for this app to unload | ||
resultPromise = appUnloadInfo.promise; | ||
immediatelyUnloadApp(app, appUnloadInfo.resolve, appUnloadInfo.reject); | ||
} else { | ||
// We're the first ones wanting the app to be resolved. | ||
resultPromise = new Promise(function (resolve, reject) { | ||
addAppToUnload(app, function () { | ||
return resultPromise; | ||
}, resolve, reject); | ||
immediatelyUnloadApp(app, resolve, reject); | ||
}); | ||
} | ||
function addAppToUnload(app, promiseGetter, resolve, reject) { | ||
appsToUnload[toName(app)] = { | ||
app: app, | ||
resolve: resolve, | ||
reject: reject | ||
}; | ||
Object.defineProperty(appsToUnload[toName(app)], "promise", { | ||
get: promiseGetter | ||
}); | ||
} | ||
function getAppUnloadInfo(appName) { | ||
return appsToUnload[appName]; | ||
} | ||
function getAppsToUnload() { | ||
return Object.keys(appsToUnload).map(function (appName) { | ||
return appsToUnload[appName].app; | ||
}).filter(isntActive); | ||
} | ||
return resultPromise; | ||
} | ||
} | ||
var apps = []; | ||
function getMountedApps() { | ||
return apps.filter(isActive).map(toName); | ||
} | ||
function getAppNames() { | ||
return apps.map(toName); | ||
} // used in devtools, not (currently) exposed as a single-spa API | ||
function immediatelyUnloadApp(app, resolve, reject) { | ||
toUnmountPromise(app).then(toUnloadPromise).then(function () { | ||
resolve(); | ||
setTimeout(function () { | ||
// reroute, but the unload promise is done | ||
reroute(); | ||
}); | ||
}).catch(reject); | ||
} | ||
function getRawAppData() { | ||
return [].concat(apps); | ||
} | ||
function getAppStatus(appName) { | ||
var app = find(apps, function (app) { | ||
return toName(app) === appName; | ||
}); | ||
return app ? app.status : null; | ||
} | ||
function registerApplication(appNameOrConfig, appOrLoadApp, activeWhen, customProps) { | ||
var registration = sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps); | ||
if (getAppNames().indexOf(registration.name) !== -1) throw Error(formatErrorMessage(21, "There is already an app registered with name ".concat(registration.name), registration.name)); | ||
apps.push(assign({ | ||
loadErrorTime: null, | ||
status: NOT_LOADED, | ||
parcels: {}, | ||
devtools: { | ||
overlays: { | ||
options: {}, | ||
selectors: [] | ||
} | ||
} | ||
}, registration)); | ||
function validateRegisterWithArguments(name, appOrLoadApp, activeWhen, customProps) { | ||
if (typeof name !== "string" || name.length === 0) throw Error(formatErrorMessage(20, "The 1st argument to registerApplication must be a non-empty string 'appName'")); | ||
if (!appOrLoadApp) throw Error(formatErrorMessage(23, "The 2nd argument to registerApplication must be an application or loading application function")); | ||
if (typeof activeWhen !== "function") throw Error(formatErrorMessage(24, "The 3rd argument to registerApplication must be an activeWhen function")); | ||
if (!!customProps && (_typeof(customProps) !== "object" || Array.isArray(customProps))) throw Error(formatErrorMessage(22, "The optional 4th argument is a customProps and must be an object")); | ||
} | ||
if (isInBrowser) { | ||
ensureJQuerySupport(); | ||
reroute(); | ||
} | ||
} | ||
function checkActivityFunctions(location) { | ||
return apps.filter(function (app) { | ||
return app.activeWhen(location); | ||
}).map(toName); | ||
} | ||
function getAppsToLoad() { | ||
return apps.filter(notSkipped).filter(withoutLoadErrors).filter(isntLoaded).filter(shouldBeActive); | ||
} | ||
function getAppsToUnmount() { | ||
return apps.filter(notSkipped).filter(isActive).filter(shouldntBeActive); | ||
} | ||
function getAppsToMount() { | ||
return apps.filter(notSkipped).filter(isntActive).filter(isLoaded).filter(shouldBeActive); | ||
} | ||
function unregisterApplication(appName) { | ||
if (!apps.find(function (app) { | ||
return toName(app) === appName; | ||
})) { | ||
throw Error(formatErrorMessage(25, "Cannot unregister application '".concat(appName, "' because no such application has been registered"), appName)); | ||
} | ||
function validateRegisterWithConfig(config) { | ||
if (Array.isArray(config) || config === null) throw Error(formatErrorMessage(39, "Configuration object can't be an Array or null!")); | ||
var validKeys = ["name", "app", "activeWhen", "customProps"]; | ||
var invalidKeys = Object.keys(config).reduce(function (invalidKeys, prop) { | ||
return validKeys.includes(prop) ? invalidKeys : invalidKeys.concat(prop); | ||
}, []); | ||
if (invalidKeys.length !== 0) throw Error(formatErrorMessage(38, "The configuration object accepts only: ".concat(validKeys.join(", "), ". Invalid keys: ").concat(invalidKeys.join(", "), "."), validKeys.join(", "), invalidKeys.join(", "))); | ||
if (typeof config.name !== "string" || config.name.length === 0) throw Error(formatErrorMessage(20, "The config.name on registerApplication must be a non-empty string")); | ||
if (_typeof(config.app) !== "object" && typeof config.app !== "function") throw Error(formatErrorMessage(20, "The config.app on registerApplication must be an application or a loading function")); | ||
return unloadApplication(appName).then(function () { | ||
var appIndex = apps.findIndex(function (app) { | ||
return toName(app) === appName; | ||
}); | ||
apps.splice(appIndex, 1); | ||
}); | ||
} | ||
function unloadApplication(appName) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
waitForUnmount: false | ||
}; | ||
var allowsStringAndFunction = function allowsStringAndFunction(activeWhen) { | ||
return typeof activeWhen === "string" || typeof activeWhen === "function"; | ||
}; | ||
if (typeof appName !== "string") { | ||
throw Error(formatErrorMessage(26, "unloadApplication requires a string 'appName'")); | ||
} | ||
if (!allowsStringAndFunction(config.activeWhen) && !(Array.isArray(config.activeWhen) && config.activeWhen.every(allowsStringAndFunction))) throw Error(formatErrorMessage(24, "The config.activeWhen on registerApplication must be a string, function or an array with both")); | ||
if (!(!config.customProps || _typeof(config.customProps) === "object" && !Array.isArray(config.customProps))) throw Error(formatErrorMessage(22, "The optional config.customProps must be an object")); | ||
} | ||
var app = find(apps, function (App) { | ||
return toName(App) === appName; | ||
}); | ||
function sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps) { | ||
var usingObjectAPI = _typeof(appNameOrConfig) === "object"; | ||
var registration = { | ||
name: null, | ||
loadApp: null, | ||
activeWhen: null, | ||
customProps: null | ||
}; | ||
if (!app) { | ||
throw Error(formatErrorMessage(27, "Could not unload application '".concat(appName, "' because no such application has been registered"), appName)); | ||
} | ||
if (usingObjectAPI) { | ||
validateRegisterWithConfig(appNameOrConfig); | ||
registration.name = appNameOrConfig.name; | ||
registration.loadApp = appNameOrConfig.app; | ||
registration.activeWhen = appNameOrConfig.activeWhen; | ||
registration.customProps = appNameOrConfig.customProps; | ||
} else { | ||
validateRegisterWithArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps); | ||
registration.name = appNameOrConfig; | ||
registration.loadApp = appOrLoadApp; | ||
registration.activeWhen = activeWhen; | ||
registration.customProps = customProps; | ||
} | ||
var appUnloadInfo = getAppUnloadInfo(toName(app)); | ||
registration.loadApp = sanitizeLoadApp(registration.loadApp); | ||
registration.customProps = sanitizeCustomProps(registration.customProps); | ||
registration.activeWhen = sanitizeActiveWhen(registration.activeWhen); | ||
return registration; | ||
} | ||
if (opts && opts.waitForUnmount) { | ||
// We need to wait for unmount before unloading the app | ||
if (appUnloadInfo) { | ||
// Someone else is already waiting for this, too | ||
return appUnloadInfo.promise; | ||
} else { | ||
// We're the first ones wanting the app to be resolved. | ||
var promise = new Promise(function (resolve, reject) { | ||
addAppToUnload(app, function () { | ||
return promise; | ||
}, resolve, reject); | ||
}); | ||
return promise; | ||
} | ||
} else { | ||
/* We should unmount the app, unload it, and remount it immediately. | ||
*/ | ||
var resultPromise; | ||
function sanitizeLoadApp(loadApp) { | ||
if (typeof loadApp !== "function") { | ||
return function () { | ||
return Promise.resolve(loadApp); | ||
}; | ||
} | ||
if (appUnloadInfo) { | ||
// Someone else is already waiting for this app to unload | ||
resultPromise = appUnloadInfo.promise; | ||
immediatelyUnloadApp(app, appUnloadInfo.resolve, appUnloadInfo.reject); | ||
} else { | ||
// We're the first ones wanting the app to be resolved. | ||
resultPromise = new Promise(function (resolve, reject) { | ||
addAppToUnload(app, function () { | ||
return resultPromise; | ||
}, resolve, reject); | ||
immediatelyUnloadApp(app, resolve, reject); | ||
}); | ||
} | ||
return loadApp; | ||
} | ||
return resultPromise; | ||
} | ||
} | ||
function sanitizeCustomProps(customProps) { | ||
return customProps ? customProps : {}; | ||
} | ||
function immediatelyUnloadApp(app, resolve, reject) { | ||
toUnmountPromise(app).then(toUnloadPromise).then(function () { | ||
resolve(); | ||
setTimeout(function () { | ||
// reroute, but the unload promise is done | ||
reroute(); | ||
}); | ||
}).catch(reject); | ||
} | ||
function sanitizeActiveWhen(activeWhen) { | ||
var activeWhenArray = Array.isArray(activeWhen) ? activeWhen : [activeWhen]; | ||
activeWhenArray = activeWhenArray.map(function (activeWhenOrPath) { | ||
return typeof activeWhenOrPath === "function" ? activeWhenOrPath : pathToActiveWhen(activeWhenOrPath); | ||
}); | ||
return function (location) { | ||
return activeWhenArray.some(function (activeWhen) { | ||
return activeWhen(location); | ||
}); | ||
}; | ||
} | ||
function validateRegisterWithArguments(name, appOrLoadApp, activeWhen, customProps) { | ||
if (typeof name !== "string" || name.length === 0) throw Error(formatErrorMessage(20, "The 1st argument to registerApplication must be a non-empty string 'appName'")); | ||
if (!appOrLoadApp) throw Error(formatErrorMessage(23, "The 2nd argument to registerApplication must be an application or loading application function")); | ||
if (typeof activeWhen !== "function") throw Error(formatErrorMessage(24, "The 3rd argument to registerApplication must be an activeWhen function")); | ||
if (!!customProps && (_typeof(customProps) !== "object" || Array.isArray(customProps))) throw Error(formatErrorMessage(22, "The optional 4th argument is a customProps and must be an object")); | ||
} | ||
function pathToActiveWhen(path) { | ||
var regex = toDynamicPathValidatorRegex(path); | ||
return function (location) { | ||
var route = location.href.replace(location.origin, ""); | ||
return regex.test(route); | ||
}; | ||
} | ||
function validateRegisterWithConfig(config) { | ||
if (Array.isArray(config) || config === null) throw Error(formatErrorMessage(39, "Configuration object can't be an Array or null!")); | ||
var validKeys = ["name", "app", "activeWhen", "customProps"]; | ||
var invalidKeys = Object.keys(config).reduce(function (invalidKeys, prop) { | ||
return validKeys.includes(prop) ? invalidKeys : invalidKeys.concat(prop); | ||
}, []); | ||
if (invalidKeys.length !== 0) throw Error(formatErrorMessage(38, "The configuration object accepts only: ".concat(validKeys.join(", "), ". Invalid keys: ").concat(invalidKeys.join(", "), "."), validKeys.join(", "), invalidKeys.join(", "))); | ||
if (typeof config.name !== "string" || config.name.length === 0) throw Error(formatErrorMessage(20, "The config.name on registerApplication must be a non-empty string")); | ||
if (_typeof(config.app) !== "object" && typeof config.app !== "function") throw Error(formatErrorMessage(20, "The config.app on registerApplication must be an application or a loading function")); | ||
function toDynamicPathValidatorRegex(path) { | ||
var lastIndex = 0, | ||
inDynamic = false, | ||
regexStr = "^"; | ||
var allowsStringAndFunction = function allowsStringAndFunction(activeWhen) { | ||
return typeof activeWhen === "string" || typeof activeWhen === "function"; | ||
}; | ||
for (var charIndex = 0; charIndex < path.length; charIndex++) { | ||
var char = path[charIndex]; | ||
var startOfDynamic = !inDynamic && char === ":"; | ||
var endOfDynamic = inDynamic && char === "/"; | ||
if (!allowsStringAndFunction(config.activeWhen) && !(Array.isArray(config.activeWhen) && config.activeWhen.every(allowsStringAndFunction))) throw Error(formatErrorMessage(24, "The config.activeWhen on registerApplication must be a string, function or an array with both")); | ||
if (!(!config.customProps || _typeof(config.customProps) === "object" && !Array.isArray(config.customProps))) throw Error(formatErrorMessage(22, "The optional config.customProps must be an object")); | ||
} | ||
if (startOfDynamic || endOfDynamic) { | ||
appendToRegex(charIndex); | ||
} | ||
} | ||
function sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps) { | ||
var usingObjectAPI = _typeof(appNameOrConfig) === "object"; | ||
var registration = { | ||
name: null, | ||
loadApp: null, | ||
activeWhen: null, | ||
customProps: null | ||
}; | ||
appendToRegex(path.length); | ||
return new RegExp(regexStr, "i"); | ||
if (usingObjectAPI) { | ||
validateRegisterWithConfig(appNameOrConfig); | ||
registration.name = appNameOrConfig.name; | ||
registration.loadApp = appNameOrConfig.app; | ||
registration.activeWhen = appNameOrConfig.activeWhen; | ||
registration.customProps = appNameOrConfig.customProps; | ||
} else { | ||
validateRegisterWithArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps); | ||
registration.name = appNameOrConfig; | ||
registration.loadApp = appOrLoadApp; | ||
registration.activeWhen = activeWhen; | ||
registration.customProps = customProps; | ||
} | ||
function appendToRegex(index) { | ||
var anyCharMaybeTrailingSlashRegex = "[^/]+/?"; | ||
var commonStringSubPath = escapeStrRegex(path.slice(lastIndex, index)); | ||
regexStr += inDynamic ? anyCharMaybeTrailingSlashRegex : commonStringSubPath; | ||
inDynamic = !inDynamic; | ||
lastIndex = index; | ||
} | ||
registration.loadApp = sanitizeLoadApp(registration.loadApp); | ||
registration.customProps = sanitizeCustomProps(registration.customProps); | ||
registration.activeWhen = sanitizeActiveWhen(registration.activeWhen); | ||
return registration; | ||
} | ||
function escapeStrRegex(str) { | ||
// borrowed from https://github.com/sindresorhus/escape-string-regexp/blob/master/index.js | ||
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&"); | ||
} | ||
} | ||
function sanitizeLoadApp(loadApp) { | ||
if (typeof loadApp !== "function") { | ||
return function () { | ||
return Promise.resolve(loadApp); | ||
}; | ||
} | ||
var appChangeUnderway = false, | ||
peopleWaitingOnAppChange = []; | ||
function triggerAppChange() { | ||
// Call reroute with no arguments, intentionally | ||
return reroute(); | ||
} | ||
function reroute() { | ||
var pendingPromises = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var eventArguments = arguments.length > 1 ? arguments[1] : undefined; | ||
return loadApp; | ||
} | ||
if (appChangeUnderway) { | ||
return new Promise(function (resolve, reject) { | ||
peopleWaitingOnAppChange.push({ | ||
resolve: resolve, | ||
reject: reject, | ||
eventArguments: eventArguments | ||
}); | ||
}); | ||
} | ||
function sanitizeCustomProps(customProps) { | ||
return customProps ? customProps : {}; | ||
} | ||
var wasNoOp = true; | ||
function sanitizeActiveWhen(activeWhen) { | ||
var activeWhenArray = Array.isArray(activeWhen) ? activeWhen : [activeWhen]; | ||
activeWhenArray = activeWhenArray.map(function (activeWhenOrPath) { | ||
return typeof activeWhenOrPath === "function" ? activeWhenOrPath : pathToActiveWhen(activeWhenOrPath); | ||
}); | ||
return function (location) { | ||
return activeWhenArray.some(function (activeWhen) { | ||
return activeWhen(location); | ||
}); | ||
}; | ||
} | ||
if (isStarted()) { | ||
appChangeUnderway = true; | ||
return performAppChanges(); | ||
} else { | ||
return loadApps(); | ||
} | ||
function pathToActiveWhen(path) { | ||
var regex = toDynamicPathValidatorRegex(path); | ||
return function (location) { | ||
var route = location.href.replace(location.origin, ""); | ||
return regex.test(route); | ||
}; | ||
} | ||
function loadApps() { | ||
return Promise.resolve().then(function () { | ||
var loadPromises = getAppsToLoad().map(toLoadPromise); | ||
function toDynamicPathValidatorRegex(path) { | ||
var lastIndex = 0, | ||
inDynamic = false, | ||
regexStr = "^"; | ||
if (loadPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
for (var charIndex = 0; charIndex < path.length; charIndex++) { | ||
var char = path[charIndex]; | ||
var startOfDynamic = !inDynamic && char === ":"; | ||
var endOfDynamic = inDynamic && char === "/"; | ||
return Promise.all(loadPromises).then(callAllEventListeners) // there are no mounted apps, before start() is called, so we always return [] | ||
.then(function () { | ||
return []; | ||
}).catch(function (err) { | ||
callAllEventListeners(); | ||
throw err; | ||
}); | ||
}); | ||
} | ||
if (startOfDynamic || endOfDynamic) { | ||
appendToRegex(charIndex); | ||
} | ||
} | ||
function performAppChanges() { | ||
return Promise.resolve().then(function () { | ||
window.dispatchEvent(new customEvent("single-spa:before-routing-event", getCustomEventDetail())); | ||
var unloadPromises = getAppsToUnload().map(toUnloadPromise); | ||
var unmountUnloadPromises = getAppsToUnmount().map(toUnmountPromise).map(function (unmountPromise) { | ||
return unmountPromise.then(toUnloadPromise); | ||
}); | ||
var allUnmountPromises = unmountUnloadPromises.concat(unloadPromises); | ||
appendToRegex(path.length); | ||
return new RegExp(regexStr, "i"); | ||
if (allUnmountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
function appendToRegex(index) { | ||
var anyCharMaybeTrailingSlashRegex = "[^/]+/?"; | ||
var commonStringSubPath = escapeStrRegex(path.slice(lastIndex, index)); | ||
regexStr += inDynamic ? anyCharMaybeTrailingSlashRegex : commonStringSubPath; | ||
inDynamic = !inDynamic; | ||
lastIndex = index; | ||
} | ||
var unmountAllPromise = Promise.all(allUnmountPromises); | ||
var appsToLoad = getAppsToLoad(); | ||
/* We load and bootstrap apps while other apps are unmounting, but we | ||
* wait to mount the app until all apps are finishing unmounting | ||
*/ | ||
function escapeStrRegex(str) { | ||
// borrowed from https://github.com/sindresorhus/escape-string-regexp/blob/master/index.js | ||
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&"); | ||
} | ||
} | ||
var loadThenMountPromises = appsToLoad.map(function (app) { | ||
return toLoadPromise(app).then(toBootstrapPromise).then(function (app) { | ||
return unmountAllPromise.then(function () { | ||
return toMountPromise(app); | ||
}); | ||
}); | ||
}); | ||
var appChangeUnderway = false, | ||
peopleWaitingOnAppChange = []; | ||
function triggerAppChange() { | ||
// Call reroute with no arguments, intentionally | ||
return reroute(); | ||
} | ||
function reroute() { | ||
var pendingPromises = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var eventArguments = arguments.length > 1 ? arguments[1] : undefined; | ||
if (loadThenMountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
/* These are the apps that are already bootstrapped and just need | ||
* to be mounted. They each wait for all unmounting apps to finish up | ||
* before they mount. | ||
*/ | ||
if (appChangeUnderway) { | ||
return new Promise(function (resolve, reject) { | ||
peopleWaitingOnAppChange.push({ | ||
resolve: resolve, | ||
reject: reject, | ||
eventArguments: eventArguments | ||
}); | ||
}); | ||
} | ||
var appsThatChanged = []; | ||
var mountPromises = getAppsToMount().filter(function (appToMount) { | ||
return appsToLoad.indexOf(appToMount) < 0; | ||
}).map(function (appToMount) { | ||
return toBootstrapPromise(appToMount).then(function () { | ||
return unmountAllPromise; | ||
}).then(function () { | ||
return toMountPromise(appToMount); | ||
}); | ||
}); | ||
if (isStarted()) { | ||
appChangeUnderway = true; | ||
return performAppChanges(); | ||
} else { | ||
return loadApps(); | ||
} | ||
if (mountPromises.length > 0) { | ||
wasNoOp = false; | ||
} | ||
function addChangedApps(apps) { | ||
appsThatChanged.push.apply(appsThatChanged, _toConsumableArray(apps)); | ||
return apps; | ||
} | ||
return unmountAllPromise.catch(function (err) { | ||
callAllEventListeners(); | ||
throw err; | ||
}).then(function () { | ||
/* Now that the apps that needed to be unmounted are unmounted, their DOM navigation | ||
* events (like hashchange or popstate) should have been cleaned up. So it's safe | ||
* to let the remaining captured event listeners to handle about the DOM event. | ||
*/ | ||
callAllEventListeners(); | ||
return Promise.all(loadThenMountPromises.concat(mountPromises)).catch(function (err) { | ||
pendingPromises.forEach(function (promise) { | ||
return promise.reject(err); | ||
}); | ||
throw err; | ||
}).then(finishUpAndReturn); | ||
}); | ||
}); | ||
} | ||
function loadApps() { | ||
return Promise.resolve().then(function () { | ||
var loadPromises = addChangedApps(getAppsToLoad()).map(toLoadPromise); | ||
return Promise.all(loadPromises).then(callAllEventListeners) // there are no mounted apps, before start() is called, so we always return [] | ||
.then(function () { | ||
return []; | ||
}).catch(function (err) { | ||
callAllEventListeners(); | ||
throw err; | ||
}); | ||
}); | ||
} | ||
function finishUpAndReturn() { | ||
var returnValue = getMountedApps(); | ||
pendingPromises.forEach(function (promise) { | ||
return promise.resolve(returnValue); | ||
}); | ||
function performAppChanges() { | ||
return Promise.resolve().then(function () { | ||
window.dispatchEvent(new customEvent("single-spa:before-routing-event", getCustomEventDetail())); | ||
var unloadPromises = addChangedApps(getAppsToUnload()).map(toUnloadPromise); | ||
var unmountUnloadPromises = addChangedApps(getAppsToUnmount()).map(toUnmountPromise).map(function (unmountPromise) { | ||
return unmountPromise.then(toUnloadPromise); | ||
}); | ||
var allUnmountPromises = unmountUnloadPromises.concat(unloadPromises); | ||
var unmountAllPromise = Promise.all(allUnmountPromises); | ||
var appsToLoad = addChangedApps(getAppsToLoad()); | ||
/* We load and bootstrap apps while other apps are unmounting, but we | ||
* wait to mount the app until all apps are finishing unmounting | ||
*/ | ||
try { | ||
var appChangeEventName = wasNoOp ? "single-spa:no-app-change" : "single-spa:app-change"; | ||
window.dispatchEvent(new customEvent(appChangeEventName, getCustomEventDetail())); | ||
window.dispatchEvent(new customEvent("single-spa:routing-event", getCustomEventDetail())); | ||
} catch (err) { | ||
/* We use a setTimeout because if someone else's event handler throws an error, single-spa | ||
* needs to carry on. If a listener to the event throws an error, it's their own fault, not | ||
* single-spa's. | ||
*/ | ||
setTimeout(function () { | ||
throw err; | ||
}); | ||
} | ||
/* Setting this allows for subsequent calls to reroute() to actually perform | ||
* a reroute instead of just getting queued behind the current reroute call. | ||
* We want to do this after the mounting/unmounting is done but before we | ||
* resolve the promise for the `reroute` function. | ||
*/ | ||
var loadThenMountPromises = appsToLoad.map(function (app) { | ||
return toLoadPromise(app).then(toBootstrapPromise).then(function (app) { | ||
return unmountAllPromise.then(function () { | ||
return toMountPromise(app); | ||
}); | ||
}); | ||
}); | ||
/* These are the apps that are already bootstrapped and just need | ||
* to be mounted. They each wait for all unmounting apps to finish up | ||
* before they mount. | ||
*/ | ||
var mountPromises = getAppsToMount().filter(function (appToMount) { | ||
return appsToLoad.indexOf(appToMount) < 0; | ||
}).map(function (appToMount) { | ||
appsThatChanged.push(appToMount); | ||
return toBootstrapPromise(appToMount).then(function () { | ||
return unmountAllPromise; | ||
}).then(function () { | ||
return toMountPromise(appToMount); | ||
}); | ||
}); | ||
return unmountAllPromise.catch(function (err) { | ||
callAllEventListeners(); | ||
throw err; | ||
}).then(function () { | ||
/* Now that the apps that needed to be unmounted are unmounted, their DOM navigation | ||
* events (like hashchange or popstate) should have been cleaned up. So it's safe | ||
* to let the remaining captured event listeners to handle about the DOM event. | ||
*/ | ||
callAllEventListeners(); | ||
return Promise.all(loadThenMountPromises.concat(mountPromises)).catch(function (err) { | ||
pendingPromises.forEach(function (promise) { | ||
return promise.reject(err); | ||
}); | ||
throw err; | ||
}).then(finishUpAndReturn); | ||
}); | ||
}); | ||
} | ||
appChangeUnderway = false; | ||
function finishUpAndReturn() { | ||
var returnValue = getMountedApps(); | ||
pendingPromises.forEach(function (promise) { | ||
return promise.resolve(returnValue); | ||
}); | ||
if (peopleWaitingOnAppChange.length > 0) { | ||
/* While we were rerouting, someone else triggered another reroute that got queued. | ||
* So we need reroute again. | ||
*/ | ||
var nextPendingPromises = peopleWaitingOnAppChange; | ||
peopleWaitingOnAppChange = []; | ||
reroute(nextPendingPromises); | ||
} | ||
try { | ||
var appChangeEventName = appsThatChanged.length === 0 ? "single-spa:no-app-change" : "single-spa:app-change"; | ||
window.dispatchEvent(new customEvent(appChangeEventName, getCustomEventDetail())); | ||
window.dispatchEvent(new customEvent("single-spa:routing-event", getCustomEventDetail())); | ||
} catch (err) { | ||
/* We use a setTimeout because if someone else's event handler throws an error, single-spa | ||
* needs to carry on. If a listener to the event throws an error, it's their own fault, not | ||
* single-spa's. | ||
*/ | ||
setTimeout(function () { | ||
throw err; | ||
}); | ||
} | ||
/* Setting this allows for subsequent calls to reroute() to actually perform | ||
* a reroute instead of just getting queued behind the current reroute call. | ||
* We want to do this after the mounting/unmounting is done but before we | ||
* resolve the promise for the `reroute` function. | ||
*/ | ||
return returnValue; | ||
} | ||
/* We need to call all event listeners that have been delayed because they were | ||
* waiting on single-spa. This includes haschange and popstate events for both | ||
* the current run of performAppChanges(), but also all of the queued event listeners. | ||
* We want to call the listeners in the same order as if they had not been delayed by | ||
* single-spa, which means queued ones first and then the most recent one. | ||
*/ | ||
appChangeUnderway = false; | ||
function callAllEventListeners() { | ||
pendingPromises.forEach(function (pendingPromise) { | ||
callCapturedEventListeners(pendingPromise.eventArguments); | ||
}); | ||
callCapturedEventListeners(eventArguments); | ||
} | ||
if (peopleWaitingOnAppChange.length > 0) { | ||
/* While we were rerouting, someone else triggered another reroute that got queued. | ||
* So we need reroute again. | ||
*/ | ||
var nextPendingPromises = peopleWaitingOnAppChange; | ||
peopleWaitingOnAppChange = []; | ||
reroute(nextPendingPromises); | ||
} | ||
function getCustomEventDetail() { | ||
var result = { | ||
detail: {} | ||
}; | ||
return returnValue; | ||
} | ||
/* We need to call all event listeners that have been delayed because they were | ||
* waiting on single-spa. This includes haschange and popstate events for both | ||
* the current run of performAppChanges(), but also all of the queued event listeners. | ||
* We want to call the listeners in the same order as if they had not been delayed by | ||
* single-spa, which means queued ones first and then the most recent one. | ||
*/ | ||
if (eventArguments && eventArguments[0]) { | ||
result.detail.originalEvent = eventArguments[0]; | ||
} | ||
return result; | ||
} | ||
} | ||
function callAllEventListeners() { | ||
pendingPromises.forEach(function (pendingPromise) { | ||
callCapturedEventListeners(pendingPromise.eventArguments); | ||
}); | ||
callCapturedEventListeners(eventArguments); | ||
} | ||
var started = false; | ||
function start(opts) { | ||
started = true; | ||
function getCustomEventDetail() { | ||
var _appsByNewStatus; | ||
if (opts && opts.urlRerouteOnly) { | ||
setUrlRerouteOnly(opts.urlRerouteOnly); | ||
} | ||
var newAppStatuses = {}; | ||
var appsByNewStatus = (_appsByNewStatus = {}, _defineProperty(_appsByNewStatus, MOUNTED, []), _defineProperty(_appsByNewStatus, NOT_MOUNTED, []), _defineProperty(_appsByNewStatus, NOT_LOADED, []), _defineProperty(_appsByNewStatus, SKIP_BECAUSE_BROKEN, []), _appsByNewStatus); | ||
appsThatChanged.forEach(function (app) { | ||
var appName = toName(app); | ||
var status = getAppStatus(appName); | ||
newAppStatuses[appName] = status; | ||
var statusArr = appsByNewStatus[status] = appsByNewStatus[status] || []; | ||
statusArr.push(appName); | ||
}); | ||
return { | ||
detail: { | ||
newAppStatuses: newAppStatuses, | ||
appsByNewStatus: appsByNewStatus, | ||
totalAppChanges: appsThatChanged.length, | ||
originalEvent: eventArguments === null || eventArguments === void 0 ? void 0 : eventArguments[0] | ||
} | ||
}; | ||
} | ||
} | ||
if (isInBrowser) { | ||
reroute(); | ||
} | ||
} | ||
function isStarted() { | ||
return started; | ||
} | ||
var started = false; | ||
function start(opts) { | ||
started = true; | ||
if (isInBrowser) { | ||
setTimeout(function () { | ||
if (!started) { | ||
console.warn(formatErrorMessage(1, "singleSpa.start() has not been called, 5000ms after single-spa was loaded. Before start() is called, apps can be declared and loaded, but not bootstrapped or mounted.")); | ||
} | ||
}, 5000); | ||
} | ||
if (opts && opts.urlRerouteOnly) { | ||
setUrlRerouteOnly(opts.urlRerouteOnly); | ||
} | ||
var devtools = { | ||
getRawAppData: getRawAppData, | ||
reroute: reroute, | ||
NOT_LOADED: NOT_LOADED, | ||
toLoadPromise: toLoadPromise, | ||
toBootstrapPromise: toBootstrapPromise, | ||
unregisterApplication: unregisterApplication | ||
}; | ||
if (isInBrowser) { | ||
reroute(); | ||
} | ||
} | ||
function isStarted() { | ||
return started; | ||
} | ||
if (isInBrowser && window.__SINGLE_SPA_DEVTOOLS__) { | ||
window.__SINGLE_SPA_DEVTOOLS__.exposedMethods = devtools; | ||
} | ||
if (isInBrowser) { | ||
setTimeout(function () { | ||
if (!started) { | ||
console.warn(formatErrorMessage(1, "singleSpa.start() has not been called, 5000ms after single-spa was loaded. Before start() is called, apps can be declared and loaded, but not bootstrapped or mounted.")); | ||
} | ||
}, 5000); | ||
} | ||
exports.BOOTSTRAPPING = BOOTSTRAPPING; | ||
exports.LOADING_SOURCE_CODE = LOADING_SOURCE_CODE; | ||
exports.LOAD_ERROR = LOAD_ERROR; | ||
exports.MOUNTED = MOUNTED; | ||
exports.MOUNTING = MOUNTING; | ||
exports.NOT_BOOTSTRAPPED = NOT_BOOTSTRAPPED; | ||
exports.NOT_LOADED = NOT_LOADED; | ||
exports.NOT_MOUNTED = NOT_MOUNTED; | ||
exports.SKIP_BECAUSE_BROKEN = SKIP_BECAUSE_BROKEN; | ||
exports.UNMOUNTING = UNMOUNTING; | ||
exports.UPDATING = UPDATING; | ||
exports.addErrorHandler = addErrorHandler; | ||
exports.checkActivityFunctions = checkActivityFunctions; | ||
exports.ensureJQuerySupport = ensureJQuerySupport; | ||
exports.getAppNames = getAppNames; | ||
exports.getAppStatus = getAppStatus; | ||
exports.getMountedApps = getMountedApps; | ||
exports.mountRootParcel = mountRootParcel; | ||
exports.navigateToUrl = navigateToUrl; | ||
exports.registerApplication = registerApplication; | ||
exports.removeErrorHandler = removeErrorHandler; | ||
exports.setBootstrapMaxTime = setBootstrapMaxTime; | ||
exports.setMountMaxTime = setMountMaxTime; | ||
exports.setUnloadMaxTime = setUnloadMaxTime; | ||
exports.setUnmountMaxTime = setUnmountMaxTime; | ||
exports.start = start; | ||
exports.triggerAppChange = triggerAppChange; | ||
exports.unloadApplication = unloadApplication; | ||
var devtools = { | ||
getRawAppData: getRawAppData, | ||
reroute: reroute, | ||
NOT_LOADED: NOT_LOADED, | ||
toLoadPromise: toLoadPromise, | ||
toBootstrapPromise: toBootstrapPromise, | ||
unregisterApplication: unregisterApplication | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
if (isInBrowser && window.__SINGLE_SPA_DEVTOOLS__) { | ||
window.__SINGLE_SPA_DEVTOOLS__.exposedMethods = devtools; | ||
} | ||
exports.BOOTSTRAPPING = BOOTSTRAPPING; | ||
exports.LOADING_SOURCE_CODE = LOADING_SOURCE_CODE; | ||
exports.LOAD_ERROR = LOAD_ERROR; | ||
exports.MOUNTED = MOUNTED; | ||
exports.MOUNTING = MOUNTING; | ||
exports.NOT_BOOTSTRAPPED = NOT_BOOTSTRAPPED; | ||
exports.NOT_LOADED = NOT_LOADED; | ||
exports.NOT_MOUNTED = NOT_MOUNTED; | ||
exports.SKIP_BECAUSE_BROKEN = SKIP_BECAUSE_BROKEN; | ||
exports.UNMOUNTING = UNMOUNTING; | ||
exports.UPDATING = UPDATING; | ||
exports.addErrorHandler = addErrorHandler; | ||
exports.checkActivityFunctions = checkActivityFunctions; | ||
exports.ensureJQuerySupport = ensureJQuerySupport; | ||
exports.getAppNames = getAppNames; | ||
exports.getAppStatus = getAppStatus; | ||
exports.getMountedApps = getMountedApps; | ||
exports.mountRootParcel = mountRootParcel; | ||
exports.navigateToUrl = navigateToUrl; | ||
exports.registerApplication = registerApplication; | ||
exports.removeErrorHandler = removeErrorHandler; | ||
exports.setBootstrapMaxTime = setBootstrapMaxTime; | ||
exports.setMountMaxTime = setMountMaxTime; | ||
exports.setUnloadMaxTime = setUnloadMaxTime; | ||
exports.setUnmountMaxTime = setUnmountMaxTime; | ||
exports.start = start; | ||
exports.triggerAppChange = triggerAppChange; | ||
exports.unloadApplication = unloadApplication; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=single-spa.dev.js.map |
@@ -1,3 +0,3 @@ | ||
/* single-spa@5.3.1 - UMD - prod */ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).singleSpa={})}(this,(function(t){var n=Object.freeze({__proto__:null,get start(){return Wt},get ensureJQuerySupport(){return vt},get setBootstrapMaxTime(){return z},get setMountMaxTime(){return X},get setUnmountMaxTime(){return Y},get setUnloadMaxTime(){return Z},get registerApplication(){return St},get getMountedApps(){return bt},get getAppStatus(){return _t},get unloadApplication(){return Rt},get checkActivityFunctions(){return Dt},get getAppNames(){return Nt},get navigateToUrl(){return at},get triggerAppChange(){return Gt},get addErrorHandler(){return a},get removeErrorHandler(){return c},get mountRootParcel(){return H},get NOT_LOADED(){return l},get LOADING_SOURCE_CODE(){return p},get NOT_BOOTSTRAPPED(){return h},get BOOTSTRAPPING(){return m},get NOT_MOUNTED(){return d},get MOUNTING(){return v},get UPDATING(){return g},get LOAD_ERROR(){return y},get MOUNTED(){return w},get UNMOUNTING(){return E},get SKIP_BECAUSE_BROKEN(){return O}}),e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{}).CustomEvent,r=function(){try{var t=new e("cat",{detail:{foo:"bar"}});return"cat"===t.type&&"bar"===t.detail.foo}catch(t){}return!1}()?e:"undefined"!=typeof document&&"function"==typeof document.createEvent?function(t,n){var e=document.createEvent("CustomEvent");return n?e.initCustomEvent(t,n.bubbles,n.cancelable,n.detail):e.initCustomEvent(t,!1,!1,void 0),e}:function(t,n){var e=document.createEventObject();return e.type=t,n?(e.bubbles=Boolean(n.bubbles),e.cancelable=Boolean(n.cancelable),e.detail=n.detail):(e.bubbles=!1,e.cancelable=!1,e.detail=void 0),e};function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=[];function u(t,n,e){var r=f(t,n,e);i.length?i.forEach((function(t){return t(r)})):setTimeout((function(){throw r}))}function a(t){if("function"!=typeof t)throw Error(s(28,!1));i.push(t)}function c(t){if("function"!=typeof t)throw Error(s(29,!1));var n=!1;return i=i.filter((function(e){var r=e===t;return n=n||r,!r})),n}function s(t,n){for(var e=arguments.length,r=new Array(e>2?e-2:0),o=2;o<e;o++)r[o-2]=arguments[o];return"single-spa minified message #".concat(t,": ").concat(n?n+" ":"","See https://single-spa.js.org/error/?code=").concat(t).concat(r.length?"&arg=".concat(r.join("&arg=")):"")}function f(t,n,e){var r,o="".concat(j(n)," '").concat(M(n),"' died in status ").concat(n.status,": ");if(t instanceof Error){try{t.message=o+t.message}catch(t){}r=t}else{console.warn(s(30,!1,n.status,M(n)));try{r=Error(o+JSON.stringify(t))}catch(n){r=t}}return r.appOrParcelName=M(n),n.status=e,r}var l="NOT_LOADED",p="LOADING_SOURCE_CODE",h="NOT_BOOTSTRAPPED",m="BOOTSTRAPPING",d="NOT_MOUNTED",v="MOUNTING",w="MOUNTED",g="UPDATING",E="UNMOUNTING",y="LOAD_ERROR",O="SKIP_BECAUSE_BROKEN";function T(t){return t.status===w}function P(t){return!T(t)}function A(t){return t.status!==l&&t.status!==p&&t.status!==y}function b(t){return!A(t)}function N(t){try{return t.activeWhen(window.location)}catch(n){u(n,t,O)}}function _(t){try{return!N(t)}catch(n){u(n,t,O)}}function S(t){return t!==O&&(!t||t.status!==O)}function D(t){return t.status!==y||(new Date).getTime()-t.loadErrorTime>=200}function M(t){return t.name}function U(t){return Boolean(t.unmountThisParcel)}function j(t){return U(t)?"parcel":"application"}function R(){for(var t=arguments.length-1;t>0;t--)for(var n in arguments[t])"__proto__"!==n&&(arguments[t-1][n]=arguments[t][n]);return arguments[0]}function L(t,n){for(var e=0;e<t.length;e++)if(n(t[e]))return t[e];return null}function I(t){return t&&("function"==typeof t||(n=t,Array.isArray(n)&&!L(n,(function(t){return"function"!=typeof t}))));var n}function x(t,n){var e=t[n]||[];0===(e=Array.isArray(e)?e:[e]).length&&(e=[function(){return Promise.resolve()}]);var r=j(t),o=M(t);return function(t){return e.reduce((function(e,i,u){return e.then((function(){var e=i(t);return G(e)?e:Promise.reject(s(15,!1,r,o,n,u))}))}),Promise.resolve())}}function G(t){return t&&"function"==typeof t.then&&"function"==typeof t.catch}function B(t,n){return Promise.resolve().then((function(){return t.status!==h?t:(t.status=m,tt(t,"bootstrap").then((function(){return t.status=d,t})).catch((function(e){if(n)throw f(e,t,O);return u(e,t,O),t})))}))}function C(t,n){return Promise.resolve().then((function(){if(t.status!==w)return t;t.status=E;var e=Object.keys(t.parcels).map((function(n){return t.parcels[n].unmountThisParcel()}));return Promise.all(e).then(r,(function(e){return r().then((function(){var r=Error(e.message);if(n)throw f(r,t,O);u(r,t,O)}))})).then((function(){return t}));function r(){return tt(t,"unmount").then((function(){t.status=d})).catch((function(e){if(n)throw f(e,t,O);u(e,t,O)}))}}))}var W=!1,K=!1;function $(t,n){return Promise.resolve().then((function(){return t.status!==d?t:(W||(window.dispatchEvent(new r("single-spa:before-first-mount")),W=!0),tt(t,"mount").then((function(){return t.status=w,K||(window.dispatchEvent(new r("single-spa:first-mount")),K=!0),t})).catch((function(e){return t.status=w,C(t,!0).then(r,r);function r(){if(n)throw f(e,t,O);return u(e,t,O),t}})))}))}var k=0,F={parcels:{}};function H(){return J.apply(F,arguments)}function J(t,n){var e=this;if(!t||"object"!==o(t)&&"function"!=typeof t)throw Error(s(2,!1));if(t.name&&"string"!=typeof t.name)throw Error(s(3,!1,o(t.name)));if("object"!==o(n))throw Error(s(4,!1,name,o(n)));if(!n.domElement)throw Error(s(5,!1,name));var r,i=k++,u="function"==typeof t,a=u?t:function(){return Promise.resolve(t)},c={id:i,parcels:{},status:u?p:h,customProps:n,parentName:M(e),unmountThisParcel:function(){if(c.status!==w)throw Error(s(6,!1,name,c.status));return C(c,!0).then((function(t){return c.parentName&&delete e.parcels[c.id],t})).then((function(t){return m(t),t})).catch((function(t){throw c.status=O,v(t),t}))}};e.parcels[i]=c;var l=a();if(!l||"function"!=typeof l.then)throw Error(s(7,!1));var m,v,E=(l=l.then((function(t){if(!t)throw Error(s(8,!1));var n=t.name||"parcel-".concat(i);if(!I(t.bootstrap))throw Error(s(9,!1,n));if(!I(t.mount))throw Error(s(10,!1,n));if(!I(t.unmount))throw Error(s(11,!1,n));if(t.update&&!I(t.update))throw Error(s(12,!1,n));var e=x(t,"bootstrap"),o=x(t,"mount"),u=x(t,"unmount");c.status=h,c.name=n,c.bootstrap=e,c.mount=o,c.unmount=u,c.timeouts=nt(t.timeouts),t.update&&(c.update=x(t,"update"),r.update=function(t){return c.customProps=t,Q(function(t){return Promise.resolve().then((function(){if(t.status!==w)throw Error(s(32,!1,M(t)));return t.status=g,tt(t,"update").then((function(){return t.status=w,t})).catch((function(n){throw f(n,t,O)}))}))}(c))})}))).then((function(){return B(c,!0)})),y=E.then((function(){return $(c,!0)})),T=new Promise((function(t,n){m=t,v=n}));return r={mount:function(){return Q(Promise.resolve().then((function(){if(c.status!==d)throw Error(s(13,!1,name,c.status));return e.parcels[i]=c,$(c)})))},unmount:function(){return Q(c.unmountThisParcel())},getStatus:function(){return c.status},loadPromise:Q(l),bootstrapPromise:Q(E),mountPromise:Q(y),unmountPromise:Q(T)}}function Q(t){return t.then((function(){return null}))}function V(t){var e=R({},t.customProps,{name:M(t),mountParcel:J.bind(t),singleSpa:n});return U(t)&&(e.unmountSelf=t.unmountThisParcel),e}var q={bootstrap:{millis:4e3,dieOnTimeout:!1,warningMillis:1e3},mount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unmount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unload:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},update:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3}};function z(t,n,e){if("number"!=typeof t||t<=0)throw Error(s(16,!1));q.bootstrap={millis:t,dieOnTimeout:n,warningMillis:e||1e3}}function X(t,n,e){if("number"!=typeof t||t<=0)throw Error(s(17,!1));q.mount={millis:t,dieOnTimeout:n,warningMillis:e||1e3}}function Y(t,n,e){if("number"!=typeof t||t<=0)throw Error(s(18,!1));q.unmount={millis:t,dieOnTimeout:n,warningMillis:e||1e3}}function Z(t,n,e){if("number"!=typeof t||t<=0)throw Error(s(19,!1));q.unload={millis:t,dieOnTimeout:n,warningMillis:e||1e3}}function tt(t,n){var e=t.timeouts[n],r=e.warningMillis,o=j(t);return new Promise((function(i,u){var a=!1,c=!1;t[n](V(t)).then((function(t){a=!0,i(t)})).catch((function(t){a=!0,u(t)})),setTimeout((function(){return l(1)}),r),setTimeout((function(){return l(!0)}),e.millis);var f=s(31,!1,n,o,M(t),e.millis);function l(t){if(!a)if(!0===t)c=!0,e.dieOnTimeout?u(Error(f)):console.error(f);else if(!c){var n=t,o=n*r;console.warn(f),o+r<e.millis&&setTimeout((function(){return l(n+1)}),r)}}}))}function nt(t){var n={};for(var e in q)n[e]=R({},q[e],t&&t[e]||{});return n}function et(t){return Promise.resolve().then((function(){return t.loadPromise?t.loadPromise:t.status!==l&&t.status!==y?t:(t.status=p,t.loadPromise=Promise.resolve().then((function(){var r=t.loadApp(V(t));if(!G(r))throw e=!0,Error(s(33,!1,M(t)));return r.then((function(e){var r;t.loadErrorTime=null,"object"!==o(n=e)&&(r=34),I(n.bootstrap)||(r=35),I(n.mount)||(r=36),I(n.unmount)||(r=37);var i=j(n);if(r){var a;try{a=JSON.stringify(n)}catch(t){}return console.error(s(r,!1,i,M(t),a),n),u(void 0,t,O),t}return n.devtools&&n.devtools.overlays&&(t.devtools.overlays=R({},t.devtools.overlays,n.devtools.overlays)),t.status=h,t.bootstrap=x(n,"bootstrap"),t.mount=x(n,"mount"),t.unmount=x(n,"unmount"),t.unload=x(n,"unload"),t.timeouts=nt(n.timeouts),delete t.loadPromise,t}))})).catch((function(n){var r;return delete t.loadPromise,e?r=O:(r=y,t.loadErrorTime=(new Date).getTime()),u(n,t,r),t})));var n,e}))}var rt,ot="undefined"!=typeof window,it={hashchange:[],popstate:[]},ut=["hashchange","popstate"];function at(t){var n;if("string"==typeof t)n=t;else if(this&&this.href)n=this.href;else{if(!(t&&t.currentTarget&&t.currentTarget.href&&t.preventDefault))throw Error(s(14,!1));n=t.currentTarget.href,t.preventDefault()}var e=mt(window.location.href),r=mt(n);0===n.indexOf("#")?window.location.hash=r.hash:e.host!==r.host&&r.host?window.location.href=n:r.pathname===e.pathname&&r.search===e.pathname?window.location.hash=r.hash:window.history.pushState(null,null,n)}function ct(t){var n=this;if(t){var e=t[0].type;ut.indexOf(e)>=0&&it[e].forEach((function(e){try{e.apply(n,t)}catch(t){setTimeout((function(){throw t}))}}))}}function st(){Bt([],arguments)}if(ot){window.addEventListener("hashchange",st),window.addEventListener("popstate",st);var ft=window.addEventListener,lt=window.removeEventListener;function pt(t){return function(){var n=window.location.href,e=t.apply(this,arguments),r=window.location.href;return rt&&n===r||st(ht(window.history.state)),e}}function ht(t){try{return new PopStateEvent("popstate",{state:t})}catch(e){var n=document.createEvent("PopStateEvent");return n.initPopStateEvent("popstate",!1,!1,t),n}}window.addEventListener=function(t,n){if(!("function"==typeof n&&ut.indexOf(t)>=0)||L(it[t],(function(t){return t===n})))return ft.apply(this,arguments);it[t].push(n)},window.removeEventListener=function(t,n){if(!("function"==typeof n&&ut.indexOf(t)>=0))return lt.apply(this,arguments);it[t]=it[t].filter((function(t){return t!==n}))},window.history.pushState=pt(window.history.pushState),window.history.replaceState=pt(window.history.replaceState),window.singleSpaNavigate=at}function mt(t){var n=document.createElement("a");return n.href=t,n}var dt=!1;function vt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.jQuery;if(t||window.$&&window.$.fn&&window.$.fn.jquery&&(t=window.$),t&&!dt){var n=t.fn.on,e=t.fn.off;t.fn.on=function(t,e){return wt.call(this,n,window.addEventListener,t,e,arguments)},t.fn.off=function(t,n){return wt.call(this,e,window.removeEventListener,t,n,arguments)},dt=!0}}function wt(t,n,e,r,o){return"string"!=typeof e?t.apply(this,o):(e.split(/\s+/).forEach((function(t){ut.indexOf(t)>=0&&(n(t,r),e=e.replace(t,""))})),""===e.trim()?this:t.apply(this,o))}var gt={};function Et(t){return Promise.resolve().then((function(){var n=gt[M(t)];return n?t.status===l?(yt(t,n),t):"UNLOADING"===t.status?n.promise.then((function(){return t})):t.status!==d?t:(t.status="UNLOADING",tt(t,"unload").then((function(){return yt(t,n),t})).catch((function(e){return function(t,n,e){delete gt[M(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,u(e,t,O),n.reject(e)}(t,n,e),t}))):t}))}function yt(t,n){delete gt[M(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,t.status=l,n.resolve()}function Ot(t,n,e,r){gt[M(t)]={app:t,resolve:e,reject:r},Object.defineProperty(gt[M(t)],"promise",{get:n})}function Tt(t){return gt[t]}function Pt(){return Object.keys(gt).map((function(t){return gt[t].app})).filter(P)}var At=[];function bt(){return At.filter(T).map(M)}function Nt(){return At.map(M)}function _t(t){var n=L(At,(function(n){return M(n)===t}));return n?n.status:null}function St(t,n,e,r){var i=function(t,n,e,r){var i,u={name:null,loadApp:null,activeWhen:null,customProps:null};return"object"===o(t)?(function(t){if(Array.isArray(t)||null===t)throw Error(s(39,!1));var n=["name","app","activeWhen","customProps"],e=Object.keys(t).reduce((function(t,e){return n.includes(e)?t:t.concat(e)}),[]);if(0!==e.length)throw Error(s(38,!1,n.join(", "),e.join(", ")));if("string"!=typeof t.name||0===t.name.length)throw Error(s(20,!1));if("object"!==o(t.app)&&"function"!=typeof t.app)throw Error(s(20,!1));var r=function(t){return"string"==typeof t||"function"==typeof t};if(!(r(t.activeWhen)||Array.isArray(t.activeWhen)&&t.activeWhen.every(r)))throw Error(s(24,!1));if(t.customProps&&("object"!==o(t.customProps)||Array.isArray(t.customProps)))throw Error(s(22,!1))}(t),u.name=t.name,u.loadApp=t.app,u.activeWhen=t.activeWhen,u.customProps=t.customProps):(function(t,n,e,r){if("string"!=typeof t||0===t.length)throw Error(s(20,!1));if(!n)throw Error(s(23,!1));if("function"!=typeof e)throw Error(s(24,!1));if(r&&("object"!==o(r)||Array.isArray(r)))throw Error(s(22,!1))}(t,n,e,r),u.name=t,u.loadApp=n,u.activeWhen=e,u.customProps=r),u.loadApp="function"!=typeof(i=u.loadApp)?function(){return Promise.resolve(i)}:i,u.customProps=function(t){return t||{}}(u.customProps),u.activeWhen=function(t){var n=Array.isArray(t)?t:[t];return n=n.map((function(t){return"function"==typeof t?t:(n=function(t){for(var n=0,e=!1,r="^",o=0;o<t.length;o++){var i=t[o];(!e&&":"===i||e&&"/"===i)&&u(o)}return u(t.length),new RegExp(r,"i");function u(o){var i=t.slice(n,o).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&");r+=e?"[^/]+/?":i,e=!e,n=o}}(t),function(t){var e=t.href.replace(t.origin,"");return n.test(e)});var n})),function(t){return n.some((function(n){return n(t)}))}}(u.activeWhen),u}(t,n,e,r);if(-1!==Nt().indexOf(i.name))throw Error(s(21,!1,i.name));At.push(R({loadErrorTime:null,status:l,parcels:{},devtools:{overlays:{options:{},selectors:[]}}},i)),ot&&(vt(),Bt())}function Dt(t){return At.filter((function(n){return n.activeWhen(t)})).map(M)}function Mt(){return At.filter(S).filter(D).filter(b).filter(N)}function Ut(){return At.filter(S).filter(T).filter(_)}function jt(){return At.filter(S).filter(P).filter(A).filter(N)}function Rt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{waitForUnmount:!1};if("string"!=typeof t)throw Error(s(26,!1));var e=L(At,(function(n){return M(n)===t}));if(!e)throw Error(s(27,!1,t));var r,o=Tt(M(e));if(n&&n.waitForUnmount){if(o)return o.promise;var i=new Promise((function(t,n){Ot(e,(function(){return i}),t,n)}));return i}return o?(r=o.promise,Lt(e,o.resolve,o.reject)):r=new Promise((function(t,n){Ot(e,(function(){return r}),t,n),Lt(e,t,n)})),r}function Lt(t,n,e){C(t).then(Et).then((function(){n(),setTimeout((function(){Bt()}))})).catch(e)}var It=!1,xt=[];function Gt(){return Bt()}function Bt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0;if(It)return new Promise((function(t,e){xt.push({resolve:t,reject:e,eventArguments:n})}));var e=!0;return Kt()?(It=!0,i()):o();function o(){return Promise.resolve().then((function(){var t=Mt().map(et);return t.length>0&&(e=!1),Promise.all(t).then(a).then((function(){return[]})).catch((function(t){throw a(),t}))}))}function i(){return Promise.resolve().then((function(){window.dispatchEvent(new r("single-spa:before-routing-event",c()));var n=Pt().map(Et),o=Ut().map(C).map((function(t){return t.then(Et)})).concat(n);o.length>0&&(e=!1);var i=Promise.all(o),s=Mt(),f=s.map((function(t){return et(t).then(B).then((function(t){return i.then((function(){return $(t)}))}))}));f.length>0&&(e=!1);var l=jt().filter((function(t){return s.indexOf(t)<0})).map((function(t){return B(t).then((function(){return i})).then((function(){return $(t)}))}));return l.length>0&&(e=!1),i.catch((function(t){throw a(),t})).then((function(){return a(),Promise.all(f.concat(l)).catch((function(n){throw t.forEach((function(t){return t.reject(n)})),n})).then(u)}))}))}function u(){var n=bt();t.forEach((function(t){return t.resolve(n)}));try{var o=e?"single-spa:no-app-change":"single-spa:app-change";window.dispatchEvent(new r(o,c())),window.dispatchEvent(new r("single-spa:routing-event",c()))}catch(t){setTimeout((function(){throw t}))}if(It=!1,xt.length>0){var i=xt;xt=[],Bt(i)}return n}function a(){t.forEach((function(t){ct(t.eventArguments)})),ct(n)}function c(){var t={detail:{}};return n&&n[0]&&(t.detail.originalEvent=n[0]),t}}var Ct=!1;function Wt(t){var n;Ct=!0,t&&t.urlRerouteOnly&&(n=t.urlRerouteOnly,rt=n),ot&&Bt()}function Kt(){return Ct}ot&&setTimeout((function(){Ct||console.warn(s(1,!1))}),5e3);var $t={getRawAppData:function(){return[].concat(At)},reroute:Bt,NOT_LOADED:l,toLoadPromise:et,toBootstrapPromise:B,unregisterApplication:function(t){if(!At.find((function(n){return M(n)===t})))throw Error(s(25,!1,t));return Rt(t).then((function(){var n=At.findIndex((function(n){return M(n)===t}));At.splice(n,1)}))}};ot&&window.__SINGLE_SPA_DEVTOOLS__&&(window.__SINGLE_SPA_DEVTOOLS__.exposedMethods=$t),t.BOOTSTRAPPING=m,t.LOADING_SOURCE_CODE=p,t.LOAD_ERROR=y,t.MOUNTED=w,t.MOUNTING=v,t.NOT_BOOTSTRAPPED=h,t.NOT_LOADED=l,t.NOT_MOUNTED=d,t.SKIP_BECAUSE_BROKEN=O,t.UNMOUNTING=E,t.UPDATING=g,t.addErrorHandler=a,t.checkActivityFunctions=Dt,t.ensureJQuerySupport=vt,t.getAppNames=Nt,t.getAppStatus=_t,t.getMountedApps=bt,t.mountRootParcel=H,t.navigateToUrl=at,t.registerApplication=St,t.removeErrorHandler=c,t.setBootstrapMaxTime=z,t.setMountMaxTime=X,t.setUnloadMaxTime=Z,t.setUnmountMaxTime=Y,t.start=Wt,t.triggerAppChange=Gt,t.unloadApplication=Rt,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
/* single-spa@5.3.2 - UMD - prod */ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).singleSpa={})}(this,(function(t){"use strict";var n=Object.freeze({__proto__:null,get start(){return kt},get ensureJQuerySupport(){return yt},get setBootstrapMaxTime(){return Z},get setMountMaxTime(){return tt},get setUnmountMaxTime(){return nt},get setUnloadMaxTime(){return et},get registerApplication(){return Ut},get getMountedApps(){return _t},get getAppStatus(){return Mt},get unloadApplication(){return xt},get checkActivityFunctions(){return jt},get getAppNames(){return Dt},get navigateToUrl(){return ft},get triggerAppChange(){return Wt},get addErrorHandler(){return f},get removeErrorHandler(){return l},get mountRootParcel(){return V},get NOT_LOADED(){return m},get LOADING_SOURCE_CODE(){return d},get NOT_BOOTSTRAPPED(){return v},get BOOTSTRAPPING(){return w},get NOT_MOUNTED(){return g},get MOUNTING(){return y},get UPDATING(){return O},get LOAD_ERROR(){return P},get MOUNTED(){return E},get UNMOUNTING(){return T},get SKIP_BECAUSE_BROKEN(){return b}});function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}function o(t){return function(t){if(Array.isArray(t))return i(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,n){if(t){if("string"==typeof t)return i(t,void 0);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(e):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?i(t,void 0):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}var u=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{}).CustomEvent,a=function(){try{var t=new u("cat",{detail:{foo:"bar"}});return"cat"===t.type&&"bar"===t.detail.foo}catch(t){}return!1}()?u:"undefined"!=typeof document&&"function"==typeof document.createEvent?function(t,n){var e=document.createEvent("CustomEvent");return n?e.initCustomEvent(t,n.bubbles,n.cancelable,n.detail):e.initCustomEvent(t,!1,!1,void 0),e}:function(t,n){var e=document.createEventObject();return e.type=t,n?(e.bubbles=Boolean(n.bubbles),e.cancelable=Boolean(n.cancelable),e.detail=n.detail):(e.bubbles=!1,e.cancelable=!1,e.detail=void 0),e},c=[];function s(t,n,e){var r=h(t,n,e);c.length?c.forEach((function(t){return t(r)})):setTimeout((function(){throw r}))}function f(t){if("function"!=typeof t)throw Error(p(28,!1));c.push(t)}function l(t){if("function"!=typeof t)throw Error(p(29,!1));var n=!1;return c=c.filter((function(e){var r=e===t;return n=n||r,!r})),n}function p(t,n){for(var e=arguments.length,r=new Array(e>2?e-2:0),o=2;o<e;o++)r[o-2]=arguments[o];return"single-spa minified message #".concat(t,": ").concat(n?n+" ":"","See https://single-spa.js.org/error/?code=").concat(t).concat(r.length?"&arg=".concat(r.join("&arg=")):"")}function h(t,n,e){var r,o="".concat(L(n)," '").concat(R(n),"' died in status ").concat(n.status,": ");if(t instanceof Error){try{t.message=o+t.message}catch(t){}r=t}else{console.warn(p(30,!1,n.status,R(n)));try{r=Error(o+JSON.stringify(t))}catch(n){r=t}}return r.appOrParcelName=R(n),n.status=e,r}var m="NOT_LOADED",d="LOADING_SOURCE_CODE",v="NOT_BOOTSTRAPPED",w="BOOTSTRAPPING",g="NOT_MOUNTED",y="MOUNTING",E="MOUNTED",O="UPDATING",T="UNMOUNTING",P="LOAD_ERROR",b="SKIP_BECAUSE_BROKEN";function A(t){return t.status===E}function N(t){return!A(t)}function S(t){return t.status!==m&&t.status!==d&&t.status!==P}function _(t){return!S(t)}function D(t){try{return t.activeWhen(window.location)}catch(n){s(n,t,b)}}function M(t){try{return!D(t)}catch(n){s(n,t,b)}}function U(t){return t!==b&&(!t||t.status!==b)}function j(t){return t.status!==P||(new Date).getTime()-t.loadErrorTime>=200}function R(t){return t.name}function I(t){return Boolean(t.unmountThisParcel)}function L(t){return I(t)?"parcel":"application"}function x(){for(var t=arguments.length-1;t>0;t--)for(var n in arguments[t])"__proto__"!==n&&(arguments[t-1][n]=arguments[t][n]);return arguments[0]}function B(t,n){for(var e=0;e<t.length;e++)if(n(t[e]))return t[e];return null}function G(t){return t&&("function"==typeof t||(n=t,Array.isArray(n)&&!B(n,(function(t){return"function"!=typeof t}))));var n}function C(t,n){var e=t[n]||[];0===(e=Array.isArray(e)?e:[e]).length&&(e=[function(){return Promise.resolve()}]);var r=L(t),o=R(t);return function(t){return e.reduce((function(e,i,u){return e.then((function(){var e=i(t);return W(e)?e:Promise.reject(p(15,!1,r,o,n,u))}))}),Promise.resolve())}}function W(t){return t&&"function"==typeof t.then&&"function"==typeof t.catch}function $(t,n){return Promise.resolve().then((function(){return t.status!==v?t:(t.status=w,rt(t,"bootstrap").then((function(){return t.status=g,t})).catch((function(e){if(n)throw h(e,t,b);return s(e,t,b),t})))}))}function K(t,n){return Promise.resolve().then((function(){if(t.status!==E)return t;t.status=T;var e=Object.keys(t.parcels).map((function(n){return t.parcels[n].unmountThisParcel()}));return Promise.all(e).then(r,(function(e){return r().then((function(){var r=Error(e.message);if(n)throw h(r,t,b);s(r,t,b)}))})).then((function(){return t}));function r(){return rt(t,"unmount").then((function(){t.status=g})).catch((function(e){if(n)throw h(e,t,b);s(e,t,b)}))}}))}var k=!1,F=!1;function H(t,n){return Promise.resolve().then((function(){return t.status!==g?t:(k||(window.dispatchEvent(new a("single-spa:before-first-mount")),k=!0),rt(t,"mount").then((function(){return t.status=E,F||(window.dispatchEvent(new a("single-spa:first-mount")),F=!0),t})).catch((function(e){return t.status=E,K(t,!0).then(r,r);function r(){if(n)throw h(e,t,b);return s(e,t,b),t}})))}))}var J=0,Q={parcels:{}};function V(){return q.apply(Q,arguments)}function q(t,n){var r=this;if(!t||"object"!==e(t)&&"function"!=typeof t)throw Error(p(2,!1));if(t.name&&"string"!=typeof t.name)throw Error(p(3,!1,e(t.name)));if("object"!==e(n))throw Error(p(4,!1,name,e(n)));if(!n.domElement)throw Error(p(5,!1,name));var o,i=J++,u="function"==typeof t,a=u?t:function(){return Promise.resolve(t)},c={id:i,parcels:{},status:u?d:v,customProps:n,parentName:R(r),unmountThisParcel:function(){if(c.status!==E)throw Error(p(6,!1,name,c.status));return K(c,!0).then((function(t){return c.parentName&&delete r.parcels[c.id],t})).then((function(t){return f(t),t})).catch((function(t){throw c.status=b,l(t),t}))}};r.parcels[i]=c;var s=a();if(!s||"function"!=typeof s.then)throw Error(p(7,!1));var f,l,m=(s=s.then((function(t){if(!t)throw Error(p(8,!1));var n=t.name||"parcel-".concat(i);if(!G(t.bootstrap))throw Error(p(9,!1,n));if(!G(t.mount))throw Error(p(10,!1,n));if(!G(t.unmount))throw Error(p(11,!1,n));if(t.update&&!G(t.update))throw Error(p(12,!1,n));var e=C(t,"bootstrap"),r=C(t,"mount"),u=C(t,"unmount");c.status=v,c.name=n,c.bootstrap=e,c.mount=r,c.unmount=u,c.timeouts=ot(t.timeouts),t.update&&(c.update=C(t,"update"),o.update=function(t){return c.customProps=t,z(function(t){return Promise.resolve().then((function(){if(t.status!==E)throw Error(p(32,!1,R(t)));return t.status=O,rt(t,"update").then((function(){return t.status=E,t})).catch((function(n){throw h(n,t,b)}))}))}(c))})}))).then((function(){return $(c,!0)})),w=m.then((function(){return H(c,!0)})),y=new Promise((function(t,n){f=t,l=n}));return o={mount:function(){return z(Promise.resolve().then((function(){if(c.status!==g)throw Error(p(13,!1,name,c.status));return r.parcels[i]=c,H(c)})))},unmount:function(){return z(c.unmountThisParcel())},getStatus:function(){return c.status},loadPromise:z(s),bootstrapPromise:z(m),mountPromise:z(w),unmountPromise:z(y)}}function z(t){return t.then((function(){return null}))}function X(t){var e=x({},t.customProps,{name:R(t),mountParcel:q.bind(t),singleSpa:n});return I(t)&&(e.unmountSelf=t.unmountThisParcel),e}var Y={bootstrap:{millis:4e3,dieOnTimeout:!1,warningMillis:1e3},mount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unmount:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},unload:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3},update:{millis:3e3,dieOnTimeout:!1,warningMillis:1e3}};function Z(t,n,e){if("number"!=typeof t||t<=0)throw Error(p(16,!1));Y.bootstrap={millis:t,dieOnTimeout:n,warningMillis:e||1e3}}function tt(t,n,e){if("number"!=typeof t||t<=0)throw Error(p(17,!1));Y.mount={millis:t,dieOnTimeout:n,warningMillis:e||1e3}}function nt(t,n,e){if("number"!=typeof t||t<=0)throw Error(p(18,!1));Y.unmount={millis:t,dieOnTimeout:n,warningMillis:e||1e3}}function et(t,n,e){if("number"!=typeof t||t<=0)throw Error(p(19,!1));Y.unload={millis:t,dieOnTimeout:n,warningMillis:e||1e3}}function rt(t,n){var e=t.timeouts[n],r=e.warningMillis,o=L(t);return new Promise((function(i,u){var a=!1,c=!1;t[n](X(t)).then((function(t){a=!0,i(t)})).catch((function(t){a=!0,u(t)})),setTimeout((function(){return f(1)}),r),setTimeout((function(){return f(!0)}),e.millis);var s=p(31,!1,n,o,R(t),e.millis);function f(t){if(!a)if(!0===t)c=!0,e.dieOnTimeout?u(Error(s)):console.error(s);else if(!c){var n=t,o=n*r;console.warn(s),o+r<e.millis&&setTimeout((function(){return f(n+1)}),r)}}}))}function ot(t){var n={};for(var e in Y)n[e]=x({},Y[e],t&&t[e]||{});return n}function it(t){return Promise.resolve().then((function(){return t.loadPromise?t.loadPromise:t.status!==m&&t.status!==P?t:(t.status=d,t.loadPromise=Promise.resolve().then((function(){var o=t.loadApp(X(t));if(!W(o))throw r=!0,Error(p(33,!1,R(t)));return o.then((function(r){var o;t.loadErrorTime=null,"object"!==e(n=r)&&(o=34),G(n.bootstrap)||(o=35),G(n.mount)||(o=36),G(n.unmount)||(o=37);var i=L(n);if(o){var u;try{u=JSON.stringify(n)}catch(t){}return console.error(p(o,!1,i,R(t),u),n),s(void 0,t,b),t}return n.devtools&&n.devtools.overlays&&(t.devtools.overlays=x({},t.devtools.overlays,n.devtools.overlays)),t.status=v,t.bootstrap=C(n,"bootstrap"),t.mount=C(n,"mount"),t.unmount=C(n,"unmount"),t.unload=C(n,"unload"),t.timeouts=ot(n.timeouts),delete t.loadPromise,t}))})).catch((function(n){var e;return delete t.loadPromise,r?e=b:(e=P,t.loadErrorTime=(new Date).getTime()),s(n,t,e),t})));var n,r}))}var ut,at="undefined"!=typeof window,ct={hashchange:[],popstate:[]},st=["hashchange","popstate"];function ft(t){var n;if("string"==typeof t)n=t;else if(this&&this.href)n=this.href;else{if(!(t&&t.currentTarget&&t.currentTarget.href&&t.preventDefault))throw Error(p(14,!1));n=t.currentTarget.href,t.preventDefault()}var e=wt(window.location.href),r=wt(n);0===n.indexOf("#")?window.location.hash=r.hash:e.host!==r.host&&r.host?window.location.href=n:r.pathname===e.pathname&&r.search===e.pathname?window.location.hash=r.hash:window.history.pushState(null,null,n)}function lt(t){var n=this;if(t){var e=t[0].type;st.indexOf(e)>=0&&ct[e].forEach((function(e){try{e.apply(n,t)}catch(t){setTimeout((function(){throw t}))}}))}}function pt(){$t([],arguments)}if(at){window.addEventListener("hashchange",pt),window.addEventListener("popstate",pt);var ht=window.addEventListener,mt=window.removeEventListener;function dt(t){return function(){var n=window.location.href,e=t.apply(this,arguments),r=window.location.href;return ut&&n===r||pt(vt(window.history.state)),e}}function vt(t){try{return new PopStateEvent("popstate",{state:t})}catch(e){var n=document.createEvent("PopStateEvent");return n.initPopStateEvent("popstate",!1,!1,t),n}}window.addEventListener=function(t,n){if(!("function"==typeof n&&st.indexOf(t)>=0)||B(ct[t],(function(t){return t===n})))return ht.apply(this,arguments);ct[t].push(n)},window.removeEventListener=function(t,n){if(!("function"==typeof n&&st.indexOf(t)>=0))return mt.apply(this,arguments);ct[t]=ct[t].filter((function(t){return t!==n}))},window.history.pushState=dt(window.history.pushState),window.history.replaceState=dt(window.history.replaceState),window.singleSpaNavigate=ft}function wt(t){var n=document.createElement("a");return n.href=t,n}var gt=!1;function yt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.jQuery;if(t||window.$&&window.$.fn&&window.$.fn.jquery&&(t=window.$),t&&!gt){var n=t.fn.on,e=t.fn.off;t.fn.on=function(t,e){return Et.call(this,n,window.addEventListener,t,e,arguments)},t.fn.off=function(t,n){return Et.call(this,e,window.removeEventListener,t,n,arguments)},gt=!0}}function Et(t,n,e,r,o){return"string"!=typeof e?t.apply(this,o):(e.split(/\s+/).forEach((function(t){st.indexOf(t)>=0&&(n(t,r),e=e.replace(t,""))})),""===e.trim()?this:t.apply(this,o))}var Ot={};function Tt(t){return Promise.resolve().then((function(){var n=Ot[R(t)];return n?t.status===m?(Pt(t,n),t):"UNLOADING"===t.status?n.promise.then((function(){return t})):t.status!==g?t:(t.status="UNLOADING",rt(t,"unload").then((function(){return Pt(t,n),t})).catch((function(e){return function(t,n,e){delete Ot[R(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,s(e,t,b),n.reject(e)}(t,n,e),t}))):t}))}function Pt(t,n){delete Ot[R(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,t.status=m,n.resolve()}function bt(t,n,e,r){Ot[R(t)]={app:t,resolve:e,reject:r},Object.defineProperty(Ot[R(t)],"promise",{get:n})}function At(t){return Ot[t]}function Nt(){return Object.keys(Ot).map((function(t){return Ot[t].app})).filter(N)}var St=[];function _t(){return St.filter(A).map(R)}function Dt(){return St.map(R)}function Mt(t){var n=B(St,(function(n){return R(n)===t}));return n?n.status:null}function Ut(t,n,r,o){var i=function(t,n,r,o){var i,u={name:null,loadApp:null,activeWhen:null,customProps:null};return"object"===e(t)?(function(t){if(Array.isArray(t)||null===t)throw Error(p(39,!1));var n=["name","app","activeWhen","customProps"],r=Object.keys(t).reduce((function(t,e){return n.includes(e)?t:t.concat(e)}),[]);if(0!==r.length)throw Error(p(38,!1,n.join(", "),r.join(", ")));if("string"!=typeof t.name||0===t.name.length)throw Error(p(20,!1));if("object"!==e(t.app)&&"function"!=typeof t.app)throw Error(p(20,!1));var o=function(t){return"string"==typeof t||"function"==typeof t};if(!(o(t.activeWhen)||Array.isArray(t.activeWhen)&&t.activeWhen.every(o)))throw Error(p(24,!1));if(t.customProps&&("object"!==e(t.customProps)||Array.isArray(t.customProps)))throw Error(p(22,!1))}(t),u.name=t.name,u.loadApp=t.app,u.activeWhen=t.activeWhen,u.customProps=t.customProps):(function(t,n,r,o){if("string"!=typeof t||0===t.length)throw Error(p(20,!1));if(!n)throw Error(p(23,!1));if("function"!=typeof r)throw Error(p(24,!1));if(o&&("object"!==e(o)||Array.isArray(o)))throw Error(p(22,!1))}(t,n,r,o),u.name=t,u.loadApp=n,u.activeWhen=r,u.customProps=o),u.loadApp="function"!=typeof(i=u.loadApp)?function(){return Promise.resolve(i)}:i,u.customProps=function(t){return t||{}}(u.customProps),u.activeWhen=function(t){var n=Array.isArray(t)?t:[t];return n=n.map((function(t){return"function"==typeof t?t:(n=function(t){for(var n=0,e=!1,r="^",o=0;o<t.length;o++){var i=t[o];(!e&&":"===i||e&&"/"===i)&&u(o)}return u(t.length),new RegExp(r,"i");function u(o){var i=t.slice(n,o).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&");r+=e?"[^/]+/?":i,e=!e,n=o}}(t),function(t){var e=t.href.replace(t.origin,"");return n.test(e)});var n})),function(t){return n.some((function(n){return n(t)}))}}(u.activeWhen),u}(t,n,r,o);if(-1!==Dt().indexOf(i.name))throw Error(p(21,!1,i.name));St.push(x({loadErrorTime:null,status:m,parcels:{},devtools:{overlays:{options:{},selectors:[]}}},i)),at&&(yt(),$t())}function jt(t){return St.filter((function(n){return n.activeWhen(t)})).map(R)}function Rt(){return St.filter(U).filter(j).filter(_).filter(D)}function It(){return St.filter(U).filter(A).filter(M)}function Lt(){return St.filter(U).filter(N).filter(S).filter(D)}function xt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{waitForUnmount:!1};if("string"!=typeof t)throw Error(p(26,!1));var e=B(St,(function(n){return R(n)===t}));if(!e)throw Error(p(27,!1,t));var r,o=At(R(e));if(n&&n.waitForUnmount){if(o)return o.promise;var i=new Promise((function(t,n){bt(e,(function(){return i}),t,n)}));return i}return o?(r=o.promise,Bt(e,o.resolve,o.reject)):r=new Promise((function(t,n){bt(e,(function(){return r}),t,n),Bt(e,t,n)})),r}function Bt(t,n,e){K(t).then(Tt).then((function(){n(),setTimeout((function(){$t()}))})).catch(e)}var Gt=!1,Ct=[];function Wt(){return $t()}function $t(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0;if(Gt)return new Promise((function(t,e){Ct.push({resolve:t,reject:e,eventArguments:n})}));var e=[];return Ft()?(Gt=!0,c()):u();function i(t){return e.push.apply(e,o(t)),t}function u(){return Promise.resolve().then((function(){var t=i(Rt()).map(it);return Promise.all(t).then(f).then((function(){return[]})).catch((function(t){throw f(),t}))}))}function c(){return Promise.resolve().then((function(){window.dispatchEvent(new a("single-spa:before-routing-event",l()));var n=i(Nt()).map(Tt),r=i(It()).map(K).map((function(t){return t.then(Tt)})).concat(n),o=Promise.all(r),u=i(Rt()),c=u.map((function(t){return it(t).then($).then((function(t){return o.then((function(){return H(t)}))}))})),p=Lt().filter((function(t){return u.indexOf(t)<0})).map((function(t){return e.push(t),$(t).then((function(){return o})).then((function(){return H(t)}))}));return o.catch((function(t){throw f(),t})).then((function(){return f(),Promise.all(c.concat(p)).catch((function(n){throw t.forEach((function(t){return t.reject(n)})),n})).then(s)}))}))}function s(){var n=_t();t.forEach((function(t){return t.resolve(n)}));try{var r=0===e.length?"single-spa:no-app-change":"single-spa:app-change";window.dispatchEvent(new a(r,l())),window.dispatchEvent(new a("single-spa:routing-event",l()))}catch(t){setTimeout((function(){throw t}))}if(Gt=!1,Ct.length>0){var o=Ct;Ct=[],$t(o)}return n}function f(){t.forEach((function(t){lt(t.eventArguments)})),lt(n)}function l(){var t,o={},i=(r(t={},E,[]),r(t,g,[]),r(t,m,[]),r(t,b,[]),t);return e.forEach((function(t){var n=R(t),e=Mt(n);o[n]=e,(i[e]=i[e]||[]).push(n)})),{detail:{newAppStatuses:o,appsByNewStatus:i,totalAppChanges:e.length,originalEvent:null==n?void 0:n[0]}}}}var Kt=!1;function kt(t){var n;Kt=!0,t&&t.urlRerouteOnly&&(n=t.urlRerouteOnly,ut=n),at&&$t()}function Ft(){return Kt}at&&setTimeout((function(){Kt||console.warn(p(1,!1))}),5e3);var Ht={getRawAppData:function(){return[].concat(St)},reroute:$t,NOT_LOADED:m,toLoadPromise:it,toBootstrapPromise:$,unregisterApplication:function(t){if(!St.find((function(n){return R(n)===t})))throw Error(p(25,!1,t));return xt(t).then((function(){var n=St.findIndex((function(n){return R(n)===t}));St.splice(n,1)}))}};at&&window.__SINGLE_SPA_DEVTOOLS__&&(window.__SINGLE_SPA_DEVTOOLS__.exposedMethods=Ht),t.BOOTSTRAPPING=w,t.LOADING_SOURCE_CODE=d,t.LOAD_ERROR=P,t.MOUNTED=E,t.MOUNTING=y,t.NOT_BOOTSTRAPPED=v,t.NOT_LOADED=m,t.NOT_MOUNTED=g,t.SKIP_BECAUSE_BROKEN=b,t.UNMOUNTING=T,t.UPDATING=O,t.addErrorHandler=f,t.checkActivityFunctions=jt,t.ensureJQuerySupport=yt,t.getAppNames=Dt,t.getAppStatus=Mt,t.getMountedApps=_t,t.mountRootParcel=V,t.navigateToUrl=ft,t.registerApplication=Ut,t.removeErrorHandler=l,t.setBootstrapMaxTime=Z,t.setMountMaxTime=tt,t.setUnloadMaxTime=et,t.setUnmountMaxTime=nt,t.start=kt,t.triggerAppChange=Wt,t.unloadApplication=xt,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=single-spa.min.js.map |
{ | ||
"name": "single-spa", | ||
"version": "5.3.1", | ||
"version": "5.3.2", | ||
"description": "Microfrontends made easy", | ||
@@ -5,0 +5,0 @@ "main": "lib/umd/single-spa.min.js", |
@@ -21,3 +21,3 @@ declare module "single-spa" { | ||
unmount(): Promise<null>; | ||
update(customProps: object): Promise<any>; | ||
update?(customProps: object): Promise<any>; | ||
getStatus(): | ||
@@ -24,0 +24,0 @@ | "NOT_LOADED" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
839505
4504