@vlian/framework 1.2.59 → 1.2.60
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/analytics/index.cjs +1 -22
- package/dist/analytics.umd.js +1 -1
- package/dist/components/LocaleSwitch.cjs +1 -116
- package/dist/components/ThemeSwitch.cjs +1 -115
- package/dist/components/index.cjs +1 -20
- package/dist/components/persistence.cjs +1 -58
- package/dist/core/Test.cjs +1 -64
- package/dist/core/app/AppContext.cjs +1 -348
- package/dist/core/app/AppContext.types.cjs +1 -4
- package/dist/core/app/BasicLayout.cjs +1 -122
- package/dist/core/app/DefaultApp.cjs +1 -150
- package/dist/core/app/index.cjs +1 -41
- package/dist/core/config/AppConfig.cjs +1 -139
- package/dist/core/config/ConfigLoader.cjs +1 -323
- package/dist/core/config/ConfigValidator.cjs +2 -133
- package/dist/core/config/index.cjs +1 -28
- package/dist/core/dev/DevTools.cjs +1 -226
- package/dist/core/error/ErrorBoundary.cjs +1 -401
- package/dist/core/error/ErrorHandler.cjs +1 -275
- package/dist/core/error/index.cjs +1 -34
- package/dist/core/event/AppEventBus.cjs +1 -444
- package/dist/core/event/frameworkEvents.cjs +1 -141
- package/dist/core/event/hooks.cjs +1 -69
- package/dist/core/event/index.cjs +1 -41
- package/dist/core/event/types.cjs +1 -62
- package/dist/core/event/useEventBus.cjs +1 -25
- package/dist/core/index.cjs +1 -140
- package/dist/core/initialization/InitializationErrorThrower.cjs +1 -75
- package/dist/core/initialization/index.cjs +1 -26
- package/dist/core/initialization/initialization.cjs +1 -64
- package/dist/core/initialization/initializationErrorState.cjs +1 -66
- package/dist/core/kernel/defaultAdapters.cjs +1 -184
- package/dist/core/kernel/errors.cjs +1 -69
- package/dist/core/kernel/index.cjs +1 -20
- package/dist/core/kernel/startKernel.cjs +1 -200
- package/dist/core/kernel/types.cjs +1 -4
- package/dist/core/middleware.cjs +1 -73
- package/dist/core/plugin/PluginEventBus.cjs +1 -298
- package/dist/core/plugin/PluginSandbox.cjs +1 -137
- package/dist/core/plugin.cjs +1 -494
- package/dist/core/router/RouterManager.cjs +1 -286
- package/dist/core/router/adapter/AdapterManager.cjs +1 -235
- package/dist/core/router/adapter/index.cjs +1 -22
- package/dist/core/router/adapter/react-router/ReactRouterAdapter.cjs +1 -128
- package/dist/core/router/adapter/react-router/index.cjs +1 -20
- package/dist/core/router/adapter/types.cjs +1 -6
- package/dist/core/router/dev/RouterDevTools.cjs +1 -260
- package/dist/core/router/dev/index.cjs +1 -20
- package/dist/core/router/dynamic/DynamicRouteManager.cjs +1 -193
- package/dist/core/router/dynamic/index.cjs +1 -20
- package/dist/core/router/errors/RouterError.cjs +1 -61
- package/dist/core/router/errors/index.cjs +1 -20
- package/dist/core/router/index.cjs +1 -36
- package/dist/core/router/lifecycle/RouterLifecycleManager.cjs +1 -144
- package/dist/core/router/lifecycle/index.cjs +1 -20
- package/dist/core/router/middleware/RouterMiddlewareManager.cjs +1 -193
- package/dist/core/router/middleware/auth.cjs +1 -66
- package/dist/core/router/middleware/index.cjs +1 -22
- package/dist/core/router/middleware/types.cjs +1 -6
- package/dist/core/router/monitoring/RouterMonitoring.cjs +1 -227
- package/dist/core/router/monitoring/index.cjs +1 -20
- package/dist/core/router/navigation/RouterNavigation.cjs +1 -239
- package/dist/core/router/navigation/index.cjs +1 -20
- package/dist/core/router/performance/RouteCache.cjs +1 -305
- package/dist/core/router/performance/RoutePreloader.cjs +1 -292
- package/dist/core/router/performance/index.cjs +1 -21
- package/dist/core/router/plugin/RouterPluginManager.cjs +1 -262
- package/dist/core/router/plugin/index.cjs +1 -21
- package/dist/core/router/plugin/types.cjs +1 -39
- package/dist/core/router/types.cjs +1 -4
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +1 -129
- package/dist/core/router/utils/adapters/react-router/transform.cjs +1 -250
- package/dist/core/router/utils/transform.cjs +1 -780
- package/dist/core/router/validation/RouterConfigValidator.cjs +2 -83
- package/dist/core/router/validation/index.cjs +1 -21
- package/dist/core/router/validation/schema.cjs +1 -159
- package/dist/core/router/version/RouteVersionManager.cjs +1 -205
- package/dist/core/router/version/index.cjs +1 -20
- package/dist/core/splash/SplashScreen.cjs +1 -341
- package/dist/core/splash/index.cjs +1 -22
- package/dist/core/splash/splashScreenUtils.cjs +1 -38
- package/dist/core/startup/AppInstance.cjs +1 -239
- package/dist/core/startup/environment.cjs +1 -169
- package/dist/core/startup/index.cjs +1 -23
- package/dist/core/startup/initializeServices.cjs +1 -226
- package/dist/core/startup/performanceTracker.cjs +1 -179
- package/dist/core/startup/renderApp.cjs +1 -314
- package/dist/core/startup/startApp.cjs +1 -317
- package/dist/core/types.cjs +1 -4
- package/dist/index.cjs +1 -52
- package/dist/index.umd.cjs +1 -27
- package/dist/index.umd.js +1 -1
- package/dist/kernel/constants.cjs +1 -65
- package/dist/kernel/index.cjs +1 -38
- package/dist/kernel/kernel.cjs +1 -295
- package/dist/kernel/manager/cacheManager.cjs +1 -46
- package/dist/kernel/manager/i18n/I18nManager.cjs +1 -91
- package/dist/kernel/manager/i18n/i18n.persistence.cjs +1 -60
- package/dist/kernel/manager/i18n/i18n.schema.cjs +1 -86
- package/dist/kernel/manager/i18n/index.cjs +1 -11
- package/dist/kernel/manager/i18nManager.cjs +1 -11
- package/dist/kernel/manager/index.cjs +1 -28
- package/dist/kernel/manager/logger/LoggerManager.cjs +1 -107
- package/dist/kernel/manager/logger/index.cjs +1 -11
- package/dist/kernel/manager/logger/logger.persistence.cjs +1 -62
- package/dist/kernel/manager/logger/logger.schema.cjs +1 -74
- package/dist/kernel/manager/loggerManager.cjs +1 -11
- package/dist/kernel/manager/theme/ThemeManager.cjs +1 -84
- package/dist/kernel/manager/theme/index.cjs +1 -11
- package/dist/kernel/manager/theme/theme.dom.cjs +1 -61
- package/dist/kernel/manager/theme/theme.persistence.cjs +1 -57
- package/dist/kernel/manager/theme/theme.schema.cjs +1 -122
- package/dist/kernel/manager/themeManager.cjs +1 -11
- package/dist/kernel/types.cjs +1 -4
- package/dist/library/index.cjs +1 -19
- package/dist/library/locale/index.cjs +1 -39
- package/dist/library/locale/langs/en-us/index.cjs +1 -32
- package/dist/library/locale/langs/zh-cn/index.cjs +1 -32
- package/dist/library/locale/types.cjs +1 -4
- package/dist/library/storage/cache.cjs +1 -243
- package/dist/library/storage/encryption.cjs +1 -147
- package/dist/library/storage/index.cjs +1 -124
- package/dist/state/StateManager.cjs +1 -166
- package/dist/state/adapters/AdapterFactory.cjs +1 -89
- package/dist/state/adapters/DefaultAdapter.cjs +1 -75
- package/dist/state/adapters/ReduxAdapter.cjs +1 -443
- package/dist/state/adapters/ZustandAdapter.cjs +1 -69
- package/dist/state/adapters/index.cjs +1 -44
- package/dist/state/adapters/types.cjs +1 -20
- package/dist/state/core/DerivedStateInstance.cjs +1 -174
- package/dist/state/core/StateInstance.cjs +1 -170
- package/dist/state/core/StateRegistry.cjs +1 -110
- package/dist/state/core/StateScope.cjs +1 -137
- package/dist/state/core/index.cjs +1 -30
- package/dist/state/index.cjs +1 -30
- package/dist/state/types.cjs +1 -12
- package/dist/state.umd.js +1 -1
- package/dist/types.cjs +1 -4
- package/dist/utils/analytics.cjs +1 -217
- package/dist/utils/configSecurity.cjs +3 -182
- package/dist/utils/csrf.cjs +1 -18
- package/dist/utils/errors/ErrorCodes.cjs +1 -25
- package/dist/utils/errors.cjs +1 -111
- package/dist/utils/index.cjs +1 -135
- package/dist/utils/logger.cjs +1 -25
- package/dist/utils/logger.types.cjs +1 -11
- package/dist/utils/monitoring.cjs +1 -18
- package/dist/utils/performance.cjs +1 -22
- package/dist/utils/resourceLoader.cjs +1 -22
- package/dist/utils/runtimeSecurity.cjs +1 -11
- package/dist/utils/security.cjs +1 -19
- package/dist/utils/traceId.cjs +1 -37
- package/dist/utils/validation.cjs +1 -19
- package/package.json +7 -3
|
@@ -1,226 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 开发工具模块(无 UI 框架依赖)
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
function _export(target, all) {
|
|
8
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
_export(exports, {
|
|
14
|
-
get DevTools () {
|
|
15
|
-
return DevTools;
|
|
16
|
-
},
|
|
17
|
-
get DevToolsTrigger () {
|
|
18
|
-
return DevToolsTrigger;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
22
|
-
const _react = require("react");
|
|
23
|
-
const _app = require("../app");
|
|
24
|
-
function toPrettyJson(value) {
|
|
25
|
-
try {
|
|
26
|
-
return JSON.stringify(value, null, 2);
|
|
27
|
-
} catch {
|
|
28
|
-
return String(value);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function DevTools({ appInstance, visible, onClose }) {
|
|
32
|
-
const [performanceMetrics, setPerformanceMetrics] = (0, _react.useState)({});
|
|
33
|
-
const stateManager = (0, _app.useStateManager)();
|
|
34
|
-
(0, _react.useEffect)(()=>{
|
|
35
|
-
if (!visible) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const tracker = appInstance.getPerformanceTracker();
|
|
39
|
-
if (!tracker) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const metrics = tracker.getMetrics();
|
|
43
|
-
setPerformanceMetrics({
|
|
44
|
-
serviceInitDuration: metrics.serviceInitDuration || 0,
|
|
45
|
-
initializationDuration: metrics.initializationDuration || 0,
|
|
46
|
-
firstRenderDuration: metrics.firstRenderDuration || 0,
|
|
47
|
-
totalStartupDuration: metrics.totalStartupDuration || 0,
|
|
48
|
-
fcp: metrics.fcp || 0,
|
|
49
|
-
lcp: metrics.lcp || 0,
|
|
50
|
-
fid: metrics.fid || 0,
|
|
51
|
-
cls: metrics.cls || 0
|
|
52
|
-
});
|
|
53
|
-
}, [
|
|
54
|
-
visible,
|
|
55
|
-
appInstance
|
|
56
|
-
]);
|
|
57
|
-
if (!visible) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const options = appInstance.getOptions();
|
|
61
|
-
const allStates = stateManager?.getAllStates?.() || [];
|
|
62
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
63
|
-
style: {
|
|
64
|
-
position: 'fixed',
|
|
65
|
-
top: 0,
|
|
66
|
-
right: 0,
|
|
67
|
-
width: 'min(680px, 95vw)',
|
|
68
|
-
height: '100vh',
|
|
69
|
-
zIndex: 9999,
|
|
70
|
-
background: '#fff',
|
|
71
|
-
borderLeft: '1px solid #d9e2ec',
|
|
72
|
-
padding: 16,
|
|
73
|
-
overflowY: 'auto',
|
|
74
|
-
boxShadow: '-8px 0 20px rgba(0, 0, 0, 0.08)'
|
|
75
|
-
},
|
|
76
|
-
children: [
|
|
77
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
78
|
-
style: {
|
|
79
|
-
display: 'flex',
|
|
80
|
-
justifyContent: 'space-between',
|
|
81
|
-
alignItems: 'center'
|
|
82
|
-
},
|
|
83
|
-
children: [
|
|
84
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h3", {
|
|
85
|
-
style: {
|
|
86
|
-
margin: 0
|
|
87
|
-
},
|
|
88
|
-
children: "DevTools"
|
|
89
|
-
}),
|
|
90
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
91
|
-
onClick: onClose,
|
|
92
|
-
style: {
|
|
93
|
-
border: 'none',
|
|
94
|
-
background: 'transparent',
|
|
95
|
-
cursor: 'pointer'
|
|
96
|
-
},
|
|
97
|
-
children: "关闭"
|
|
98
|
-
})
|
|
99
|
-
]
|
|
100
|
-
}),
|
|
101
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("section", {
|
|
102
|
-
style: {
|
|
103
|
-
marginTop: 12
|
|
104
|
-
},
|
|
105
|
-
children: [
|
|
106
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h4", {
|
|
107
|
-
children: "实例"
|
|
108
|
-
}),
|
|
109
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
110
|
-
children: [
|
|
111
|
-
"id: ",
|
|
112
|
-
appInstance.id
|
|
113
|
-
]
|
|
114
|
-
}),
|
|
115
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
116
|
-
children: [
|
|
117
|
-
"initialized: ",
|
|
118
|
-
String(appInstance.isInitialized())
|
|
119
|
-
]
|
|
120
|
-
})
|
|
121
|
-
]
|
|
122
|
-
}),
|
|
123
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("section", {
|
|
124
|
-
style: {
|
|
125
|
-
marginTop: 12
|
|
126
|
-
},
|
|
127
|
-
children: [
|
|
128
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h4", {
|
|
129
|
-
children: "性能"
|
|
130
|
-
}),
|
|
131
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("pre", {
|
|
132
|
-
style: {
|
|
133
|
-
background: '#f7fafc',
|
|
134
|
-
padding: 10,
|
|
135
|
-
borderRadius: 8
|
|
136
|
-
},
|
|
137
|
-
children: toPrettyJson(performanceMetrics)
|
|
138
|
-
})
|
|
139
|
-
]
|
|
140
|
-
}),
|
|
141
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("section", {
|
|
142
|
-
style: {
|
|
143
|
-
marginTop: 12
|
|
144
|
-
},
|
|
145
|
-
children: [
|
|
146
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h4", {
|
|
147
|
-
children: "状态管理"
|
|
148
|
-
}),
|
|
149
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
150
|
-
children: [
|
|
151
|
-
"stateCount: ",
|
|
152
|
-
allStates.length
|
|
153
|
-
]
|
|
154
|
-
}),
|
|
155
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("pre", {
|
|
156
|
-
style: {
|
|
157
|
-
background: '#f7fafc',
|
|
158
|
-
padding: 10,
|
|
159
|
-
borderRadius: 8
|
|
160
|
-
},
|
|
161
|
-
children: toPrettyJson(allStates.slice(0, 10))
|
|
162
|
-
})
|
|
163
|
-
]
|
|
164
|
-
}),
|
|
165
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("section", {
|
|
166
|
-
style: {
|
|
167
|
-
marginTop: 12
|
|
168
|
-
},
|
|
169
|
-
children: [
|
|
170
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h4", {
|
|
171
|
-
children: "配置"
|
|
172
|
-
}),
|
|
173
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("pre", {
|
|
174
|
-
style: {
|
|
175
|
-
background: '#f7fafc',
|
|
176
|
-
padding: 10,
|
|
177
|
-
borderRadius: 8,
|
|
178
|
-
whiteSpace: 'pre-wrap'
|
|
179
|
-
},
|
|
180
|
-
children: toPrettyJson(options)
|
|
181
|
-
})
|
|
182
|
-
]
|
|
183
|
-
})
|
|
184
|
-
]
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
function resolvePosition(position) {
|
|
188
|
-
const style = {
|
|
189
|
-
position: 'fixed',
|
|
190
|
-
zIndex: 9998
|
|
191
|
-
};
|
|
192
|
-
const pos = position || 'bottom-right';
|
|
193
|
-
if (pos.includes('bottom')) style.bottom = 16;
|
|
194
|
-
if (pos.includes('top')) style.top = 16;
|
|
195
|
-
if (pos.includes('right')) style.right = 16;
|
|
196
|
-
if (pos.includes('left')) style.left = 16;
|
|
197
|
-
return style;
|
|
198
|
-
}
|
|
199
|
-
function DevToolsTrigger({ appInstance, position = 'bottom-right' }) {
|
|
200
|
-
const [visible, setVisible] = (0, _react.useState)(false);
|
|
201
|
-
if (process.env.NODE_ENV !== 'development') {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
205
|
-
children: [
|
|
206
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
207
|
-
onClick: ()=>setVisible(true),
|
|
208
|
-
style: {
|
|
209
|
-
...resolvePosition(position),
|
|
210
|
-
border: 'none',
|
|
211
|
-
background: '#2f80ed',
|
|
212
|
-
color: '#fff',
|
|
213
|
-
borderRadius: 999,
|
|
214
|
-
padding: '8px 14px',
|
|
215
|
-
cursor: 'pointer'
|
|
216
|
-
},
|
|
217
|
-
children: "DevTools"
|
|
218
|
-
}),
|
|
219
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(DevTools, {
|
|
220
|
-
appInstance: appInstance,
|
|
221
|
-
visible: visible,
|
|
222
|
-
onClose: ()=>setVisible(false)
|
|
223
|
-
})
|
|
224
|
-
]
|
|
225
|
-
});
|
|
226
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get DevTools(){return DevTools},get DevToolsTrigger(){return DevToolsTrigger}});const _jsxruntime=require("react/jsx-runtime");const _react=require("react");const _app=require("../app");function toPrettyJson(value){try{return JSON.stringify(value,null,2)}catch{return String(value)}}function DevTools({appInstance,visible,onClose}){const[performanceMetrics,setPerformanceMetrics]=(0,_react.useState)({});const stateManager=(0,_app.useStateManager)();(0,_react.useEffect)(()=>{if(!visible){return}const tracker=appInstance.getPerformanceTracker();if(!tracker){return}const metrics=tracker.getMetrics();setPerformanceMetrics({serviceInitDuration:metrics.serviceInitDuration||0,initializationDuration:metrics.initializationDuration||0,firstRenderDuration:metrics.firstRenderDuration||0,totalStartupDuration:metrics.totalStartupDuration||0,fcp:metrics.fcp||0,lcp:metrics.lcp||0,fid:metrics.fid||0,cls:metrics.cls||0})},[visible,appInstance]);if(!visible){return null}const options=appInstance.getOptions();const allStates=stateManager?.getAllStates?.()||[];return(0,_jsxruntime.jsxs)("div",{style:{position:"fixed",top:0,right:0,width:"min(680px, 95vw)",height:"100vh",zIndex:9999,background:"#fff",borderLeft:"1px solid #d9e2ec",padding:16,overflowY:"auto",boxShadow:"-8px 0 20px rgba(0, 0, 0, 0.08)"},children:[(0,_jsxruntime.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,_jsxruntime.jsx)("h3",{style:{margin:0},children:"DevTools"}),(0,_jsxruntime.jsx)("button",{onClick:onClose,style:{border:"none",background:"transparent",cursor:"pointer"},children:"关闭"})]}),(0,_jsxruntime.jsxs)("section",{style:{marginTop:12},children:[(0,_jsxruntime.jsx)("h4",{children:"实例"}),(0,_jsxruntime.jsxs)("div",{children:["id: ",appInstance.id]}),(0,_jsxruntime.jsxs)("div",{children:["initialized: ",String(appInstance.isInitialized())]})]}),(0,_jsxruntime.jsxs)("section",{style:{marginTop:12},children:[(0,_jsxruntime.jsx)("h4",{children:"性能"}),(0,_jsxruntime.jsx)("pre",{style:{background:"#f7fafc",padding:10,borderRadius:8},children:toPrettyJson(performanceMetrics)})]}),(0,_jsxruntime.jsxs)("section",{style:{marginTop:12},children:[(0,_jsxruntime.jsx)("h4",{children:"状态管理"}),(0,_jsxruntime.jsxs)("div",{children:["stateCount: ",allStates.length]}),(0,_jsxruntime.jsx)("pre",{style:{background:"#f7fafc",padding:10,borderRadius:8},children:toPrettyJson(allStates.slice(0,10))})]}),(0,_jsxruntime.jsxs)("section",{style:{marginTop:12},children:[(0,_jsxruntime.jsx)("h4",{children:"配置"}),(0,_jsxruntime.jsx)("pre",{style:{background:"#f7fafc",padding:10,borderRadius:8,whiteSpace:"pre-wrap"},children:toPrettyJson(options)})]})]})}function resolvePosition(position){const style={position:"fixed",zIndex:9998};const pos=position||"bottom-right";if(pos.includes("bottom"))style.bottom=16;if(pos.includes("top"))style.top=16;if(pos.includes("right"))style.right=16;if(pos.includes("left"))style.left=16;return style}function DevToolsTrigger({appInstance,position="bottom-right"}){const[visible,setVisible]=(0,_react.useState)(false);if(process.env.NODE_ENV!=="development"){return null}return(0,_jsxruntime.jsxs)(_jsxruntime.Fragment,{children:[(0,_jsxruntime.jsx)("button",{onClick:()=>setVisible(true),style:{...resolvePosition(position),border:"none",background:"#2f80ed",color:"#fff",borderRadius:999,padding:"8px 14px",cursor:"pointer"},children:"DevTools"}),(0,_jsxruntime.jsx)(DevTools,{appInstance:appInstance,visible:visible,onClose:()=>setVisible(false)})]})}
|
|
@@ -1,401 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get ErrorBoundary () {
|
|
13
|
-
return ErrorBoundary;
|
|
14
|
-
},
|
|
15
|
-
get useErrorHandler () {
|
|
16
|
-
return useErrorHandler;
|
|
17
|
-
},
|
|
18
|
-
get withErrorBoundary () {
|
|
19
|
-
return withErrorBoundary;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
23
|
-
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
24
|
-
const _reacterrorboundary = require("react-error-boundary");
|
|
25
|
-
const _logger = require("@vlian/logger");
|
|
26
|
-
const _utils = require("@vlian/utils");
|
|
27
|
-
const _initialization = require("../initialization");
|
|
28
|
-
const _ErrorHandler = require("./ErrorHandler");
|
|
29
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
30
|
-
if (typeof WeakMap !== "function") return null;
|
|
31
|
-
var cacheBabelInterop = new WeakMap();
|
|
32
|
-
var cacheNodeInterop = new WeakMap();
|
|
33
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
34
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
35
|
-
})(nodeInterop);
|
|
36
|
-
}
|
|
37
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
38
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
39
|
-
return obj;
|
|
40
|
-
}
|
|
41
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
42
|
-
return {
|
|
43
|
-
default: obj
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
47
|
-
if (cache && cache.has(obj)) {
|
|
48
|
-
return cache.get(obj);
|
|
49
|
-
}
|
|
50
|
-
var newObj = {
|
|
51
|
-
__proto__: null
|
|
52
|
-
};
|
|
53
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
54
|
-
for(var key in obj){
|
|
55
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
56
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
57
|
-
if (desc && (desc.get || desc.set)) {
|
|
58
|
-
Object.defineProperty(newObj, key, desc);
|
|
59
|
-
} else {
|
|
60
|
-
newObj[key] = obj[key];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
newObj.default = obj;
|
|
65
|
-
if (cache) {
|
|
66
|
-
cache.set(obj, newObj);
|
|
67
|
-
}
|
|
68
|
-
return newObj;
|
|
69
|
-
}
|
|
70
|
-
function ErrorBoundary({ children, fallback, onError, showInConsole = true, resetKeys, onReset, onResetKeysChange }) {
|
|
71
|
-
// 使用 ref 存储重试计数,在多次错误之间保持状态
|
|
72
|
-
const retryCountRef = (0, _react.useRef)(0);
|
|
73
|
-
// 优化:使用统一的错误处理器
|
|
74
|
-
const errorHandler = (0, _react.useMemo)(()=>(0, _ErrorHandler.getDefaultErrorHandler)(), []);
|
|
75
|
-
// 处理错误,将标准 Error 转换为 FrameworkError
|
|
76
|
-
const handleError = (0, _react.useCallback)(async (error, errorInfo)=>{
|
|
77
|
-
const normalizedError = _utils.errorUtils.normalizeError(error);
|
|
78
|
-
// 将 react-error-boundary 的 errorInfo 转换为 React 的 ErrorInfo 格式
|
|
79
|
-
const reactErrorInfo = {
|
|
80
|
-
componentStack: errorInfo.componentStack || ''
|
|
81
|
-
};
|
|
82
|
-
// 使用统一的错误处理器处理错误
|
|
83
|
-
const handleResult = await errorHandler.handleError(normalizedError, {
|
|
84
|
-
componentStack: reactErrorInfo.componentStack,
|
|
85
|
-
source: 'ErrorBoundary'
|
|
86
|
-
});
|
|
87
|
-
// 如果错误处理器没有处理错误,使用默认处理
|
|
88
|
-
if (!handleResult.handled) {
|
|
89
|
-
_logger.logger.error('错误边界捕获到错误:', {
|
|
90
|
-
error: normalizedError.toJSON(),
|
|
91
|
-
errorInfo: {
|
|
92
|
-
componentStack: reactErrorInfo.componentStack
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
// 调用错误回调
|
|
97
|
-
if (onError) {
|
|
98
|
-
onError(normalizedError, reactErrorInfo);
|
|
99
|
-
}
|
|
100
|
-
// 在控制台显示错误(如果配置了)
|
|
101
|
-
if (showInConsole) {
|
|
102
|
-
console.error('错误边界捕获到错误:', normalizedError);
|
|
103
|
-
console.error('错误信息:', reactErrorInfo);
|
|
104
|
-
}
|
|
105
|
-
}, [
|
|
106
|
-
errorHandler,
|
|
107
|
-
onError,
|
|
108
|
-
showInConsole
|
|
109
|
-
]);
|
|
110
|
-
// 处理重置
|
|
111
|
-
const handleReset = ()=>{
|
|
112
|
-
// 清除初始化错误状态
|
|
113
|
-
_initialization.initializationErrorState.clearError();
|
|
114
|
-
// 调用用户提供的重置回调
|
|
115
|
-
if (onReset) {
|
|
116
|
-
onReset();
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
// 默认 fallback UI(使用无框架 HTML 组件)
|
|
120
|
-
// 使用内部组件来管理重试计数状态,使用 React.memo 优化性能
|
|
121
|
-
const DefaultFallbackComponent = /*#__PURE__*/ _react.default.memo(({ error, resetErrorBoundary })=>{
|
|
122
|
-
const normalizedError = _utils.errorUtils.normalizeError(error);
|
|
123
|
-
const [retryCount, setRetryCount] = (0, _react.useState)(retryCountRef.current);
|
|
124
|
-
const [showDetails, setShowDetails] = (0, _react.useState)(false);
|
|
125
|
-
// 同步 ref 的值到 state,确保组件重新创建时能读取到最新的重试计数
|
|
126
|
-
(0, _react.useEffect)(()=>{
|
|
127
|
-
setRetryCount(retryCountRef.current);
|
|
128
|
-
}, []);
|
|
129
|
-
const handleRetry = (0, _react.useCallback)(()=>{
|
|
130
|
-
// 增加重试计数
|
|
131
|
-
const newCount = retryCount + 1;
|
|
132
|
-
retryCountRef.current = newCount;
|
|
133
|
-
setRetryCount(newCount);
|
|
134
|
-
// 执行重置
|
|
135
|
-
handleReset();
|
|
136
|
-
resetErrorBoundary();
|
|
137
|
-
}, [
|
|
138
|
-
retryCount,
|
|
139
|
-
resetErrorBoundary
|
|
140
|
-
]);
|
|
141
|
-
const handleReload = (0, _react.useCallback)(()=>{
|
|
142
|
-
// 刷新页面
|
|
143
|
-
window.location.reload();
|
|
144
|
-
}, []);
|
|
145
|
-
// 构建用户友好的错误提示
|
|
146
|
-
const userFriendlyMessage = (0, _react.useMemo)(()=>{
|
|
147
|
-
// 根据错误类型提供不同的提示
|
|
148
|
-
if (normalizedError.code === 'NETWORK_ERROR') {
|
|
149
|
-
return '网络连接失败,请检查您的网络设置后再尝试';
|
|
150
|
-
}
|
|
151
|
-
if (normalizedError.code === 'TIMEOUT_ERROR') {
|
|
152
|
-
return '请求超时,请稍后再尝试';
|
|
153
|
-
}
|
|
154
|
-
if (normalizedError.code === 'VALIDATION_ERROR') {
|
|
155
|
-
return '数据验证失败,请检查输入内容';
|
|
156
|
-
}
|
|
157
|
-
// 默认提示
|
|
158
|
-
return '应用运行时发生了错误,请稍后再尝试';
|
|
159
|
-
}, [
|
|
160
|
-
normalizedError.code
|
|
161
|
-
]);
|
|
162
|
-
// 构建按钮数组
|
|
163
|
-
const extraButtons = (0, _react.useMemo)(()=>{
|
|
164
|
-
const buttons = [
|
|
165
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
166
|
-
onClick: handleRetry,
|
|
167
|
-
"aria-label": "重试加载应用",
|
|
168
|
-
style: {
|
|
169
|
-
border: 'none',
|
|
170
|
-
background: 'var(--app-primary-color, #2f80ed)',
|
|
171
|
-
color: '#fff',
|
|
172
|
-
borderRadius: 6,
|
|
173
|
-
padding: '8px 14px',
|
|
174
|
-
cursor: 'pointer'
|
|
175
|
-
},
|
|
176
|
-
children: "重试"
|
|
177
|
-
}, "retry"),
|
|
178
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
179
|
-
onClick: ()=>setShowDetails(!showDetails),
|
|
180
|
-
"aria-label": showDetails ? '隐藏错误详情' : '显示错误详情',
|
|
181
|
-
style: {
|
|
182
|
-
border: '1px solid #cfd7df',
|
|
183
|
-
background: '#fff',
|
|
184
|
-
color: '#1f2933',
|
|
185
|
-
borderRadius: 6,
|
|
186
|
-
padding: '8px 14px',
|
|
187
|
-
cursor: 'pointer'
|
|
188
|
-
},
|
|
189
|
-
children: showDetails ? '隐藏详情' : '查看详情'
|
|
190
|
-
}, "details")
|
|
191
|
-
];
|
|
192
|
-
// 如果重试次数 >= 1,添加刷新页面按钮(提前显示)
|
|
193
|
-
if (retryCount >= 1) {
|
|
194
|
-
buttons.push(/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
195
|
-
onClick: handleReload,
|
|
196
|
-
"aria-label": "刷新页面",
|
|
197
|
-
style: {
|
|
198
|
-
border: '1px solid #cfd7df',
|
|
199
|
-
background: '#fff',
|
|
200
|
-
color: '#1f2933',
|
|
201
|
-
borderRadius: 6,
|
|
202
|
-
padding: '8px 14px',
|
|
203
|
-
cursor: 'pointer'
|
|
204
|
-
},
|
|
205
|
-
children: "刷新页面"
|
|
206
|
-
}, "reload"));
|
|
207
|
-
}
|
|
208
|
-
return buttons;
|
|
209
|
-
}, [
|
|
210
|
-
retryCount,
|
|
211
|
-
handleRetry,
|
|
212
|
-
handleReload,
|
|
213
|
-
showDetails
|
|
214
|
-
]);
|
|
215
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
216
|
-
role: "alert",
|
|
217
|
-
"aria-live": "assertive",
|
|
218
|
-
"aria-atomic": "true",
|
|
219
|
-
style: {
|
|
220
|
-
display: 'flex',
|
|
221
|
-
flexDirection: 'column',
|
|
222
|
-
alignItems: 'center',
|
|
223
|
-
justifyContent: 'center',
|
|
224
|
-
minHeight: '100vh',
|
|
225
|
-
padding: '24px'
|
|
226
|
-
},
|
|
227
|
-
children: [
|
|
228
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
229
|
-
style: {
|
|
230
|
-
maxWidth: 580,
|
|
231
|
-
width: '100%',
|
|
232
|
-
textAlign: 'center',
|
|
233
|
-
border: '1px solid #dde5ec',
|
|
234
|
-
borderRadius: 10,
|
|
235
|
-
padding: 24,
|
|
236
|
-
background: '#fff'
|
|
237
|
-
},
|
|
238
|
-
children: [
|
|
239
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
240
|
-
style: {
|
|
241
|
-
fontSize: 40,
|
|
242
|
-
lineHeight: '44px'
|
|
243
|
-
},
|
|
244
|
-
children: "⚠️"
|
|
245
|
-
}),
|
|
246
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h2", {
|
|
247
|
-
style: {
|
|
248
|
-
margin: '8px 0 4px'
|
|
249
|
-
},
|
|
250
|
-
children: "出错了"
|
|
251
|
-
}),
|
|
252
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("p", {
|
|
253
|
-
style: {
|
|
254
|
-
marginTop: 0,
|
|
255
|
-
color: '#52606d'
|
|
256
|
-
},
|
|
257
|
-
children: userFriendlyMessage
|
|
258
|
-
}),
|
|
259
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
260
|
-
style: {
|
|
261
|
-
display: 'flex',
|
|
262
|
-
gap: 8,
|
|
263
|
-
justifyContent: 'center',
|
|
264
|
-
flexWrap: 'wrap'
|
|
265
|
-
},
|
|
266
|
-
children: extraButtons
|
|
267
|
-
})
|
|
268
|
-
]
|
|
269
|
-
}),
|
|
270
|
-
showDetails && /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
271
|
-
style: {
|
|
272
|
-
marginTop: 24,
|
|
273
|
-
padding: 16,
|
|
274
|
-
backgroundColor: '#f5f5f5',
|
|
275
|
-
borderRadius: 4,
|
|
276
|
-
maxWidth: 800,
|
|
277
|
-
width: '100%',
|
|
278
|
-
maxHeight: 400,
|
|
279
|
-
overflow: 'auto'
|
|
280
|
-
},
|
|
281
|
-
children: [
|
|
282
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
283
|
-
style: {
|
|
284
|
-
marginBottom: 8,
|
|
285
|
-
fontWeight: 'bold'
|
|
286
|
-
},
|
|
287
|
-
children: "错误详情:"
|
|
288
|
-
}),
|
|
289
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
290
|
-
style: {
|
|
291
|
-
fontFamily: 'monospace',
|
|
292
|
-
fontSize: 12
|
|
293
|
-
},
|
|
294
|
-
children: [
|
|
295
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
296
|
-
children: [
|
|
297
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
298
|
-
children: "错误类型:"
|
|
299
|
-
}),
|
|
300
|
-
normalizedError.name
|
|
301
|
-
]
|
|
302
|
-
}),
|
|
303
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
304
|
-
children: [
|
|
305
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
306
|
-
children: "错误代码:"
|
|
307
|
-
}),
|
|
308
|
-
normalizedError.code
|
|
309
|
-
]
|
|
310
|
-
}),
|
|
311
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
312
|
-
children: [
|
|
313
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
314
|
-
children: "错误信息:"
|
|
315
|
-
}),
|
|
316
|
-
normalizedError.message
|
|
317
|
-
]
|
|
318
|
-
}),
|
|
319
|
-
normalizedError.stack && /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
320
|
-
style: {
|
|
321
|
-
marginTop: 8
|
|
322
|
-
},
|
|
323
|
-
children: [
|
|
324
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
325
|
-
children: "堆栈信息:"
|
|
326
|
-
}),
|
|
327
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("pre", {
|
|
328
|
-
style: {
|
|
329
|
-
whiteSpace: 'pre-wrap',
|
|
330
|
-
wordBreak: 'break-word'
|
|
331
|
-
},
|
|
332
|
-
children: normalizedError.stack
|
|
333
|
-
})
|
|
334
|
-
]
|
|
335
|
-
})
|
|
336
|
-
]
|
|
337
|
-
})
|
|
338
|
-
]
|
|
339
|
-
})
|
|
340
|
-
]
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
DefaultFallbackComponent.displayName = 'DefaultFallbackComponent';
|
|
344
|
-
const defaultFallback = ({ error, resetErrorBoundary })=>{
|
|
345
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(DefaultFallbackComponent, {
|
|
346
|
-
error: error,
|
|
347
|
-
resetErrorBoundary: resetErrorBoundary
|
|
348
|
-
});
|
|
349
|
-
};
|
|
350
|
-
// 如果提供了自定义 fallback,使用自定义的
|
|
351
|
-
const fallbackRender = fallback ? ({ error, resetErrorBoundary })=>{
|
|
352
|
-
const normalizedError = _utils.errorUtils.normalizeError(error);
|
|
353
|
-
return fallback(normalizedError, ()=>{
|
|
354
|
-
handleReset();
|
|
355
|
-
resetErrorBoundary();
|
|
356
|
-
});
|
|
357
|
-
} : defaultFallback;
|
|
358
|
-
// 处理重置时清除重试计数
|
|
359
|
-
const handleResetWithCount = ()=>{
|
|
360
|
-
retryCountRef.current = 0;
|
|
361
|
-
handleReset();
|
|
362
|
-
};
|
|
363
|
-
// 处理 resetKeys 变化时清除重试计数
|
|
364
|
-
const handleResetKeysChange = (prevKeys, nextKeys)=>{
|
|
365
|
-
retryCountRef.current = 0;
|
|
366
|
-
if (onResetKeysChange) {
|
|
367
|
-
onResetKeysChange(prevKeys, nextKeys);
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
// 构建 react-error-boundary 的 props
|
|
371
|
-
const errorBoundaryProps = {
|
|
372
|
-
fallbackRender,
|
|
373
|
-
onError: handleError,
|
|
374
|
-
onReset: handleResetWithCount,
|
|
375
|
-
resetKeys,
|
|
376
|
-
onResetKeysChange: handleResetKeysChange
|
|
377
|
-
};
|
|
378
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacterrorboundary.ErrorBoundary, {
|
|
379
|
-
...errorBoundaryProps,
|
|
380
|
-
children: children
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
384
|
-
const WrappedComponent = (props)=>{
|
|
385
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(ErrorBoundary, {
|
|
386
|
-
...errorBoundaryProps,
|
|
387
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Component, {
|
|
388
|
-
...props
|
|
389
|
-
})
|
|
390
|
-
});
|
|
391
|
-
};
|
|
392
|
-
WrappedComponent.displayName = `withErrorBoundary(${Component.displayName || Component.name || 'Component'})`;
|
|
393
|
-
return WrappedComponent;
|
|
394
|
-
}
|
|
395
|
-
function useErrorHandler() {
|
|
396
|
-
return (error)=>{
|
|
397
|
-
// 将错误设置到初始化错误状态
|
|
398
|
-
// InitializationErrorThrower 组件会检测到错误并抛出,让 ErrorBoundary 捕获
|
|
399
|
-
_initialization.initializationErrorState.setError(error);
|
|
400
|
-
};
|
|
401
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get ErrorBoundary(){return ErrorBoundary},get useErrorHandler(){return useErrorHandler},get withErrorBoundary(){return withErrorBoundary}});const _jsxruntime=require("react/jsx-runtime");const _react=/*#__PURE__*/_interop_require_wildcard(require("react"));const _reacterrorboundary=require("react-error-boundary");const _logger=require("@vlian/logger");const _utils=require("@vlian/utils");const _initialization=require("../initialization");const _ErrorHandler=require("./ErrorHandler");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interop_require_wildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={__proto__:null};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}function ErrorBoundary({children,fallback,onError,showInConsole=true,resetKeys,onReset,onResetKeysChange}){const retryCountRef=(0,_react.useRef)(0);const errorHandler=(0,_react.useMemo)(()=>(0,_ErrorHandler.getDefaultErrorHandler)(),[]);const handleError=(0,_react.useCallback)(async(error,errorInfo)=>{const normalizedError=_utils.errorUtils.normalizeError(error);const reactErrorInfo={componentStack:errorInfo.componentStack||""};const handleResult=await errorHandler.handleError(normalizedError,{componentStack:reactErrorInfo.componentStack,source:"ErrorBoundary"});if(!handleResult.handled){_logger.logger.error("错误边界捕获到错误:",{error:normalizedError.toJSON(),errorInfo:{componentStack:reactErrorInfo.componentStack}})}if(onError){onError(normalizedError,reactErrorInfo)}if(showInConsole){console.error("错误边界捕获到错误:",normalizedError);console.error("错误信息:",reactErrorInfo)}},[errorHandler,onError,showInConsole]);const handleReset=()=>{_initialization.initializationErrorState.clearError();if(onReset){onReset()}};const DefaultFallbackComponent=_react.default.memo(({error,resetErrorBoundary})=>{const normalizedError=_utils.errorUtils.normalizeError(error);const[retryCount,setRetryCount]=(0,_react.useState)(retryCountRef.current);const[showDetails,setShowDetails]=(0,_react.useState)(false);(0,_react.useEffect)(()=>{setRetryCount(retryCountRef.current)},[]);const handleRetry=(0,_react.useCallback)(()=>{const newCount=retryCount+1;retryCountRef.current=newCount;setRetryCount(newCount);handleReset();resetErrorBoundary()},[retryCount,resetErrorBoundary]);const handleReload=(0,_react.useCallback)(()=>{window.location.reload()},[]);const userFriendlyMessage=(0,_react.useMemo)(()=>{if(normalizedError.code==="NETWORK_ERROR"){return"网络连接失败,请检查您的网络设置后再尝试"}if(normalizedError.code==="TIMEOUT_ERROR"){return"请求超时,请稍后再尝试"}if(normalizedError.code==="VALIDATION_ERROR"){return"数据验证失败,请检查输入内容"}return"应用运行时发生了错误,请稍后再尝试"},[normalizedError.code]);const extraButtons=(0,_react.useMemo)(()=>{const buttons=[(0,_jsxruntime.jsx)("button",{onClick:handleRetry,"aria-label":"重试加载应用",style:{border:"none",background:"var(--app-primary-color, #2f80ed)",color:"#fff",borderRadius:6,padding:"8px 14px",cursor:"pointer"},children:"重试"},"retry"),(0,_jsxruntime.jsx)("button",{onClick:()=>setShowDetails(!showDetails),"aria-label":showDetails?"隐藏错误详情":"显示错误详情",style:{border:"1px solid #cfd7df",background:"#fff",color:"#1f2933",borderRadius:6,padding:"8px 14px",cursor:"pointer"},children:showDetails?"隐藏详情":"查看详情"},"details")];if(retryCount>=1){buttons.push((0,_jsxruntime.jsx)("button",{onClick:handleReload,"aria-label":"刷新页面",style:{border:"1px solid #cfd7df",background:"#fff",color:"#1f2933",borderRadius:6,padding:"8px 14px",cursor:"pointer"},children:"刷新页面"},"reload"))}return buttons},[retryCount,handleRetry,handleReload,showDetails]);return(0,_jsxruntime.jsxs)("div",{role:"alert","aria-live":"assertive","aria-atomic":"true",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",padding:"24px"},children:[(0,_jsxruntime.jsxs)("div",{style:{maxWidth:580,width:"100%",textAlign:"center",border:"1px solid #dde5ec",borderRadius:10,padding:24,background:"#fff"},children:[(0,_jsxruntime.jsx)("div",{style:{fontSize:40,lineHeight:"44px"},children:"⚠️"}),(0,_jsxruntime.jsx)("h2",{style:{margin:"8px 0 4px"},children:"出错了"}),(0,_jsxruntime.jsx)("p",{style:{marginTop:0,color:"#52606d"},children:userFriendlyMessage}),(0,_jsxruntime.jsx)("div",{style:{display:"flex",gap:8,justifyContent:"center",flexWrap:"wrap"},children:extraButtons})]}),showDetails&&(0,_jsxruntime.jsxs)("div",{style:{marginTop:24,padding:16,backgroundColor:"#f5f5f5",borderRadius:4,maxWidth:800,width:"100%",maxHeight:400,overflow:"auto"},children:[(0,_jsxruntime.jsx)("div",{style:{marginBottom:8,fontWeight:"bold"},children:"错误详情:"}),(0,_jsxruntime.jsxs)("div",{style:{fontFamily:"monospace",fontSize:12},children:[(0,_jsxruntime.jsxs)("div",{children:[(0,_jsxruntime.jsx)("strong",{children:"错误类型:"}),normalizedError.name]}),(0,_jsxruntime.jsxs)("div",{children:[(0,_jsxruntime.jsx)("strong",{children:"错误代码:"}),normalizedError.code]}),(0,_jsxruntime.jsxs)("div",{children:[(0,_jsxruntime.jsx)("strong",{children:"错误信息:"}),normalizedError.message]}),normalizedError.stack&&(0,_jsxruntime.jsxs)("div",{style:{marginTop:8},children:[(0,_jsxruntime.jsx)("strong",{children:"堆栈信息:"}),(0,_jsxruntime.jsx)("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:normalizedError.stack})]})]})]})]})});DefaultFallbackComponent.displayName="DefaultFallbackComponent";const defaultFallback=({error,resetErrorBoundary})=>{return(0,_jsxruntime.jsx)(DefaultFallbackComponent,{error:error,resetErrorBoundary:resetErrorBoundary})};const fallbackRender=fallback?({error,resetErrorBoundary})=>{const normalizedError=_utils.errorUtils.normalizeError(error);return fallback(normalizedError,()=>{handleReset();resetErrorBoundary()})}:defaultFallback;const handleResetWithCount=()=>{retryCountRef.current=0;handleReset()};const handleResetKeysChange=(prevKeys,nextKeys)=>{retryCountRef.current=0;if(onResetKeysChange){onResetKeysChange(prevKeys,nextKeys)}};const errorBoundaryProps={fallbackRender,onError:handleError,onReset:handleResetWithCount,resetKeys,onResetKeysChange:handleResetKeysChange};return(0,_jsxruntime.jsx)(_reacterrorboundary.ErrorBoundary,{...errorBoundaryProps,children:children})}function withErrorBoundary(Component,errorBoundaryProps){const WrappedComponent=props=>{return(0,_jsxruntime.jsx)(ErrorBoundary,{...errorBoundaryProps,children:(0,_jsxruntime.jsx)(Component,{...props})})};WrappedComponent.displayName=`withErrorBoundary(${Component.displayName||Component.name||"Component"})`;return WrappedComponent}function useErrorHandler(){return error=>{_initialization.initializationErrorState.setError(error)}}
|