@lvetechs/micro-app 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ErrorBoundary.d.ts +52 -0
- package/dist/components/MicroApp.d.ts +26 -0
- package/dist/components/MicroAppErrorBoundary.d.ts +21 -0
- package/dist/components/MicroAppLoader.d.ts +7 -0
- package/dist/components/MicroAppMonitor.d.ts +38 -0
- package/dist/components/MicroAppStatusPanel.d.ts +6 -0
- package/dist/components/RemoteAppLoader.d.ts +24 -0
- package/dist/core/MicroAppManager.d.ts +8 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.es.js +2526 -0
- package/dist/index.umd.js +59 -0
- package/dist/style.css +1 -0
- package/dist/types/index.d.ts +105 -0
- package/package.json +6 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
(function(L,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],_):(L=typeof globalThis<"u"?globalThis:L||self,_(L.LveMicroApp={},L.React))})(this,function(L,_){"use strict";var Zn=Object.defineProperty;var Qn=(L,_,G)=>_ in L?Zn(L,_,{enumerable:!0,configurable:!0,writable:!0,value:G}):L[_]=G;var $=(L,_,G)=>Qn(L,typeof _!="symbol"?_+"":_,G);function G(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const h=G(_);class zt{constructor(t,r){$(this,"manager");$(this,"name");this.name=t,this.manager=r}getStatus(){return this.manager.getAppStatus(this.name)}getInfo(){return this.manager.getAppInfo(this.name)}start(){this.manager.startApp(this.name)}stop(){this.manager.stopApp(this.name)}restart(){this.manager.restartApp(this.name)}updateStatus(t,r){this.manager.updateAppStatus(this.name,t,r)}onStatusChange(t){return this.manager.onStatusChange(this.name,t)}async checkHealth(){return this.manager.checkAppHealth(this.name)}}class qt{constructor(t){$(this,"apps",new Map);$(this,"configMap",new Map);$(this,"instances",new Map);$(this,"statusListeners",new Map);$(this,"appChangeListeners",new Set);$(this,"options");$(this,"initialized",!1);this.options=t,this.initialize()}initialize(){this.initialized&&(console.warn("[MicroApp] 已初始化,重新初始化..."),this.apps.clear(),this.configMap.clear(),this.instances.clear());const t=[...this.options.apps].sort((r,n)=>(n.priority??0)-(r.priority??0));for(const r of t)if(r.enabled!==!1){this.configMap.set(r.name,r);const n=r.container;this.apps.set(r.name,{name:r.name,status:"idle",entry:r.entry,container:n}),this.instances.set(r.name,new zt(r.name,this))}this.initialized=!0,console.log("[MicroApp] 初始化完成",this.getAppNames())}getAppNames(){return Array.from(this.apps.keys())}getApps(){const t={};return this.apps.forEach((r,n)=>{t[n]=r}),t}getApp(t){return this.apps.get(t)}getAppStatus(t){var r;return((r=this.apps.get(t))==null?void 0:r.status)??"idle"}getAppInfo(t){return this.apps.get(t)}getAppInstance(t){return this.instances.get(t)}getAllAppInstances(){return this.instances}startApp(t){const r=this.apps.get(t),n=this.configMap.get(t);if(!r||!n){console.warn(`[MicroApp] 应用 ${t} 不存在`);return}if(r.status==="running"){console.log(`[MicroApp] 应用 ${t} 已在运行中`);return}this.updateAppStatus(t,"starting"),console.log(t,n,r,9999),this.loadApp(t,n,r)}async loadApp(t,r,n){var i,s,c,l,u,p;const o=n.container;if(!o){const f=new Error(`[MicroApp] 应用 ${t} 的容器不存在`);this.updateAppStatus(t,"error",f.message),(s=(i=this.options).onError)==null||s.call(i,f,t);return}try{await this.loadIframe(t,r.entry,o),this.updateAppStatus(t,"running"),(l=(c=this.options).onLoad)==null||l.call(c,t)}catch(f){const m=f instanceof Error?f:new Error(String(f));this.updateAppStatus(t,"error",m.message),(p=(u=this.options).onError)==null||p.call(u,m,t)}}loadIframe(t,r,n){async function o(i){try{const s=await fetch(i,{method:"HEAD",mode:"no-cors"});return!!(s.status===0||s.ok)}catch{}}return new Promise(async(i,s)=>{if(!await o(r))throw new Error(`iframe 加载失败: ${r}`);const l=document.createElement("iframe");l.src=r,l.style.width="100%",l.style.height="100%",l.style.border="none",l.setAttribute("sandbox","allow-scripts allow-forms allow-popups allow-top-navigation");const u=document.querySelector(n);if(!u){s(new Error(`容器不存在: ${n}`));return}u.innerHTML="",u.appendChild(l),l.onload=()=>{console.log(`[MicroApp] ${t} iframe 加载成功`),i()},l.onerror=()=>{s(new Error(`iframe 加载失败: ${r}`))}})}stopApp(t){const r=this.apps.get(t);if(!r){console.warn(`[MicroApp] 应用 ${t} 不存在`);return}if(!(r.status==="stopped"||r.status==="idle")){if(r.container){const n=document.querySelector(r.container);n&&(n.innerHTML="")}this.updateAppStatus(t,"stopped")}}restartApp(t){if(!this.configMap.get(t)){console.warn(`[MicroApp] 应用 ${t} 不存在`);return}this.stopApp(t),setTimeout(()=>{this.startApp(t)},300)}updateAppStatus(t,r,n){var c,l;const o=this.apps.get(t);if(!o)return;const i={...o,status:r,error:n,lastCheckTime:Date.now()};r==="running"&&!o.startTime&&(i.startTime=Date.now()),this.apps.set(t,i);const s=this.statusListeners.get(t);s&&s.forEach(u=>u(r,i)),this.appChangeListeners.forEach(u=>{u(t,r,i)}),(l=(c=this.options).onStatusChange)==null||l.call(c,t,r)}onStatusChange(t,r){return this.statusListeners.has(t)||this.statusListeners.set(t,new Set),this.statusListeners.get(t).add(r),()=>{const n=this.statusListeners.get(t);n&&(n.delete(r),n.size===0&&this.statusListeners.delete(t))}}onAppChange(t){return this.appChangeListeners.add(t),()=>{this.appChangeListeners.delete(t)}}async checkAppHealth(t){const r=this.apps.get(t);if(!r)return!1;try{return await new Promise(n=>setTimeout(n,100)),r.status==="running"?(this.updateAppStatus(t,"running"),!0):!1}catch(n){return this.updateAppStatus(t,"error",n instanceof Error?n.message:"健康检查失败"),!1}}destroy(){this.apps.forEach((t,r)=>{this.stopApp(r)}),this.apps.clear(),this.configMap.clear(),this.instances.clear(),this.statusListeners.clear(),this.appChangeListeners.clear(),this.initialized=!1,console.log("[MicroApp] 已销毁")}}function He(e){const t=new qt(e);return{start:()=>{Object.values(t.getApps()).forEach(n=>{n.status!=="running"&&t.startApp(n.name)})},stop:()=>{const r=t.getApps();Object.keys(r).forEach(n=>{t.stopApp(n)})},startApp:r=>{var n;try{t.startApp(r)}catch(o){(n=e.onError)==null||n.call(e,o instanceof Error?o:new Error(String(o)),r)}},stopApp:r=>{var n;try{t.stopApp(r)}catch(o){(n=e.onError)==null||n.call(e,o instanceof Error?o:new Error(String(o)),r)}},restartApp:r=>{var n;try{t.restartApp(r)}catch(o){(n=e.onError)==null||n.call(e,o instanceof Error?o:new Error(String(o)),r)}},getApp:r=>t.getAppInstance(r)||null,getAllApps:()=>t.getAllAppInstances(),onAppChange:r=>t.onAppChange((n,o)=>{r(n,o)}),onStatusChange:(r,n)=>t.onStatusChange(r,o=>{n(o)}),destroy:()=>{t.destroy()}}}var Oe={exports:{}},re={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var Je;function Kt(){if(Je)return re;Je=1;var e=_,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function s(c,l,u){var p,f={},m=null,w=null;u!==void 0&&(m=""+u),l.key!==void 0&&(m=""+l.key),l.ref!==void 0&&(w=l.ref);for(p in l)n.call(l,p)&&!i.hasOwnProperty(p)&&(f[p]=l[p]);if(c&&c.defaultProps)for(p in l=c.defaultProps,l)f[p]===void 0&&(f[p]=l[p]);return{$$typeof:t,type:c,key:m,ref:w,props:f,_owner:o.current}}return re.Fragment=r,re.jsx=s,re.jsxs=s,re}var ne={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var Ge;function Ht(){return Ge||(Ge=1,process.env.NODE_ENV!=="production"&&function(){var e=_,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),s=Symbol.for("react.provider"),c=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),w=Symbol.for("react.offscreen"),C=Symbol.iterator,O="@@iterator";function E(a){if(a===null||typeof a!="object")return null;var d=C&&a[C]||a[O];return typeof d=="function"?d:null}var N=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function v(a){{for(var d=arguments.length,g=new Array(d>1?d-1:0),b=1;b<d;b++)g[b-1]=arguments[b];P("error",a,g)}}function P(a,d,g){{var b=N.ReactDebugCurrentFrame,T=b.getStackAddendum();T!==""&&(d+="%s",g=g.concat([T]));var A=g.map(function(S){return String(S)});A.unshift("Warning: "+d),Function.prototype.apply.call(console[a],console,A)}}var j=!1,B=!1,de=!1,we=!1,pe=!1,Re;Re=Symbol.for("react.module.reference");function he(a){return!!(typeof a=="string"||typeof a=="function"||a===n||a===i||pe||a===o||a===u||a===p||we||a===w||j||B||de||typeof a=="object"&&a!==null&&(a.$$typeof===m||a.$$typeof===f||a.$$typeof===s||a.$$typeof===c||a.$$typeof===l||a.$$typeof===Re||a.getModuleId!==void 0))}function Ve(a,d,g){var b=a.displayName;if(b)return b;var T=d.displayName||d.name||"";return T!==""?g+"("+T+")":g}function xt(a){return a.displayName||"Context"}function K(a){if(a==null)return null;if(typeof a.tag=="number"&&v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof a=="function")return a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case n:return"Fragment";case r:return"Portal";case i:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case p:return"SuspenseList"}if(typeof a=="object")switch(a.$$typeof){case c:var d=a;return xt(d)+".Consumer";case s:var g=a;return xt(g._context)+".Provider";case l:return Ve(a,a.render,"ForwardRef");case f:var b=a.displayName||null;return b!==null?b:K(a.type)||"Memo";case m:{var T=a,A=T._payload,S=T._init;try{return K(S(A))}catch{return null}}}return null}var H=Object.assign,me=0,wt,Rt,Ct,St,Nt,_t,Ot;function Pt(){}Pt.__reactDisabledLog=!0;function Sn(){{if(me===0){wt=console.log,Rt=console.info,Ct=console.warn,St=console.error,Nt=console.group,_t=console.groupCollapsed,Ot=console.groupEnd;var a={configurable:!0,enumerable:!0,value:Pt,writable:!0};Object.defineProperties(console,{info:a,log:a,warn:a,error:a,group:a,groupCollapsed:a,groupEnd:a})}me++}}function Nn(){{if(me--,me===0){var a={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:H({},a,{value:wt}),info:H({},a,{value:Rt}),warn:H({},a,{value:Ct}),error:H({},a,{value:St}),group:H({},a,{value:Nt}),groupCollapsed:H({},a,{value:_t}),groupEnd:H({},a,{value:Ot})})}me<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Ue=N.ReactCurrentDispatcher,$e;function Ce(a,d,g){{if($e===void 0)try{throw Error()}catch(T){var b=T.stack.trim().match(/\n( *(at )?)/);$e=b&&b[1]||""}return`
|
|
18
|
+
`+$e+a}}var Be=!1,Se;{var _n=typeof WeakMap=="function"?WeakMap:Map;Se=new _n}function Tt(a,d){if(!a||Be)return"";{var g=Se.get(a);if(g!==void 0)return g}var b;Be=!0;var T=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var A;A=Ue.current,Ue.current=null,Sn();try{if(d){var S=function(){throw Error()};if(Object.defineProperty(S.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(S,[])}catch(I){b=I}Reflect.construct(a,[],S)}else{try{S.call()}catch(I){b=I}a.call(S.prototype)}}else{try{throw Error()}catch(I){b=I}a()}}catch(I){if(I&&b&&typeof I.stack=="string"){for(var R=I.stack.split(`
|
|
19
|
+
`),F=b.stack.split(`
|
|
20
|
+
`),D=R.length-1,k=F.length-1;D>=1&&k>=0&&R[D]!==F[k];)k--;for(;D>=1&&k>=0;D--,k--)if(R[D]!==F[k]){if(D!==1||k!==1)do if(D--,k--,k<0||R[D]!==F[k]){var M=`
|
|
21
|
+
`+R[D].replace(" at new "," at ");return a.displayName&&M.includes("<anonymous>")&&(M=M.replace("<anonymous>",a.displayName)),typeof a=="function"&&Se.set(a,M),M}while(D>=1&&k>=0);break}}}finally{Be=!1,Ue.current=A,Nn(),Error.prepareStackTrace=T}var te=a?a.displayName||a.name:"",J=te?Ce(te):"";return typeof a=="function"&&Se.set(a,J),J}function On(a,d,g){return Tt(a,!1)}function Pn(a){var d=a.prototype;return!!(d&&d.isReactComponent)}function Ne(a,d,g){if(a==null)return"";if(typeof a=="function")return Tt(a,Pn(a));if(typeof a=="string")return Ce(a);switch(a){case u:return Ce("Suspense");case p:return Ce("SuspenseList")}if(typeof a=="object")switch(a.$$typeof){case l:return On(a.render);case f:return Ne(a.type,d,g);case m:{var b=a,T=b._payload,A=b._init;try{return Ne(A(T),d,g)}catch{}}}return""}var ve=Object.prototype.hasOwnProperty,At={},jt=N.ReactDebugCurrentFrame;function _e(a){if(a){var d=a._owner,g=Ne(a.type,a._source,d?d.type:null);jt.setExtraStackFrame(g)}else jt.setExtraStackFrame(null)}function Tn(a,d,g,b,T){{var A=Function.call.bind(ve);for(var S in a)if(A(a,S)){var R=void 0;try{if(typeof a[S]!="function"){var F=Error((b||"React class")+": "+g+" type `"+S+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof a[S]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw F.name="Invariant Violation",F}R=a[S](d,S,b,g,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(D){R=D}R&&!(R instanceof Error)&&(_e(T),v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",b||"React class",g,S,typeof R),_e(null)),R instanceof Error&&!(R.message in At)&&(At[R.message]=!0,_e(T),v("Failed %s type: %s",g,R.message),_e(null))}}}var An=Array.isArray;function We(a){return An(a)}function jn(a){{var d=typeof Symbol=="function"&&Symbol.toStringTag,g=d&&a[Symbol.toStringTag]||a.constructor.name||"Object";return g}}function Dn(a){try{return Dt(a),!1}catch{return!0}}function Dt(a){return""+a}function kt(a){if(Dn(a))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",jn(a)),Dt(a)}var Lt=N.ReactCurrentOwner,kn={key:!0,ref:!0,__self:!0,__source:!0},Ft,It;function Ln(a){if(ve.call(a,"ref")){var d=Object.getOwnPropertyDescriptor(a,"ref").get;if(d&&d.isReactWarning)return!1}return a.ref!==void 0}function Fn(a){if(ve.call(a,"key")){var d=Object.getOwnPropertyDescriptor(a,"key").get;if(d&&d.isReactWarning)return!1}return a.key!==void 0}function In(a,d){typeof a.ref=="string"&&Lt.current}function Mn(a,d){{var g=function(){Ft||(Ft=!0,v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",d))};g.isReactWarning=!0,Object.defineProperty(a,"key",{get:g,configurable:!0})}}function Vn(a,d){{var g=function(){It||(It=!0,v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",d))};g.isReactWarning=!0,Object.defineProperty(a,"ref",{get:g,configurable:!0})}}var Un=function(a,d,g,b,T,A,S){var R={$$typeof:t,type:a,key:d,ref:g,props:S,_owner:A};return R._store={},Object.defineProperty(R._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(R,"_self",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.defineProperty(R,"_source",{configurable:!1,enumerable:!1,writable:!1,value:T}),Object.freeze&&(Object.freeze(R.props),Object.freeze(R)),R};function $n(a,d,g,b,T){{var A,S={},R=null,F=null;g!==void 0&&(kt(g),R=""+g),Fn(d)&&(kt(d.key),R=""+d.key),Ln(d)&&(F=d.ref,In(d,T));for(A in d)ve.call(d,A)&&!kn.hasOwnProperty(A)&&(S[A]=d[A]);if(a&&a.defaultProps){var D=a.defaultProps;for(A in D)S[A]===void 0&&(S[A]=D[A])}if(R||F){var k=typeof a=="function"?a.displayName||a.name||"Unknown":a;R&&Mn(S,k),F&&Vn(S,k)}return Un(a,R,F,T,b,Lt.current,S)}}var Ye=N.ReactCurrentOwner,Mt=N.ReactDebugCurrentFrame;function ee(a){if(a){var d=a._owner,g=Ne(a.type,a._source,d?d.type:null);Mt.setExtraStackFrame(g)}else Mt.setExtraStackFrame(null)}var ze;ze=!1;function qe(a){return typeof a=="object"&&a!==null&&a.$$typeof===t}function Vt(){{if(Ye.current){var a=K(Ye.current.type);if(a)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+a+"`."}return""}}function Bn(a){return""}var Ut={};function Wn(a){{var d=Vt();if(!d){var g=typeof a=="string"?a:a.displayName||a.name;g&&(d=`
|
|
24
|
+
|
|
25
|
+
Check the top-level render call using <`+g+">.")}return d}}function $t(a,d){{if(!a._store||a._store.validated||a.key!=null)return;a._store.validated=!0;var g=Wn(d);if(Ut[g])return;Ut[g]=!0;var b="";a&&a._owner&&a._owner!==Ye.current&&(b=" It was passed a child from "+K(a._owner.type)+"."),ee(a),v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',g,b),ee(null)}}function Bt(a,d){{if(typeof a!="object")return;if(We(a))for(var g=0;g<a.length;g++){var b=a[g];qe(b)&&$t(b,d)}else if(qe(a))a._store&&(a._store.validated=!0);else if(a){var T=E(a);if(typeof T=="function"&&T!==a.entries)for(var A=T.call(a),S;!(S=A.next()).done;)qe(S.value)&&$t(S.value,d)}}}function Yn(a){{var d=a.type;if(d==null||typeof d=="string")return;var g;if(typeof d=="function")g=d.propTypes;else if(typeof d=="object"&&(d.$$typeof===l||d.$$typeof===f))g=d.propTypes;else return;if(g){var b=K(d);Tn(g,a.props,"prop",b,a)}else if(d.PropTypes!==void 0&&!ze){ze=!0;var T=K(d);v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",T||"Unknown")}typeof d.getDefaultProps=="function"&&!d.getDefaultProps.isReactClassApproved&&v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function zn(a){{for(var d=Object.keys(a.props),g=0;g<d.length;g++){var b=d[g];if(b!=="children"&&b!=="key"){ee(a),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",b),ee(null);break}}a.ref!==null&&(ee(a),v("Invalid attribute `ref` supplied to `React.Fragment`."),ee(null))}}var Wt={};function Yt(a,d,g,b,T,A){{var S=he(a);if(!S){var R="";(a===void 0||typeof a=="object"&&a!==null&&Object.keys(a).length===0)&&(R+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var F=Bn();F?R+=F:R+=Vt();var D;a===null?D="null":We(a)?D="array":a!==void 0&&a.$$typeof===t?(D="<"+(K(a.type)||"Unknown")+" />",R=" Did you accidentally export a JSX literal instead of a component?"):D=typeof a,v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",D,R)}var k=$n(a,d,g,T,A);if(k==null)return k;if(S){var M=d.children;if(M!==void 0)if(b)if(We(M)){for(var te=0;te<M.length;te++)Bt(M[te],a);Object.freeze&&Object.freeze(M)}else v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Bt(M,a)}if(ve.call(d,"key")){var J=K(a),I=Object.keys(d).filter(function(Xn){return Xn!=="key"}),Ke=I.length>0?"{key: someKey, "+I.join(": ..., ")+": ...}":"{key: someKey}";if(!Wt[J+Ke]){var Gn=I.length>0?"{"+I.join(": ..., ")+": ...}":"{}";v(`A props object containing a "key" prop is being spread into JSX:
|
|
26
|
+
let props = %s;
|
|
27
|
+
<%s {...props} />
|
|
28
|
+
React keys must be passed directly to JSX without using spread:
|
|
29
|
+
let props = %s;
|
|
30
|
+
<%s key={someKey} {...props} />`,Ke,J,Gn,J),Wt[J+Ke]=!0}}return a===n?zn(k):Yn(k),k}}function qn(a,d,g){return Yt(a,d,g,!0)}function Kn(a,d,g){return Yt(a,d,g,!1)}var Hn=Kn,Jn=qn;ne.Fragment=n,ne.jsx=Hn,ne.jsxs=Jn}()),ne}process.env.NODE_ENV==="production"?Oe.exports=Kt():Oe.exports=Ht();var y=Oe.exports;/**
|
|
31
|
+
* @remix-run/router v1.23.2
|
|
32
|
+
*
|
|
33
|
+
* Copyright (c) Remix Software Inc.
|
|
34
|
+
*
|
|
35
|
+
* This source code is licensed under the MIT license found in the
|
|
36
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
37
|
+
*
|
|
38
|
+
* @license MIT
|
|
39
|
+
*/function ae(){return ae=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ae.apply(this,arguments)}var z;(function(e){e.Pop="POP",e.Push="PUSH",e.Replace="REPLACE"})(z||(z={}));const Xe="popstate";function Jt(e){e===void 0&&(e={});function t(n,o){let{pathname:i,search:s,hash:c}=n.location;return Pe("",{pathname:i,search:s,hash:c},o.state&&o.state.usr||null,o.state&&o.state.key||"default")}function r(n,o){return typeof o=="string"?o:oe(o)}return Xt(t,r,null,e)}function x(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function V(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function Gt(){return Math.random().toString(36).substr(2,8)}function Ze(e,t){return{usr:e.state,key:e.key,idx:t}}function Pe(e,t,r,n){return r===void 0&&(r=null),ae({pathname:typeof e=="string"?e:e.pathname,search:"",hash:""},typeof t=="string"?X(t):t,{state:r,key:t&&t.key||n||Gt()})}function oe(e){let{pathname:t="/",search:r="",hash:n=""}=e;return r&&r!=="?"&&(t+=r.charAt(0)==="?"?r:"?"+r),n&&n!=="#"&&(t+=n.charAt(0)==="#"?n:"#"+n),t}function X(e){let t={};if(e){let r=e.indexOf("#");r>=0&&(t.hash=e.substr(r),e=e.substr(0,r));let n=e.indexOf("?");n>=0&&(t.search=e.substr(n),e=e.substr(0,n)),e&&(t.pathname=e)}return t}function Xt(e,t,r,n){n===void 0&&(n={});let{window:o=document.defaultView,v5Compat:i=!1}=n,s=o.history,c=z.Pop,l=null,u=p();u==null&&(u=0,s.replaceState(ae({},s.state,{idx:u}),""));function p(){return(s.state||{idx:null}).idx}function f(){c=z.Pop;let E=p(),N=E==null?null:E-u;u=E,l&&l({action:c,location:O.location,delta:N})}function m(E,N){c=z.Push;let v=Pe(O.location,E,N);u=p()+1;let P=Ze(v,u),j=O.createHref(v);try{s.pushState(P,"",j)}catch(B){if(B instanceof DOMException&&B.name==="DataCloneError")throw B;o.location.assign(j)}i&&l&&l({action:c,location:O.location,delta:1})}function w(E,N){c=z.Replace;let v=Pe(O.location,E,N);u=p();let P=Ze(v,u),j=O.createHref(v);s.replaceState(P,"",j),i&&l&&l({action:c,location:O.location,delta:0})}function C(E){let N=o.location.origin!=="null"?o.location.origin:o.location.href,v=typeof E=="string"?E:oe(E);return v=v.replace(/ $/,"%20"),x(N,"No window.location.(origin|href) available to create URL for href: "+v),new URL(v,N)}let O={get action(){return c},get location(){return e(o,s)},listen(E){if(l)throw new Error("A history only accepts one active listener");return o.addEventListener(Xe,f),l=E,()=>{o.removeEventListener(Xe,f),l=null}},createHref(E){return t(o,E)},createURL:C,encodeLocation(E){let N=C(E);return{pathname:N.pathname,search:N.search,hash:N.hash}},push:m,replace:w,go(E){return s.go(E)}};return O}var Qe;(function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"})(Qe||(Qe={}));function Zt(e,t,r){return r===void 0&&(r="/"),Qt(e,t,r)}function Qt(e,t,r,n){let o=typeof t=="string"?X(t):t,i=q(o.pathname||"/",r);if(i==null)return null;let s=et(e);er(s);let c=null;for(let l=0;c==null&&l<s.length;++l){let u=fr(i);c=ur(s[l],u)}return c}function et(e,t,r,n){t===void 0&&(t=[]),r===void 0&&(r=[]),n===void 0&&(n="");let o=(i,s,c)=>{let l={relativePath:c===void 0?i.path||"":c,caseSensitive:i.caseSensitive===!0,childrenIndex:s,route:i};l.relativePath.startsWith("/")&&(x(l.relativePath.startsWith(n),'Absolute route path "'+l.relativePath+'" nested under path '+('"'+n+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),l.relativePath=l.relativePath.slice(n.length));let u=W([n,l.relativePath]),p=r.concat(l);i.children&&i.children.length>0&&(x(i.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+u+'".')),et(i.children,t,p,u)),!(i.path==null&&!i.index)&&t.push({path:u,score:sr(u,i.index),routesMeta:p})};return e.forEach((i,s)=>{var c;if(i.path===""||!((c=i.path)!=null&&c.includes("?")))o(i,s);else for(let l of tt(i.path))o(i,s,l)}),t}function tt(e){let t=e.split("/");if(t.length===0)return[];let[r,...n]=t,o=r.endsWith("?"),i=r.replace(/\?$/,"");if(n.length===0)return o?[i,""]:[i];let s=tt(n.join("/")),c=[];return c.push(...s.map(l=>l===""?i:[i,l].join("/"))),o&&c.push(...s),c.map(l=>e.startsWith("/")&&l===""?"/":l)}function er(e){e.sort((t,r)=>t.score!==r.score?r.score-t.score:lr(t.routesMeta.map(n=>n.childrenIndex),r.routesMeta.map(n=>n.childrenIndex)))}const tr=/^:[\w-]+$/,rr=3,nr=2,ar=1,or=10,ir=-2,rt=e=>e==="*";function sr(e,t){let r=e.split("/"),n=r.length;return r.some(rt)&&(n+=ir),t&&(n+=nr),r.filter(o=>!rt(o)).reduce((o,i)=>o+(tr.test(i)?rr:i===""?ar:or),n)}function lr(e,t){return e.length===t.length&&e.slice(0,-1).every((n,o)=>n===t[o])?e[e.length-1]-t[t.length-1]:0}function ur(e,t,r){let{routesMeta:n}=e,o={},i="/",s=[];for(let c=0;c<n.length;++c){let l=n[c],u=c===n.length-1,p=i==="/"?t:t.slice(i.length)||"/",f=Te({path:l.relativePath,caseSensitive:l.caseSensitive,end:u},p),m=l.route;if(!f)return null;Object.assign(o,f.params),s.push({params:o,pathname:W([i,f.pathname]),pathnameBase:vr(W([i,f.pathnameBase])),route:m}),f.pathnameBase!=="/"&&(i=W([i,f.pathnameBase]))}return s}function Te(e,t){typeof e=="string"&&(e={path:e,caseSensitive:!1,end:!0});let[r,n]=cr(e.path,e.caseSensitive,e.end),o=t.match(r);if(!o)return null;let i=o[0],s=i.replace(/(.)\/+$/,"$1"),c=o.slice(1);return{params:n.reduce((u,p,f)=>{let{paramName:m,isOptional:w}=p;if(m==="*"){let O=c[f]||"";s=i.slice(0,i.length-O.length).replace(/(.)\/+$/,"$1")}const C=c[f];return w&&!C?u[m]=void 0:u[m]=(C||"").replace(/%2F/g,"/"),u},{}),pathname:i,pathnameBase:s,pattern:e}}function cr(e,t,r){t===void 0&&(t=!1),r===void 0&&(r=!0),V(e==="*"||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were '+('"'+e.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+e.replace(/\*$/,"/*")+'".'));let n=[],o="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(s,c,l)=>(n.push({paramName:c,isOptional:l!=null}),l?"/?([^\\/]+)?":"/([^\\/]+)"));return e.endsWith("*")?(n.push({paramName:"*"}),o+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):r?o+="\\/*$":e!==""&&e!=="/"&&(o+="(?:(?=\\/|$))"),[new RegExp(o,t?void 0:"i"),n]}function fr(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return V(!1,'The URL path "'+e+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+t+").")),e}}function q(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let r=t.endsWith("/")?t.length-1:t.length,n=e.charAt(r);return n&&n!=="/"?null:e.slice(r)||"/"}const dr=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,pr=e=>dr.test(e);function hr(e,t){t===void 0&&(t="/");let{pathname:r,search:n="",hash:o=""}=typeof e=="string"?X(e):e,i;if(r)if(pr(r))i=r;else{if(r.includes("//")){let s=r;r=r.replace(/\/\/+/g,"/"),V(!1,"Pathnames cannot have embedded double slashes - normalizing "+(s+" -> "+r))}r.startsWith("/")?i=nt(r.substring(1),"/"):i=nt(r,t)}else i=t;return{pathname:i,search:gr(n),hash:yr(o)}}function nt(e,t){let r=t.replace(/\/+$/,"").split("/");return e.split("/").forEach(o=>{o===".."?r.length>1&&r.pop():o!=="."&&r.push(o)}),r.length>1?r.join("/"):"/"}function Ae(e,t,r,n){return"Cannot include a '"+e+"' character in a manually specified "+("`to."+t+"` field ["+JSON.stringify(n)+"]. Please separate it out to the ")+("`to."+r+"` field. Alternatively you may provide the full path as ")+'a string in <Link to="..."> and the router will parse it for you.'}function mr(e){return e.filter((t,r)=>r===0||t.route.path&&t.route.path.length>0)}function at(e,t){let r=mr(e);return t?r.map((n,o)=>o===r.length-1?n.pathname:n.pathnameBase):r.map(n=>n.pathnameBase)}function ot(e,t,r,n){n===void 0&&(n=!1);let o;typeof e=="string"?o=X(e):(o=ae({},e),x(!o.pathname||!o.pathname.includes("?"),Ae("?","pathname","search",o)),x(!o.pathname||!o.pathname.includes("#"),Ae("#","pathname","hash",o)),x(!o.search||!o.search.includes("#"),Ae("#","search","hash",o)));let i=e===""||o.pathname==="",s=i?"/":o.pathname,c;if(s==null)c=r;else{let f=t.length-1;if(!n&&s.startsWith("..")){let m=s.split("/");for(;m[0]==="..";)m.shift(),f-=1;o.pathname=m.join("/")}c=f>=0?t[f]:"/"}let l=hr(o,c),u=s&&s!=="/"&&s.endsWith("/"),p=(i||s===".")&&r.endsWith("/");return!l.pathname.endsWith("/")&&(u||p)&&(l.pathname+="/"),l}const W=e=>e.join("/").replace(/\/\/+/g,"/"),vr=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),gr=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,yr=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e;function Er(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}const it=["post","put","patch","delete"];new Set(it);const br=["get",...it];new Set(br);/**
|
|
40
|
+
* React Router v6.30.3
|
|
41
|
+
*
|
|
42
|
+
* Copyright (c) Remix Software Inc.
|
|
43
|
+
*
|
|
44
|
+
* This source code is licensed under the MIT license found in the
|
|
45
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
46
|
+
*
|
|
47
|
+
* @license MIT
|
|
48
|
+
*/function ie(){return ie=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ie.apply(this,arguments)}const se=h.createContext(null);process.env.NODE_ENV!=="production"&&(se.displayName="DataRouter");const je=h.createContext(null);process.env.NODE_ENV!=="production"&&(je.displayName="DataRouterState");const xr=h.createContext(null);process.env.NODE_ENV!=="production"&&(xr.displayName="Await");const U=h.createContext(null);process.env.NODE_ENV!=="production"&&(U.displayName="Navigation");const le=h.createContext(null);process.env.NODE_ENV!=="production"&&(le.displayName="Location");const Y=h.createContext({outlet:null,matches:[],isDataRoute:!1});process.env.NODE_ENV!=="production"&&(Y.displayName="Route");const De=h.createContext(null);process.env.NODE_ENV!=="production"&&(De.displayName="RouteError");function wr(e,t){let{relative:r}=t===void 0?{}:t;ue()||(process.env.NODE_ENV!=="production"?x(!1,"useHref() may be used only in the context of a <Router> component."):x(!1));let{basename:n,navigator:o}=h.useContext(U),{hash:i,pathname:s,search:c}=ce(e,{relative:r}),l=s;return n!=="/"&&(l=s==="/"?n:W([n,s])),o.createHref({pathname:l,search:c,hash:i})}function ue(){return h.useContext(le)!=null}function Z(){return ue()||(process.env.NODE_ENV!=="production"?x(!1,"useLocation() may be used only in the context of a <Router> component."):x(!1)),h.useContext(le).location}const st="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function lt(e){h.useContext(U).static||h.useLayoutEffect(e)}function ut(){let{isDataRoute:e}=h.useContext(Y);return e?Fr():Rr()}function Rr(){ue()||(process.env.NODE_ENV!=="production"?x(!1,"useNavigate() may be used only in the context of a <Router> component."):x(!1));let e=h.useContext(se),{basename:t,future:r,navigator:n}=h.useContext(U),{matches:o}=h.useContext(Y),{pathname:i}=Z(),s=JSON.stringify(at(o,r.v7_relativeSplatPath)),c=h.useRef(!1);return lt(()=>{c.current=!0}),h.useCallback(function(u,p){if(p===void 0&&(p={}),process.env.NODE_ENV!=="production"&&V(c.current,st),!c.current)return;if(typeof u=="number"){n.go(u);return}let f=ot(u,JSON.parse(s),i,p.relative==="path");e==null&&t!=="/"&&(f.pathname=f.pathname==="/"?t:W([t,f.pathname])),(p.replace?n.replace:n.push)(f,p.state,p)},[t,n,s,i,e])}function ce(e,t){let{relative:r}=t===void 0?{}:t,{future:n}=h.useContext(U),{matches:o}=h.useContext(Y),{pathname:i}=Z(),s=JSON.stringify(at(o,n.v7_relativeSplatPath));return h.useMemo(()=>ot(e,JSON.parse(s),i,r==="path"),[e,s,i,r])}function Cr(e,t){return Sr(e,t)}function Sr(e,t,r,n){ue()||(process.env.NODE_ENV!=="production"?x(!1,"useRoutes() may be used only in the context of a <Router> component."):x(!1));let{navigator:o}=h.useContext(U),{matches:i}=h.useContext(Y),s=i[i.length-1],c=s?s.params:{},l=s?s.pathname:"/",u=s?s.pathnameBase:"/",p=s&&s.route;if(process.env.NODE_ENV!=="production"){let v=p&&p.path||"";dt(l,!p||v.endsWith("*"),"You rendered descendant <Routes> (or called `useRoutes()`) at "+('"'+l+'" (under <Route path="'+v+'">) but the ')+`parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
49
|
+
|
|
50
|
+
`+('Please change the parent <Route path="'+v+'"> to <Route ')+('path="'+(v==="/"?"*":v+"/*")+'">.'))}let f=Z(),m;if(t){var w;let v=typeof t=="string"?X(t):t;u==="/"||(w=v.pathname)!=null&&w.startsWith(u)||(process.env.NODE_ENV!=="production"?x(!1,"When overriding the location using `<Routes location>` or `useRoutes(routes, location)`, the location pathname must begin with the portion of the URL pathname that was "+('matched by all parent routes. The current pathname base is "'+u+'" ')+('but pathname "'+v.pathname+'" was given in the `location` prop.')):x(!1)),m=v}else m=f;let C=m.pathname||"/",O=C;if(u!=="/"){let v=u.replace(/^\//,"").split("/");O="/"+C.replace(/^\//,"").split("/").slice(v.length).join("/")}let E=Zt(e,{pathname:O});process.env.NODE_ENV!=="production"&&(process.env.NODE_ENV!=="production"&&V(p||E!=null,'No routes matched location "'+m.pathname+m.search+m.hash+'" '),process.env.NODE_ENV!=="production"&&V(E==null||E[E.length-1].route.element!==void 0||E[E.length-1].route.Component!==void 0||E[E.length-1].route.lazy!==void 0,'Matched leaf route at location "'+m.pathname+m.search+m.hash+'" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.'));let N=Tr(E&&E.map(v=>Object.assign({},v,{params:Object.assign({},c,v.params),pathname:W([u,o.encodeLocation?o.encodeLocation(v.pathname).pathname:v.pathname]),pathnameBase:v.pathnameBase==="/"?u:W([u,o.encodeLocation?o.encodeLocation(v.pathnameBase).pathname:v.pathnameBase])})),i,r,n);return t&&N?h.createElement(le.Provider,{value:{location:ie({pathname:"/",search:"",hash:"",state:null,key:"default"},m),navigationType:z.Pop}},N):N}function Nr(){let e=Lr(),t=Er(e)?e.status+" "+e.statusText:e instanceof Error?e.message:JSON.stringify(e),r=e instanceof Error?e.stack:null,n="rgba(200,200,200, 0.5)",o={padding:"0.5rem",backgroundColor:n},i={padding:"2px 4px",backgroundColor:n},s=null;return process.env.NODE_ENV!=="production"&&(console.error("Error handled by React Router default ErrorBoundary:",e),s=h.createElement(h.Fragment,null,h.createElement("p",null,"💿 Hey developer 👋"),h.createElement("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",h.createElement("code",{style:i},"ErrorBoundary")," or"," ",h.createElement("code",{style:i},"errorElement")," prop on your route."))),h.createElement(h.Fragment,null,h.createElement("h2",null,"Unexpected Application Error!"),h.createElement("h3",{style:{fontStyle:"italic"}},t),r?h.createElement("pre",{style:o},r):null,s)}const _r=h.createElement(Nr,null);class Or extends h.Component{constructor(t){super(t),this.state={location:t.location,revalidation:t.revalidation,error:t.error}}static getDerivedStateFromError(t){return{error:t}}static getDerivedStateFromProps(t,r){return r.location!==t.location||r.revalidation!=="idle"&&t.revalidation==="idle"?{error:t.error,location:t.location,revalidation:t.revalidation}:{error:t.error!==void 0?t.error:r.error,location:r.location,revalidation:t.revalidation||r.revalidation}}componentDidCatch(t,r){console.error("React Router caught the following error during render",t,r)}render(){return this.state.error!==void 0?h.createElement(Y.Provider,{value:this.props.routeContext},h.createElement(De.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function Pr(e){let{routeContext:t,match:r,children:n}=e,o=h.useContext(se);return o&&o.static&&o.staticContext&&(r.route.errorElement||r.route.ErrorBoundary)&&(o.staticContext._deepestRenderedBoundaryId=r.route.id),h.createElement(Y.Provider,{value:t},n)}function Tr(e,t,r,n){var o;if(t===void 0&&(t=[]),r===void 0&&(r=null),n===void 0&&(n=null),e==null){var i;if(!r)return null;if(r.errors)e=r.matches;else if((i=n)!=null&&i.v7_partialHydration&&t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let s=e,c=(o=r)==null?void 0:o.errors;if(c!=null){let p=s.findIndex(f=>f.route.id&&(c==null?void 0:c[f.route.id])!==void 0);p>=0||(process.env.NODE_ENV!=="production"?x(!1,"Could not find a matching route for errors on route IDs: "+Object.keys(c).join(",")):x(!1)),s=s.slice(0,Math.min(s.length,p+1))}let l=!1,u=-1;if(r&&n&&n.v7_partialHydration)for(let p=0;p<s.length;p++){let f=s[p];if((f.route.HydrateFallback||f.route.hydrateFallbackElement)&&(u=p),f.route.id){let{loaderData:m,errors:w}=r,C=f.route.loader&&m[f.route.id]===void 0&&(!w||w[f.route.id]===void 0);if(f.route.lazy||C){l=!0,u>=0?s=s.slice(0,u+1):s=[s[0]];break}}}return s.reduceRight((p,f,m)=>{let w,C=!1,O=null,E=null;r&&(w=c&&f.route.id?c[f.route.id]:void 0,O=f.route.errorElement||_r,l&&(u<0&&m===0?(dt("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),C=!0,E=null):u===m&&(C=!0,E=f.route.hydrateFallbackElement||null)));let N=t.concat(s.slice(0,m+1)),v=()=>{let P;return w?P=O:C?P=E:f.route.Component?P=h.createElement(f.route.Component,null):f.route.element?P=f.route.element:P=p,h.createElement(Pr,{match:f,routeContext:{outlet:p,matches:N,isDataRoute:r!=null},children:P})};return r&&(f.route.ErrorBoundary||f.route.errorElement||m===0)?h.createElement(Or,{location:r.location,revalidation:r.revalidation,component:O,error:w,children:v(),routeContext:{outlet:null,matches:N,isDataRoute:!0}}):v()},null)}var ct=function(e){return e.UseBlocker="useBlocker",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e}(ct||{}),fe=function(e){return e.UseBlocker="useBlocker",e.UseLoaderData="useLoaderData",e.UseActionData="useActionData",e.UseRouteError="useRouteError",e.UseNavigation="useNavigation",e.UseRouteLoaderData="useRouteLoaderData",e.UseMatches="useMatches",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e.UseRouteId="useRouteId",e}(fe||{});function ke(e){return e+" must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router."}function Ar(e){let t=h.useContext(se);return t||(process.env.NODE_ENV!=="production"?x(!1,ke(e)):x(!1)),t}function jr(e){let t=h.useContext(je);return t||(process.env.NODE_ENV!=="production"?x(!1,ke(e)):x(!1)),t}function Dr(e){let t=h.useContext(Y);return t||(process.env.NODE_ENV!=="production"?x(!1,ke(e)):x(!1)),t}function Le(e){let t=Dr(e),r=t.matches[t.matches.length-1];return r.route.id||(process.env.NODE_ENV!=="production"?x(!1,e+' can only be used on routes that contain a unique "id"'):x(!1)),r.route.id}function kr(){return Le(fe.UseRouteId)}function Lr(){var e;let t=h.useContext(De),r=jr(fe.UseRouteError),n=Le(fe.UseRouteError);return t!==void 0?t:(e=r.errors)==null?void 0:e[n]}function Fr(){let{router:e}=Ar(ct.UseNavigateStable),t=Le(fe.UseNavigateStable),r=h.useRef(!1);return lt(()=>{r.current=!0}),h.useCallback(function(o,i){i===void 0&&(i={}),process.env.NODE_ENV!=="production"&&V(r.current,st),r.current&&(typeof o=="number"?e.navigate(o):e.navigate(o,ie({fromRouteId:t},i)))},[e,t])}const ft={};function dt(e,t,r){!t&&!ft[e]&&(ft[e]=!0,process.env.NODE_ENV!=="production"&&V(!1,r))}const pt={};function Ir(e,t){process.env.NODE_ENV!=="production"&&!pt[t]&&(pt[t]=!0,console.warn(t))}const ht=(e,t,r)=>Ir(e,"⚠️ React Router Future Flag Warning: "+t+". "+("You can use the `"+e+"` future flag to opt-in early. ")+("For more information, see "+r+"."));function Mr(e,t){(e==null?void 0:e.v7_startTransition)===void 0&&ht("v7_startTransition","React Router will begin wrapping state updates in `React.startTransition` in v7","https://reactrouter.com/v6/upgrading/future#v7_starttransition"),(e==null?void 0:e.v7_relativeSplatPath)===void 0&&ht("v7_relativeSplatPath","Relative route resolution within Splat routes is changing in v7","https://reactrouter.com/v6/upgrading/future#v7_relativesplatpath")}function mt(e){process.env.NODE_ENV!=="production"?x(!1,"A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>."):x(!1)}function Vr(e){let{basename:t="/",children:r=null,location:n,navigationType:o=z.Pop,navigator:i,static:s=!1,future:c}=e;ue()&&(process.env.NODE_ENV!=="production"?x(!1,"You cannot render a <Router> inside another <Router>. You should never have more than one in your app."):x(!1));let l=t.replace(/^\/*/,"/"),u=h.useMemo(()=>({basename:l,navigator:i,static:s,future:ie({v7_relativeSplatPath:!1},c)}),[l,c,i,s]);typeof n=="string"&&(n=X(n));let{pathname:p="/",search:f="",hash:m="",state:w=null,key:C="default"}=n,O=h.useMemo(()=>{let E=q(p,l);return E==null?null:{location:{pathname:E,search:f,hash:m,state:w,key:C},navigationType:o}},[l,p,f,m,w,C,o]);return process.env.NODE_ENV!=="production"&&V(O!=null,'<Router basename="'+l+'"> is not able to match the URL '+('"'+p+f+m+'" because it does not start with the ')+"basename, so the <Router> won't render anything."),O==null?null:h.createElement(U.Provider,{value:u},h.createElement(le.Provider,{children:r,value:O}))}function Ur(e){let{children:t,location:r}=e;return Cr(Fe(t),r)}new Promise(()=>{});function Fe(e,t){t===void 0&&(t=[]);let r=[];return h.Children.forEach(e,(n,o)=>{if(!h.isValidElement(n))return;let i=[...t,o];if(n.type===h.Fragment){r.push.apply(r,Fe(n.props.children,i));return}n.type!==mt&&(process.env.NODE_ENV!=="production"?x(!1,"["+(typeof n.type=="string"?n.type:n.type.name)+"] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>"):x(!1)),!n.props.index||!n.props.children||(process.env.NODE_ENV!=="production"?x(!1,"An index route cannot have child routes."):x(!1));let s={id:n.props.id||i.join("-"),caseSensitive:n.props.caseSensitive,element:n.props.element,Component:n.props.Component,index:n.props.index,path:n.props.path,loader:n.props.loader,action:n.props.action,errorElement:n.props.errorElement,ErrorBoundary:n.props.ErrorBoundary,hasErrorBoundary:n.props.ErrorBoundary!=null||n.props.errorElement!=null,shouldRevalidate:n.props.shouldRevalidate,handle:n.props.handle,lazy:n.props.lazy};n.props.children&&(s.children=Fe(n.props.children,i)),r.push(s)}),r}/**
|
|
51
|
+
* React Router DOM v6.30.3
|
|
52
|
+
*
|
|
53
|
+
* Copyright (c) Remix Software Inc.
|
|
54
|
+
*
|
|
55
|
+
* This source code is licensed under the MIT license found in the
|
|
56
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
57
|
+
*
|
|
58
|
+
* @license MIT
|
|
59
|
+
*/function Q(){return Q=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Q.apply(this,arguments)}function Ie(e,t){if(e==null)return{};var r={},n=Object.keys(e),o,i;for(i=0;i<n.length;i++)o=n[i],!(t.indexOf(o)>=0)&&(r[o]=e[o]);return r}const ge="get",ye="application/x-www-form-urlencoded";function Ee(e){return e!=null&&typeof e.tagName=="string"}function $r(e){return Ee(e)&&e.tagName.toLowerCase()==="button"}function Br(e){return Ee(e)&&e.tagName.toLowerCase()==="form"}function Wr(e){return Ee(e)&&e.tagName.toLowerCase()==="input"}function Yr(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function zr(e,t){return e.button===0&&(!t||t==="_self")&&!Yr(e)}let be=null;function qr(){if(be===null)try{new FormData(document.createElement("form"),0),be=!1}catch{be=!0}return be}const Kr=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function Me(e){return e!=null&&!Kr.has(e)?(process.env.NODE_ENV!=="production"&&V(!1,'"'+e+'" is not a valid `encType` for `<Form>`/`<fetcher.Form>` '+('and will default to "'+ye+'"')),null):e}function Hr(e,t){let r,n,o,i,s;if(Br(e)){let c=e.getAttribute("action");n=c?q(c,t):null,r=e.getAttribute("method")||ge,o=Me(e.getAttribute("enctype"))||ye,i=new FormData(e)}else if($r(e)||Wr(e)&&(e.type==="submit"||e.type==="image")){let c=e.form;if(c==null)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let l=e.getAttribute("formaction")||c.getAttribute("action");if(n=l?q(l,t):null,r=e.getAttribute("formmethod")||c.getAttribute("method")||ge,o=Me(e.getAttribute("formenctype"))||Me(c.getAttribute("enctype"))||ye,i=new FormData(c,e),!qr()){let{name:u,type:p,value:f}=e;if(p==="image"){let m=u?u+".":"";i.append(m+"x","0"),i.append(m+"y","0")}else u&&i.append(u,f)}}else{if(Ee(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');r=ge,n=null,o=ye,s=e}return i&&o==="text/plain"&&(s=i,i=void 0),{action:n,method:r.toLowerCase(),encType:o,formData:i,body:s}}const Jr=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],Gr=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],Xr=["fetcherKey","navigate","reloadDocument","replace","state","method","action","onSubmit","relative","preventScrollReset","viewTransition"],Zr="6";try{window.__reactRouterVersion=Zr}catch{}const vt=h.createContext({isTransitioning:!1});process.env.NODE_ENV!=="production"&&(vt.displayName="ViewTransition");const Qr=h.createContext(new Map);process.env.NODE_ENV!=="production"&&(Qr.displayName="Fetchers");const gt=h["startTransition"];function en(e){let{basename:t,children:r,future:n,window:o}=e,i=h.useRef();i.current==null&&(i.current=Jt({window:o,v5Compat:!0}));let s=i.current,[c,l]=h.useState({action:s.action,location:s.location}),{v7_startTransition:u}=n||{},p=h.useCallback(f=>{u&>?gt(()=>l(f)):l(f)},[l,u]);return h.useLayoutEffect(()=>s.listen(p),[s,p]),h.useEffect(()=>Mr(n),[n]),h.createElement(Vr,{basename:t,children:r,location:c.location,navigationType:c.action,navigator:s,future:n})}process.env.NODE_ENV;const tn=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",rn=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,yt=h.forwardRef(function(t,r){let{onClick:n,relative:o,reloadDocument:i,replace:s,state:c,target:l,to:u,preventScrollReset:p,viewTransition:f}=t,m=Ie(t,Jr),{basename:w}=h.useContext(U),C,O=!1;if(typeof u=="string"&&rn.test(u)&&(C=u,tn))try{let P=new URL(window.location.href),j=u.startsWith("//")?new URL(P.protocol+u):new URL(u),B=q(j.pathname,w);j.origin===P.origin&&B!=null?u=B+j.search+j.hash:O=!0}catch{process.env.NODE_ENV!=="production"&&V(!1,'<Link to="'+u+'"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.')}let E=wr(u,{relative:o}),N=sn(u,{replace:s,state:c,target:l,preventScrollReset:p,relative:o,viewTransition:f});function v(P){n&&n(P),P.defaultPrevented||N(P)}return h.createElement("a",Q({},m,{href:C||E,onClick:O||i?n:v,ref:r,target:l}))});process.env.NODE_ENV!=="production"&&(yt.displayName="Link");const nn=h.forwardRef(function(t,r){let{"aria-current":n="page",caseSensitive:o=!1,className:i="",end:s=!1,style:c,to:l,viewTransition:u,children:p}=t,f=Ie(t,Gr),m=ce(l,{relative:f.relative}),w=Z(),C=h.useContext(je),{navigator:O,basename:E}=h.useContext(U),N=C!=null&&pn(m)&&u===!0,v=O.encodeLocation?O.encodeLocation(m).pathname:m.pathname,P=w.pathname,j=C&&C.navigation&&C.navigation.location?C.navigation.location.pathname:null;o||(P=P.toLowerCase(),j=j?j.toLowerCase():null,v=v.toLowerCase()),j&&E&&(j=q(j,E)||j);const B=v!=="/"&&v.endsWith("/")?v.length-1:v.length;let de=P===v||!s&&P.startsWith(v)&&P.charAt(B)==="/",we=j!=null&&(j===v||!s&&j.startsWith(v)&&j.charAt(v.length)==="/"),pe={isActive:de,isPending:we,isTransitioning:N},Re=de?n:void 0,he;typeof i=="function"?he=i(pe):he=[i,de?"active":null,we?"pending":null,N?"transitioning":null].filter(Boolean).join(" ");let Ve=typeof c=="function"?c(pe):c;return h.createElement(yt,Q({},f,{"aria-current":Re,className:he,ref:r,style:Ve,to:l,viewTransition:u}),typeof p=="function"?p(pe):p)});process.env.NODE_ENV!=="production"&&(nn.displayName="NavLink");const an=h.forwardRef((e,t)=>{let{fetcherKey:r,navigate:n,reloadDocument:o,replace:i,state:s,method:c=ge,action:l,onSubmit:u,relative:p,preventScrollReset:f,viewTransition:m}=e,w=Ie(e,Xr),C=fn(),O=dn(l,{relative:p}),E=c.toLowerCase()==="get"?"get":"post",N=v=>{if(u&&u(v),v.defaultPrevented)return;v.preventDefault();let P=v.nativeEvent.submitter,j=(P==null?void 0:P.getAttribute("formmethod"))||c;C(P||v.currentTarget,{fetcherKey:r,method:j,navigate:n,replace:i,state:s,relative:p,preventScrollReset:f,viewTransition:m})};return h.createElement("form",Q({ref:t,method:E,action:O,onSubmit:o?u:N},w))});process.env.NODE_ENV!=="production"&&(an.displayName="Form"),process.env.NODE_ENV;var xe;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(xe||(xe={}));var Et;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Et||(Et={}));function on(e){return e+" must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router."}function bt(e){let t=h.useContext(se);return t||(process.env.NODE_ENV!=="production"?x(!1,on(e)):x(!1)),t}function sn(e,t){let{target:r,replace:n,state:o,preventScrollReset:i,relative:s,viewTransition:c}=t===void 0?{}:t,l=ut(),u=Z(),p=ce(e,{relative:s});return h.useCallback(f=>{if(zr(f,r)){f.preventDefault();let m=n!==void 0?n:oe(u)===oe(p);l(e,{replace:m,state:o,preventScrollReset:i,relative:s,viewTransition:c})}},[u,l,p,n,o,r,e,i,s,c])}function ln(){if(typeof document>"u")throw new Error("You are calling submit during the server render. Try calling submit within a `useEffect` or callback instead.")}let un=0,cn=()=>"__"+String(++un)+"__";function fn(){let{router:e}=bt(xe.UseSubmit),{basename:t}=h.useContext(U),r=kr();return h.useCallback(function(n,o){o===void 0&&(o={}),ln();let{action:i,method:s,encType:c,formData:l,body:u}=Hr(n,t);if(o.navigate===!1){let p=o.fetcherKey||cn();e.fetch(p,r,o.action||i,{preventScrollReset:o.preventScrollReset,formData:l,body:u,formMethod:o.method||s,formEncType:o.encType||c,flushSync:o.flushSync})}else e.navigate(o.action||i,{preventScrollReset:o.preventScrollReset,formData:l,body:u,formMethod:o.method||s,formEncType:o.encType||c,replace:o.replace,state:o.state,fromRouteId:r,flushSync:o.flushSync,viewTransition:o.viewTransition})},[e,t,r])}function dn(e,t){let{relative:r}=t===void 0?{}:t,{basename:n}=h.useContext(U),o=h.useContext(Y);o||(process.env.NODE_ENV!=="production"?x(!1,"useFormAction must be used inside a RouteContext"):x(!1));let[i]=o.matches.slice(-1),s=Q({},ce(e||".",{relative:r})),c=Z();if(e==null){s.search=c.search;let l=new URLSearchParams(s.search),u=l.getAll("index");if(u.some(f=>f==="")){l.delete("index"),u.filter(m=>m).forEach(m=>l.append("index",m));let f=l.toString();s.search=f?"?"+f:""}}return(!e||e===".")&&i.route.index&&(s.search=s.search?s.search.replace(/^\?/,"?index&"):"?index"),n!=="/"&&(s.pathname=s.pathname==="/"?n:W([n,s.pathname])),oe(s)}function pn(e,t){t===void 0&&(t={});let r=h.useContext(vt);r==null&&(process.env.NODE_ENV!=="production"?x(!1,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"):x(!1));let{basename:n}=bt(xe.useViewTransitionState),o=ce(e,{relative:t.relative});if(!r.isTransitioning)return!1;let i=q(r.currentLocation.pathname,n)||r.currentLocation.pathname,s=q(r.nextLocation.pathname,n)||r.nextLocation.pathname;return Te(o.pathname,s)!=null||Te(o.pathname,i)!=null}function hn({appName:e,appPath:t,children:r,onStatusChange:n}){return y.jsx(y.Fragment,{children:r})}class mn extends _.Component{constructor(t){super(t),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,r){const{appName:n,onError:o}=this.props;this.setState({errorInfo:r}),console.error(`[ErrorBoundary][${n}] 🛡️ 捕获到运行时错误:`,t),console.error(`[ErrorBoundary][${n}] 组件栈:`,r.componentStack),o==null||o(t,r)}render(){const{hasError:t,error:r,errorInfo:n}=this.state,{appName:o,children:i,onReset:s}=this.props;return t?y.jsx("div",{className:"flex items-center justify-center min-h-[400px] p-6",children:y.jsx("div",{className:"w-full max-w-lg",children:y.jsxs("div",{className:"bg-white rounded-lg shadow-lg border border-red-200 overflow-hidden",children:[y.jsx("div",{className:"bg-red-50 border-b border-red-200 px-6 py-4",children:y.jsxs("div",{className:"flex items-center gap-3",children:[y.jsx("span",{className:"text-2xl",children:"🛡️"}),y.jsxs("div",{children:[y.jsxs("h3",{className:"text-lg font-semibold text-red-800",children:["子应用 [",o,"] 运行出错"]}),y.jsx("p",{className:"text-sm text-red-600 mt-0.5",children:"该错误已被隔离,不影响其他子应用的正常运行"})]})]})}),y.jsxs("div",{className:"px-6 py-4 space-y-4",children:[r&&y.jsxs("div",{children:[y.jsx("p",{className:"text-sm font-medium text-gray-700 mb-1",children:"错误信息:"}),y.jsx("div",{className:"bg-red-50 rounded-md px-4 py-3 text-sm text-red-700 font-mono break-all",children:r.message})]}),(n==null?void 0:n.componentStack)&&y.jsxs("details",{className:"group",children:[y.jsxs("summary",{className:"text-sm font-medium text-gray-700 cursor-pointer hover:text-gray-900 select-none",children:[y.jsx("span",{className:"group-open:hidden",children:"▶ 展开错误堆栈"}),y.jsx("span",{className:"hidden group-open:inline",children:"▼ 收起错误堆栈"})]}),y.jsx("pre",{className:"mt-2 bg-gray-50 rounded-md px-4 py-3 text-xs text-gray-600 overflow-x-auto max-h-48 overflow-y-auto whitespace-pre-wrap",children:n.componentStack})]}),y.jsx("div",{className:"bg-blue-50 rounded-md px-4 py-3",children:y.jsx("p",{className:"text-sm text-blue-700",children:"点击重试会完整重载该子应用,或返回继续使用其他功能。"})})]}),y.jsxs("div",{className:"px-6 py-4 bg-gray-50 border-t border-gray-200 flex gap-3",children:[y.jsx("button",{onClick:s,className:"px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 transition-colors",children:"重试加载"}),y.jsx("button",{onClick:()=>window.history.back(),className:"px-4 py-2 bg-white text-gray-700 text-sm font-medium rounded-md border border-gray-300 hover:bg-gray-50 transition-colors",children:"返回上一页"})]})]})})}):i}}function vn({appName:e,children:t,onError:r}){const[n,o]=_.useState(0),i=_.useCallback(()=>{console.log(`[ErrorBoundary][${e}] 触发 key 重置,完整重建子应用`),o(l=>l+1)},[e]),s=_.useCallback((l,u)=>{c({type:"SET_ERROR",error:l}),r==null||r(l,u)},[r]),[,c]=_.useReducer((l,u)=>{switch(u.type){case"SET_ERROR":return{...l,hasError:!0,error:u.error??null};case"RESET_ERROR":return{...l,hasError:!1,error:null};case"ROUTE_CHANGED":return l.hasError?(i(),{...l,hasError:!1,error:null}):l;default:return l}},{hasError:!1,error:null,errorInfo:null});return _.useEffect(()=>{c({type:"ROUTE_CHANGED"})},[location.pathname]),y.jsx(mn,{appName:e,onError:s,onReset:i,children:t},n)}function gn(){const[e,t]=_.useState(null),r=_.useCallback(n=>{const o=n instanceof Error?n:new Error(n);t(o)},[]);if(e)throw e;return r}function yn({url:e,containerId:t,mode:r="iframe",iframeStyle:n,onError:o,onLoad:i}){const s=_.useRef(null),c=gn();async function l(u){try{const p=await fetch(u,{method:"HEAD",mode:"no-cors"});return!!(p.status===0||p.ok)}catch(p){c(p instanceof Error?p:new Error("请求失败"))}}return _.useEffect(()=>{if(!s.current)return;const u=s.current;r==="iframe"&&(async()=>{const f=document.createElement("iframe"),m=document.querySelector(".micro-app-container");return await l(e)&&(f.src=e,f.style.width="100%",f.style.height=m?m.offsetHeight+"px":"100%",f.style.border="none",f.setAttribute("sandbox","allow-same-origin allow-scripts allow-forms allow-popups allow-top-navigation"),Object.assign(f.style,n||{})),u.appendChild(f),()=>{u.contains(f)&&u.removeChild(f)}})()},[e,t,r,n,o,i]),y.jsx("div",{ref:s,id:t,style:{width:"100%",height:"100%",position:"relative"}})}function En({apps:e}){return y.jsx(Ur,{children:e.map(t=>{const r=t.active_rule?t.active_rule:`/${t.name}/*`,n=t.active_rule||`/app/${t.name}`;return y.jsx(mt,{path:r,element:y.jsx(hn,{appName:t.name,appPath:n,children:y.jsx(vn,{appName:t.name,children:y.jsx(_.Suspense,{fallback:y.jsx("div",{className:"flex items-center justify-center h-96",children:y.jsx("div",{className:"text-center",children:y.jsxs("p",{className:"mt-4 text-gray-600",children:["正在加载 ",t.name,"..."]})})}),children:y.jsx("div",{id:t.container.replace("#",""),"data-micro-app":t.name,className:"micro-app-container w-full h-full flex-1",children:t.entry&&y.jsx(yn,{url:t.entry,containerId:t.container.replace("#",""),mode:"iframe"})})})})})},t.name)})})}function bn(e){return e.active_rule?e.active_rule:`/${e.name}/*`}function xn({apps:e,activeApp:t,onError:r,onStatusChange:n,onLoad:o,children:i}){const s=ut(),c=_.useRef(new Set),l=_.useRef({onError:r,onStatusChange:n,onLoad:o});l.current={onError:r,onStatusChange:n,onLoad:o};const u=_.useMemo(()=>He({apps:e,onError:l.current.onError,onStatusChange:(f,m)=>{var w,C;(C=(w=l.current).onStatusChange)==null||C.call(w,f,m)},onLoad:l.current.onLoad}),[e]);return _.useEffect(()=>{if(!t)return;const p=e.find(w=>w.name===t);if(!p)return;const f=bn(p);s(f);const m=()=>{if(!document.querySelector(p.container)){requestAnimationFrame(m);return}c.current.has(t)||(u.startApp(t),c.current.add(t))};requestAnimationFrame(m),e.forEach(w=>{w.name!==t&&c.current.has(w.name)&&(u.stopApp(w.name),c.current.delete(w.name))})},[t,e,u,s]),y.jsxs("div",{className:"micro-app-wrapper",children:[y.jsx(En,{apps:e}),i]})}function wn(e){return y.jsx(en,{children:y.jsx(xn,{...e})})}class Rn extends _.Component{constructor(r){super(r);$(this,"handleRetry",()=>{var r,n;this.setState({hasError:!1,error:null}),(n=(r=this.props).onRetry)==null||n.call(r,this.props.appName)});this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){var o,i;console.error(`[${this.props.appName||"ErrorBoundary"}] 捕获错误:`,r,n),(i=(o=this.props).onError)==null||i.call(o,r,this.props.appName)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:y.jsx("div",{className:"micro-app-error flex flex-col items-center justify-center h-full p-4 bg-gray-50 rounded",children:y.jsxs("div",{className:"text-center",children:[y.jsx("div",{className:"text-red-500 text-4xl mb-2",children:"⚠️"}),y.jsxs("h3",{className:"text-lg font-semibold text-gray-800 mb-2",children:[this.props.appName||"应用"," 加载失败"]}),y.jsx("p",{className:"text-sm text-gray-500 mb-4",children:((r=this.state.error)==null?void 0:r.message)||"应用渲染时发生错误"}),y.jsx("button",{onClick:this.handleRetry,className:"px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors",children:"重试"})]})}):this.props.children}}const Cn="1.0.0";L.ErrorBoundary=Rn,L.MicroApp=wn,L.createMicroApp=He,L.version=Cn,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.micro-app-wrapper,.micro-app-container{width:100%;height:100%}.block{display:block}.hidden{display:none}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================
|
|
3
|
+
* 微前端服务类型定义
|
|
4
|
+
* ============================================
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 子应用状态
|
|
8
|
+
*/
|
|
9
|
+
export type MicroAppStatus = 'idle' | 'starting' | 'running' | 'error' | 'stopped';
|
|
10
|
+
/**
|
|
11
|
+
* 子应用加载模式
|
|
12
|
+
*/
|
|
13
|
+
export type LoadMode = 'iframe' | 'dynamic';
|
|
14
|
+
/**
|
|
15
|
+
* 子应用配置
|
|
16
|
+
*/
|
|
17
|
+
export interface SubAppConfig {
|
|
18
|
+
/** 应用名称,唯一标识 */
|
|
19
|
+
name: string;
|
|
20
|
+
/** 应用入口 URL(远程应用时使用) */
|
|
21
|
+
entry?: string;
|
|
22
|
+
/** 挂载容器的 DOM 节点 */
|
|
23
|
+
container: string;
|
|
24
|
+
/** 描述信息 */
|
|
25
|
+
description?: string;
|
|
26
|
+
/** 优先级,数值越大越先加载 */
|
|
27
|
+
priority?: number;
|
|
28
|
+
/** 是否启用 */
|
|
29
|
+
enabled?: boolean;
|
|
30
|
+
/** 路由规则,用于匹配子应用 */
|
|
31
|
+
active_rule?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 微应用信息(运行时状态)
|
|
35
|
+
*/
|
|
36
|
+
export interface MicroAppInfo {
|
|
37
|
+
name: string;
|
|
38
|
+
status: MicroAppStatus;
|
|
39
|
+
startTime?: number;
|
|
40
|
+
error?: string;
|
|
41
|
+
lastCheckTime?: number;
|
|
42
|
+
entry?: string;
|
|
43
|
+
container?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 微应用实例接口
|
|
47
|
+
*/
|
|
48
|
+
export interface MicroAppInstance {
|
|
49
|
+
/** 应用名称 */
|
|
50
|
+
name: string;
|
|
51
|
+
/** 获取应用状态 */
|
|
52
|
+
getStatus: () => MicroAppStatus;
|
|
53
|
+
/** 获取应用信息 */
|
|
54
|
+
getInfo: () => MicroAppInfo | undefined;
|
|
55
|
+
/** 启动应用 */
|
|
56
|
+
start: () => void;
|
|
57
|
+
/** 停止应用 */
|
|
58
|
+
stop: () => void;
|
|
59
|
+
/** 重启应用 */
|
|
60
|
+
restart: () => void;
|
|
61
|
+
/** 手动更新状态 */
|
|
62
|
+
updateStatus: (status: MicroAppStatus, error?: string) => void;
|
|
63
|
+
/** 订阅状态变化 */
|
|
64
|
+
onStatusChange: (callback: (status: MicroAppStatus, info?: MicroAppInfo) => void) => () => void;
|
|
65
|
+
/** 健康检查 */
|
|
66
|
+
checkHealth: () => Promise<boolean>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 微前端服务配置
|
|
70
|
+
*/
|
|
71
|
+
export interface MicroAppOptions {
|
|
72
|
+
/** 子应用配置数组 */
|
|
73
|
+
apps: SubAppConfig[];
|
|
74
|
+
/** 错误回调 */
|
|
75
|
+
onError?: (error: Error, appName?: string) => void;
|
|
76
|
+
/** 状态变化回调 */
|
|
77
|
+
onStatusChange?: (name: string, status: MicroAppStatus) => void;
|
|
78
|
+
/** 加载完成回调 */
|
|
79
|
+
onLoad?: (appName: string) => void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 微前端服务实例
|
|
83
|
+
*/
|
|
84
|
+
export interface MicroAppService {
|
|
85
|
+
/** 启动所有应用 */
|
|
86
|
+
start: () => void;
|
|
87
|
+
/** 停止所有应用 */
|
|
88
|
+
stop: () => void;
|
|
89
|
+
/** 启动指定应用 */
|
|
90
|
+
startApp: (name: string) => void;
|
|
91
|
+
/** 停止指定应用 */
|
|
92
|
+
stopApp: (name: string) => void;
|
|
93
|
+
/** 重启指定应用 */
|
|
94
|
+
restartApp: (name: string) => void;
|
|
95
|
+
/** 获取指定应用实例 */
|
|
96
|
+
getApp: (name: string) => MicroAppInstance | null;
|
|
97
|
+
/** 获取所有应用 */
|
|
98
|
+
getAllApps: () => Map<string, MicroAppInstance>;
|
|
99
|
+
/** 监听所有应用状态变化 */
|
|
100
|
+
onAppChange: (callback: (name: string, status: MicroAppStatus) => void) => () => void;
|
|
101
|
+
/** 监听指定应用状态变化 */
|
|
102
|
+
onStatusChange: (name: string, callback: (status: MicroAppStatus) => void) => () => void;
|
|
103
|
+
/** 销毁实例 */
|
|
104
|
+
destroy: () => void;
|
|
105
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvetechs/micro-app",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "轻量级微前端框架 - 支持函数式和组件式实例化",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
|
-
"dist"
|
|
10
|
+
"dist",
|
|
11
|
+
"package.json",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.md"
|
|
11
14
|
],
|
|
12
15
|
"peerDependencies": {
|
|
13
16
|
"react": "^18.2.0",
|
|
@@ -36,12 +39,11 @@
|
|
|
36
39
|
"react",
|
|
37
40
|
"iframe"
|
|
38
41
|
],
|
|
39
|
-
"author": "",
|
|
42
|
+
"author": "lvetechs",
|
|
40
43
|
"license": "MIT",
|
|
41
44
|
"scripts": {
|
|
42
45
|
"dev": "vite",
|
|
43
46
|
"build": "tsc && vite build",
|
|
44
|
-
"build:lib": "tsc && vite build --mode lib",
|
|
45
47
|
"preview": "vite preview",
|
|
46
48
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
|
|
47
49
|
}
|