UNPKG

16.7 kBJavaScriptView Raw
1/* single-spa@5.3.0 - ESM - prod */
2var 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=`${M(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 M(t){return D(t)?"parcel":"application"}function j(){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=M(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=j({},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=M(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]=j({},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=M(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=j({},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(){Mt([],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(31,!1));const e=["name","app","activeWhen","customProps"];if(0!==Object.keys(t).reduce((t,n)=>e.includes(n)?t:t.concat(n),[]).length)throw Error(u(30,!1));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 n=t=>"string"==typeof t||"function"==typeof t;if(!(n(t.activeWhen)||Array.isArray(t.activeWhen)&&t.activeWhen.every(n)))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(j({loadErrorTime:null,status:c,parcels:{},devtools:{overlays:{options:{},selectors:[]}}},o)),et&&(pt(),Mt())}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(()=>{Mt()})}).catch(n)}let _t=!1,St=[];function Dt(){return Mt()}function Mt(t=[],e){if(_t)return new Promise((t,n)=>{St.push({resolve:t,reject:n,eventArguments:e})});let r=!0;return jt?(_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=[],Mt(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 jt=!1;function Ut(t){var e;jt=!0,t&&t.urlRerouteOnly&&(e=t.urlRerouteOnly,st=e),et&&Mt()}et&&setTimeout(()=>{jt||console.warn(u(1,!1))},5e3);var Lt={getRawAppData:function(){return[...Et]},reroute:Mt,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};
3//# sourceMappingURL=single-spa.min.js.map