UNPKG

15.6 kBJavaScriptView Raw
1/* single-spa@5.0.0 - ESM - prod */
2var t=Object.freeze({__proto__:null,get start(){return Rt},get ensureJQuerySupport(){return dt},get setBootstrapMaxTime(){return z},get setMountMaxTime(){return X},get setUnmountMaxTime(){return Y},get setUnloadMaxTime(){return Z},get registerApplication(){return Nt},get getMountedApps(){return Tt},get getAppStatus(){return bt},get unloadApplication(){return St},get checkActivityFunctions(){return _t},get getAppNames(){return Pt},get navigateToUrl(){return it},get triggerAppChange(){return Lt},get addErrorHandler(){return i},get removeErrorHandler(){return a},get mountRootParcel(){return F},get NOT_LOADED(){return c},get LOADING_SOURCE_CODE(){return l},get NOT_BOOTSTRAPPED(){return f},get BOOTSTRAPPING(){return h},get NOT_MOUNTED(){return p},get MOUNTING(){return m},get UPDATING(){return v},get LOAD_ERROR(){return E},get MOUNTED(){return d},get UNMOUNTING(){return w},get SKIP_BECAUSE_BROKEN(){return y}}),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,e){var r=document.createEvent("CustomEvent");return e?r.initCustomEvent(t,e.bubbles,e.cancelable,e.detail):r.initCustomEvent(t,!1,!1,void 0),r}:function(t,e){var r=document.createEventObject();return r.type=t,e?(r.bubbles=Boolean(e.bubbles),r.cancelable=Boolean(e.cancelable),r.detail=e.detail):(r.bubbles=!1,r.cancelable=!1,r.detail=void 0),r},n=[];function o(t,e){var r=s(t,e);n.length?n.forEach(t=>t(r)):setTimeout(()=>{throw r})}function i(t){if("function"!=typeof t)throw Error(u(28,!1));n.push(t)}function a(t){if("function"!=typeof t)throw Error(u(29,!1));var e=!1;return n=n.filter(r=>{var n=r===t;return e=e||n,!n}),e}function u(t,e){for(var r=arguments.length,n=new Array(r>2?r-2:0),o=2;o<r;o++)n[o-2]=arguments[o];return"single-spa minified message #".concat(t,": ").concat(e?e+" ":"","See https://single-spa.js.org/error/?code=").concat(t).concat(n.length?"&arg=".concat(n.join("&arg=")):"")}function s(t,e){var r,n="".concat(U(e)," '").concat(D(e),"' died in status ").concat(e.status,": ");if(t instanceof Error){try{t.message=n+t.message}catch(t){}r=t}else{console.warn(u(30,!1,e.status,D(e)));try{r=Error(n+JSON.stringify(t))}catch(e){r=t}}return r.appOrParcelName=D(e),r}var c="NOT_LOADED",l="LOADING_SOURCE_CODE",f="NOT_BOOTSTRAPPED",h="BOOTSTRAPPING",p="NOT_MOUNTED",m="MOUNTING",d="MOUNTED",v="UPDATING",w="UNMOUNTING",g="UNLOADING",E="LOAD_ERROR",y="SKIP_BECAUSE_BROKEN";function O(t){return t.status===d}function T(t){return!O(t)}function P(t){return t.status!==c&&t.status!==l&&t.status!==E}function b(t){return!P(t)}function N(t){try{return t.activeWhen(window.location)}catch(e){o(e,t),t.status=y}}function _(t){try{return!t.activeWhen(window.location)}catch(e){o(e,t),t.status=y}}function A(t){return t!==y&&(!t||t.status!==y)}function S(t){return t.status!==E||(new Date).getTime()-t.loadErrorTime>=200}function D(t){return t.name}function M(t){return Boolean(t.unmountThisParcel)}function U(t){return M(t)?"parcel":"application"}function L(){for(var t=arguments.length-1;t>0;t--)for(var e in arguments[t])"__proto__"!==e&&(arguments[t-1][e]=arguments[t][e]);return arguments[0]}function j(t,e){for(var r=0;r<t.length;r++)if(e(t[r]))return t[r];return null}function I(t){return t&&("function"==typeof t||(e=t,Array.isArray(e)&&!j(e,t=>"function"!=typeof t)));var e}function R(t,e){var r=t[e]||[];0===(r=Array.isArray(r)?r:[r]).length&&(r=[()=>Promise.resolve()]);var n=U(t),o=D(t);return function(t){return r.reduce((r,i,a)=>r.then(()=>{var r=i(t);return x(r)?r:Promise.reject(u(15,!1,n,o,e,a))}),Promise.resolve())}}function x(t){return t&&"function"==typeof t.then&&"function"==typeof t.catch}function B(t,e){return Promise.resolve().then(()=>t.status!==f?t:(t.status=h,tt(t,"bootstrap").then(()=>(t.status=p,t)).catch(r=>{if(t.status=y,e)throw s(r,t);return o(r,t),t})))}function G(t,e){return Promise.resolve().then(()=>{if(t.status!==d)return t;t.status=w;var r=Object.keys(t.parcels).map(e=>t.parcels[e].unmountThisParcel());return Promise.all(r).then(n,r=>n().then(()=>{var n=Error(r.message);if(e){var i=s(n,t);throw t.status=y,i}o(n,t),t.status=y})).then(()=>t);function n(){return tt(t,"unmount").then(()=>{t.status=p}).catch(r=>{if(e){var n=s(r,t);throw t.status=y,n}o(r,t),t.status=y})}})}var C=!1,K=!1;function W(t,e){return Promise.resolve().then(()=>t.status!==p?t:(C||(window.dispatchEvent(new r("single-spa:before-first-mount")),C=!0),tt(t,"mount").then(()=>(t.status=d,K||(window.dispatchEvent(new r("single-spa:first-mount")),K=!0),t)).catch(r=>{return t.status=d,G(t).then(n,n);function n(){if(e){var n=s(r,t);throw t.status=y,n}return o(r,t),t.status=y,t}})))}var $=0,k={parcels:{}};function F(){return J.apply(k,arguments)}function J(t,e){var r=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));var n,o=$++,i="function"==typeof t,a=i?t:()=>Promise.resolve(t),c={id:o,parcels:{},status:i?l:f,customProps:e,parentName:D(r),unmountThisParcel(){if(c.status!==d)throw Error(u(6,!1,name,c.status));return G(c,!0).then(t=>(c.parentName&&delete r.parcels[c.id],t)).then(t=>(m(t),t)).catch(t=>{throw c.status=y,w(t),t})}};r.parcels[o]=c;var h=a();if(!h||"function"!=typeof h.then)throw Error(u(7,!1));var m,w,g=(h=h.then(t=>{if(!t)throw Error(u(8,!1));var e=t.name||"parcel-".concat(o);if(!I(t.bootstrap))throw Error(u(9,!1,e));if(!I(t.mount))throw Error(u(10,!1,e));if(!I(t.unmount))throw Error(u(11,!1,e));if(t.update&&!I(t.update))throw Error(u(12,!1,e));var r=R(t,"bootstrap"),i=R(t,"mount"),a=R(t,"unmount");c.status=f,c.name=e,c.bootstrap=r,c.mount=i,c.unmount=a,c.timeouts=et(t.timeouts),t.update&&(c.update=R(t,"update"),n.update=function(t){return c.customProps=t,H(function(t){return Promise.resolve().then(()=>{if(t.status!==d)throw Error(u(32,!1,D(t)));return t.status=v,tt(t,"update").then(()=>(t.status=d,t)).catch(e=>{var r=s(e,t);throw t.status=y,r})})}(c))})})).then(()=>B(c,!0)),E=g.then(()=>W(c,!0)),O=new Promise((t,e)=>{m=t,w=e});return n={mount:()=>H(Promise.resolve().then(()=>{if(c.status!==p)throw Error(u(13,!1,name,c.status));return r.parcels[o]=c,W(c)})),unmount:()=>H(c.unmountThisParcel()),getStatus:()=>c.status,loadPromise:H(h),bootstrapPromise:H(g),mountPromise:H(E),unmountPromise:H(O)}}function H(t){return t.then(()=>null)}function Q(e){var r=L({},e.customProps,{name:D(e),mountParcel:J.bind(e),singleSpa:t});return M(e)&&(r.unmountSelf=e.unmountThisParcel),r}var V=1e3,q={bootstrap:{millis:4e3,dieOnTimeout:!1,warningMillis:V},mount:{millis:3e3,dieOnTimeout:!1,warningMillis:V},unmount:{millis:3e3,dieOnTimeout:!1,warningMillis:V},unload:{millis:3e3,dieOnTimeout:!1,warningMillis:V},update:{millis:3e3,dieOnTimeout:!1,warningMillis:V}};function z(t,e,r){if("number"!=typeof t||t<=0)throw Error(u(16,!1));q.bootstrap={millis:t,dieOnTimeout:e,warningMillis:r||V}}function X(t,e,r){if("number"!=typeof t||t<=0)throw Error(u(17,!1));q.mount={millis:t,dieOnTimeout:e,warningMillis:r||V}}function Y(t,e,r){if("number"!=typeof t||t<=0)throw Error(u(18,!1));q.unmount={millis:t,dieOnTimeout:e,warningMillis:r||V}}function Z(t,e,r){if("number"!=typeof t||t<=0)throw Error(u(19,!1));q.unload={millis:t,dieOnTimeout:e,warningMillis:r||V}}function tt(t,e){var r=t.timeouts[e],n=r.warningMillis,o=U(t);return new Promise((i,a)=>{var s=!1,c=!1;t[e](Q(t)).then(t=>{s=!0,i(t)}).catch(t=>{s=!0,a(t)}),setTimeout(()=>f(1),n),setTimeout(()=>f(!0),r.millis);var l=u(31,!1,e,o,D(t),r.millis);function f(t){if(!s)if(!0===t)c=!0,r.dieOnTimeout?a(Error(l)):console.error(l);else if(!c){var e=t,o=e*n;console.warn(l),o+n<r.millis&&setTimeout(()=>f(e+1),n)}}})}function et(t){var e={};for(var r in q)e[r]=L({},q[r],t&&t[r]||{});return e}function rt(t){return Promise.resolve().then(()=>{return t.status!==c&&t.status!==E?t:(t.status=l,Promise.resolve().then(()=>{var n=t.loadImpl(Q(t));if(!x(n))throw r=!0,Error(u(33,!1,D(t)));return n.then(r=>{var n;t.loadErrorTime=null,"object"!=typeof(e=r)&&(n=34),I(e.bootstrap)||(n=35),I(e.mount)||(n=36),I(e.unmount)||(n=37);var i=U(e);if(n){var a;try{a=JSON.stringify(e)}catch(t){}return console.error(u(n,!1,i,D(t),a),e),o(void 0,t),t.status=y,t}return e.devtools&&e.devtools.overlays&&(t.devtools.overlays=L({},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=et(e.timeouts),t})}).catch(e=>(o(e,t),r?t.status=y:(t.status=E,t.loadErrorTime=(new Date).getTime()),t)));var e,r})}var nt={hashchange:[],popstate:[]},ot=["hashchange","popstate"];function it(t){var 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()}var r=pt(window.location.href),n=pt(e);0===e.indexOf("#")?window.location.hash=n.hash:r.host!==n.host&&n.host?window.location.href=e:n.pathname===r.pathname&&n.search===r.pathname?window.location.hash=n.hash:window.history.pushState(null,null,e)}function at(t){if(t){var e=t[0].type;ot.indexOf(e)>=0&&nt[e].forEach(e=>{try{e.apply(this,t)}catch(t){setTimeout(()=>{throw t})}})}}function ut(){jt([],arguments)}window.addEventListener("hashchange",ut),window.addEventListener("popstate",ut);var st=window.addEventListener,ct=window.removeEventListener;window.addEventListener=function(t,e){if(!("function"==typeof e&&ot.indexOf(t)>=0)||j(nt[t],t=>t===e))return st.apply(this,arguments);nt[t].push(e)},window.removeEventListener=function(t,e){if(!("function"==typeof e&&ot.indexOf(t)>=0))return ct.apply(this,arguments);nt[t]=nt[t].filter(t=>t!==e)};var lt=window.history.pushState;window.history.pushState=function(t){var e=lt.apply(this,arguments);return ut(ht(t)),e};var ft=window.history.replaceState;function ht(t){try{return new PopStateEvent("popstate",{state:t})}catch(r){var e=document.createEvent("PopStateEvent");return e.initPopStateEvent("popstate",!1,!1,t),e}}function pt(t){var e=document.createElement("a");return e.href=t,e}window.history.replaceState=function(t){var e=ft.apply(this,arguments);return ut(ht(t)),e},window.singleSpaNavigate=it;var mt=!1;function dt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.jQuery;if(t||window.$&&window.$.fn&&window.$.fn.jquery&&(t=window.$),t&&!mt){var e=t.fn.on,r=t.fn.off;t.fn.on=function(t,r){return vt.call(this,e,window.addEventListener,t,r,arguments)},t.fn.off=function(t,e){return vt.call(this,r,window.removeEventListener,t,e,arguments)},mt=!0}}function vt(t,e,r,n,o){return"string"!=typeof r?t.apply(this,o):(r.split(/\s+/).forEach(t=>{ot.indexOf(t)>=0&&(e(t,n),r=r.replace(t,""))}),""===r.trim()?this:t.apply(this,o))}var wt={};function gt(t){return Promise.resolve().then(()=>{var e=wt[D(t)];return e?t.status===c?(Et(t,e),t):t.status===g?e.promise.then(()=>t):t.status!==p?t:(t.status=g,tt(t,"unload").then(()=>(Et(t,e),t)).catch(r=>(function(t,e,r){delete wt[D(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,o(r,t),t.status=y,e.reject(r)}(t,e,r),t))):t})}function Et(t,e){delete wt[D(t)],delete t.bootstrap,delete t.mount,delete t.unmount,delete t.unload,t.status=c,e.resolve()}function yt(t,e,r,n){wt[D(t)]={app:t,resolve:r,reject:n},Object.defineProperty(wt[D(t)],"promise",{get:e})}var Ot=[];function Tt(){return Ot.filter(O).map(D)}function Pt(){return Ot.map(D)}function bt(t){var e=j(Ot,e=>D(e)===t);return e?e.status:null}function Nt(t,e,r){var n,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if("string"!=typeof t||0===t.length)throw Error(u(20,!1));if(-1!==Pt().indexOf(t))throw Error(u(21,!1,t));if("object"!=typeof o||Array.isArray(o))throw Error(u(22,!1));if(!e)throw Error(u(23,!1));if(n="function"!=typeof e?()=>Promise.resolve(e):e,"function"!=typeof r)throw Error(u(24,!1));Ot.push({loadErrorTime:null,name:t,loadImpl:n,activeWhen:r,status:c,parcels:{},devtools:{overlays:{options:{},selectors:[]}},customProps:o}),dt(),jt()}function _t(t){return Ot.filter(e=>e.activeWhen(t)).map(D)}function At(){return Ot.filter(A).filter(S).filter(b).filter(N)}function St(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{waitForUnmount:!1};if("string"!=typeof t)throw Error(u(26,!1));var r=j(Ot,e=>D(e)===t);if(!r)throw Error(u(27,!1,t));var n,o=function(t){return wt[t]}(D(r));if(e&&e.waitForUnmount){if(o)return o.promise;var i=new Promise((t,e)=>{yt(r,()=>i,t,e)});return i}return o?(n=o.promise,Dt(r,o.resolve,o.reject)):n=new Promise((t,e)=>{yt(r,()=>n,t,e),Dt(r,t,e)}),n}function Dt(t,e,r){G(t).then(gt).then(()=>{e(),setTimeout(()=>{jt()})}).catch(r)}var Mt=!1,Ut=[];function Lt(){return jt()}function jt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1?arguments[1]:void 0;if(Mt)return new Promise((t,r)=>{Ut.push({resolve:t,reject:r,eventArguments:e})});Mt=!0;var n=!0;return It?Promise.resolve().then(()=>{window.dispatchEvent(new r("single-spa:before-routing-event",a()));var e=Object.keys(wt).map(t=>wt[t].app).filter(T).map(gt),u=Ot.filter(A).filter(O).filter(_).map(G).map(t=>t.then(gt)).concat(e);u.length>0&&(n=!1);var s=Promise.all(u),c=At(),l=c.map(t=>rt(t).then(B).then(t=>s.then(()=>W(t))));l.length>0&&(n=!1);var f=Ot.filter(A).filter(T).filter(P).filter(N).filter(t=>c.indexOf(t)<0).map(t=>B(t).then(()=>s).then(()=>W(t)));return f.length>0&&(n=!1),s.catch(t=>{throw i(),t}).then(()=>(i(),Promise.all(l.concat(f)).catch(e=>{throw t.forEach(t=>t.reject(e)),e}).then(()=>o(!1))))}):Promise.resolve().then(()=>{var t=At().map(rt);return t.length>0&&(n=!1),Promise.all(t).then(o).catch(t=>{throw i(),t})});function o(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],o=Tt();e&&i(),t.forEach(t=>t.resolve(o));try{var u=n?"single-spa:no-app-change":"single-spa:app-change";window.dispatchEvent(new r(u,a())),window.dispatchEvent(new r("single-spa:routing-event",a()))}catch(t){setTimeout(()=>{throw t})}if(Mt=!1,Ut.length>0){var s=Ut;Ut=[],jt(s)}return o}function i(){t.forEach(t=>{at(t.eventArguments)}),at(e)}function a(){var t={detail:{}};return e&&e[0]&&(t.detail.originalEvent=e[0]),t}}var It=!1;function Rt(){It=!0,jt()}setTimeout(()=>{It||console.warn(u(1,!1))},5e3);var xt={getRawAppData:function(){return[...Ot]},reroute:jt,NOT_LOADED:c,toLoadPromise:rt,toBootstrapPromise:B,unregisterApplication:function(t){if(!Ot.find(e=>D(e)===t))throw Error(u(25,!1,t));return St(t).then(()=>{var e=Ot.findIndex(e=>D(e)===t);Ot.splice(e,1)})}};window&&window.__SINGLE_SPA_DEVTOOLS__&&(window.__SINGLE_SPA_DEVTOOLS__.exposedMethods=xt);export{h 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,p as NOT_MOUNTED,y as SKIP_BECAUSE_BROKEN,w as UNMOUNTING,v as UPDATING,i as addErrorHandler,_t as checkActivityFunctions,dt as ensureJQuerySupport,Pt as getAppNames,bt as getAppStatus,Tt as getMountedApps,F as mountRootParcel,it as navigateToUrl,Nt as registerApplication,a as removeErrorHandler,z as setBootstrapMaxTime,X as setMountMaxTime,Z as setUnloadMaxTime,Y as setUnmountMaxTime,Rt as start,Lt as triggerAppChange,St as unloadApplication};
3//# sourceMappingURL=single-spa.min.js.map