UNPKG

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