@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,262 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 路由插件管理器
|
|
3
|
-
* 负责插件的注册、执行和生命周期管理
|
|
4
|
-
*/ "use strict";
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
function _export(target, all) {
|
|
9
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
_export(exports, {
|
|
15
|
-
get RouterPluginManager () {
|
|
16
|
-
return RouterPluginManager;
|
|
17
|
-
},
|
|
18
|
-
get getRouterPluginManager () {
|
|
19
|
-
return getRouterPluginManager;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _logger = require("@vlian/logger");
|
|
23
|
-
const _types = require("./types");
|
|
24
|
-
function _define_property(obj, key, value) {
|
|
25
|
-
if (key in obj) {
|
|
26
|
-
Object.defineProperty(obj, key, {
|
|
27
|
-
value: value,
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
obj[key] = value;
|
|
34
|
-
}
|
|
35
|
-
return obj;
|
|
36
|
-
}
|
|
37
|
-
let RouterPluginManager = class RouterPluginManager {
|
|
38
|
-
/**
|
|
39
|
-
* 注册插件
|
|
40
|
-
*
|
|
41
|
-
* @param plugin - 插件实例
|
|
42
|
-
* @param options - 注册选项
|
|
43
|
-
* @returns 取消注册函数
|
|
44
|
-
*/ register(plugin, options = {}) {
|
|
45
|
-
// 验证插件
|
|
46
|
-
if (!plugin.name) {
|
|
47
|
-
throw new Error('插件必须提供名称');
|
|
48
|
-
}
|
|
49
|
-
// 检查是否已存在
|
|
50
|
-
if (this.plugins.has(plugin.name) && !options.overwrite) {
|
|
51
|
-
throw new Error(`插件 "${plugin.name}" 已存在`);
|
|
52
|
-
}
|
|
53
|
-
// 设置默认值
|
|
54
|
-
const pluginWithDefaults = {
|
|
55
|
-
priority: 100,
|
|
56
|
-
enabled: true,
|
|
57
|
-
...plugin
|
|
58
|
-
};
|
|
59
|
-
// 检查依赖
|
|
60
|
-
if (pluginWithDefaults.dependencies) {
|
|
61
|
-
const missingDeps = pluginWithDefaults.dependencies.filter((dep)=>!this.plugins.has(dep));
|
|
62
|
-
if (missingDeps.length > 0) {
|
|
63
|
-
throw new Error(`插件 "${plugin.name}" 缺少依赖: ${missingDeps.join(', ')}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// 注册插件
|
|
67
|
-
this.plugins.set(plugin.name, {
|
|
68
|
-
plugin: pluginWithDefaults,
|
|
69
|
-
status: 'registered',
|
|
70
|
-
registeredAt: Date.now()
|
|
71
|
-
});
|
|
72
|
-
_logger.logger.debug(`路由插件已注册: ${plugin.name}`);
|
|
73
|
-
// 调用注册钩子
|
|
74
|
-
if (pluginWithDefaults.hooks?.onRegister) {
|
|
75
|
-
try {
|
|
76
|
-
const context = {
|
|
77
|
-
config: {},
|
|
78
|
-
meta: {
|
|
79
|
-
stage: _types.PluginLifecycleStage.REGISTER
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
pluginWithDefaults.hooks.onRegister(context);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
_logger.logger.error(`插件注册钩子执行失败: ${plugin.name}`, error);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// 返回取消注册函数
|
|
88
|
-
return ()=>{
|
|
89
|
-
this.unregister(plugin.name);
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* 批量注册插件
|
|
94
|
-
*
|
|
95
|
-
* @param plugins - 插件数组
|
|
96
|
-
* @param options - 注册选项
|
|
97
|
-
*/ registerBatch(plugins, options = {}) {
|
|
98
|
-
// 按依赖关系排序
|
|
99
|
-
const sortedPlugins = this.sortByDependencies(plugins);
|
|
100
|
-
sortedPlugins.forEach((plugin)=>{
|
|
101
|
-
this.register(plugin, options);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* 按依赖关系排序插件(拓扑排序)
|
|
106
|
-
*/ sortByDependencies(plugins) {
|
|
107
|
-
const sorted = [];
|
|
108
|
-
const visited = new Set();
|
|
109
|
-
const visiting = new Set();
|
|
110
|
-
const visit = (plugin)=>{
|
|
111
|
-
if (visiting.has(plugin.name || '')) {
|
|
112
|
-
throw new Error(`检测到循环依赖: ${plugin.name}`);
|
|
113
|
-
}
|
|
114
|
-
if (visited.has(plugin.name || '')) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
visiting.add(plugin.name || '');
|
|
118
|
-
// 先访问依赖
|
|
119
|
-
if (plugin.dependencies) {
|
|
120
|
-
plugin.dependencies.forEach((depName)=>{
|
|
121
|
-
const dep = plugins.find((p)=>p.name === depName);
|
|
122
|
-
if (dep) {
|
|
123
|
-
visit(dep);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
visiting.delete(plugin.name || '');
|
|
128
|
-
visited.add(plugin.name || '');
|
|
129
|
-
sorted.push(plugin);
|
|
130
|
-
};
|
|
131
|
-
plugins.forEach((plugin)=>{
|
|
132
|
-
if (!visited.has(plugin.name || '')) {
|
|
133
|
-
visit(plugin);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return sorted;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* 取消注册插件
|
|
140
|
-
*
|
|
141
|
-
* @param name - 插件名称
|
|
142
|
-
*/ unregister(name) {
|
|
143
|
-
const registration = this.plugins.get(name);
|
|
144
|
-
if (!registration) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
// 调用销毁钩子
|
|
148
|
-
if (registration.plugin.hooks?.onDestroy) {
|
|
149
|
-
try {
|
|
150
|
-
const context = {
|
|
151
|
-
config: {},
|
|
152
|
-
meta: {
|
|
153
|
-
stage: _types.PluginLifecycleStage.DESTROY
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
registration.plugin.hooks.onDestroy(context);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
_logger.logger.error(`插件销毁钩子执行失败: ${name}`, error);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
this.plugins.delete(name);
|
|
162
|
-
_logger.logger.debug(`路由插件已取消注册: ${name}`);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* 执行插件钩子
|
|
166
|
-
*
|
|
167
|
-
* @param stage - 生命周期阶段
|
|
168
|
-
* @param context - 插件上下文
|
|
169
|
-
*/ async executeHooks(stage, context) {
|
|
170
|
-
// 获取启用的插件并按优先级排序
|
|
171
|
-
const enabledPlugins = Array.from(this.plugins.values()).filter((reg)=>reg.plugin.enabled !== false).sort((a, b)=>(a.plugin.priority || 100) - (b.plugin.priority || 100));
|
|
172
|
-
// 根据阶段选择钩子
|
|
173
|
-
const hookMap = {
|
|
174
|
-
[_types.PluginLifecycleStage.REGISTER]: 'onRegister',
|
|
175
|
-
[_types.PluginLifecycleStage.BEFORE_INIT]: 'onBeforeInit',
|
|
176
|
-
[_types.PluginLifecycleStage.AFTER_INIT]: 'onAfterInit',
|
|
177
|
-
[_types.PluginLifecycleStage.BEFORE_TRANSFORM]: 'onBeforeTransform',
|
|
178
|
-
[_types.PluginLifecycleStage.AFTER_TRANSFORM]: 'onAfterTransform',
|
|
179
|
-
[_types.PluginLifecycleStage.BEFORE_MATCH]: 'onBeforeMatch',
|
|
180
|
-
[_types.PluginLifecycleStage.AFTER_MATCH]: 'onAfterMatch',
|
|
181
|
-
[_types.PluginLifecycleStage.DESTROY]: 'onDestroy'
|
|
182
|
-
};
|
|
183
|
-
const hookName = hookMap[stage];
|
|
184
|
-
if (!hookName) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
// 执行钩子
|
|
188
|
-
for (const registration of enabledPlugins){
|
|
189
|
-
const hook = registration.plugin.hooks?.[hookName];
|
|
190
|
-
if (hook) {
|
|
191
|
-
try {
|
|
192
|
-
await hook(context);
|
|
193
|
-
} catch (error) {
|
|
194
|
-
_logger.logger.error(`插件钩子执行失败: ${registration.plugin.name}.${hookName}`, error);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* 获取插件
|
|
201
|
-
*
|
|
202
|
-
* @param name - 插件名称
|
|
203
|
-
* @returns 插件实例,如果不存在返回 undefined
|
|
204
|
-
*/ getPlugin(name) {
|
|
205
|
-
return this.plugins.get(name)?.plugin;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* 获取所有插件
|
|
209
|
-
*
|
|
210
|
-
* @returns 插件数组
|
|
211
|
-
*/ getAllPlugins() {
|
|
212
|
-
return Array.from(this.plugins.values()).map((reg)=>reg.plugin);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* 获取启用的插件
|
|
216
|
-
*
|
|
217
|
-
* @returns 启用的插件数组
|
|
218
|
-
*/ getEnabledPlugins() {
|
|
219
|
-
return Array.from(this.plugins.values()).filter((reg)=>reg.plugin.enabled !== false).map((reg)=>reg.plugin);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* 清空所有插件
|
|
223
|
-
*/ clear() {
|
|
224
|
-
// 调用所有插件的销毁钩子
|
|
225
|
-
for (const [name, registration] of this.plugins.entries()){
|
|
226
|
-
if (registration.plugin.hooks?.onDestroy) {
|
|
227
|
-
try {
|
|
228
|
-
const context = {
|
|
229
|
-
config: {},
|
|
230
|
-
meta: {
|
|
231
|
-
stage: _types.PluginLifecycleStage.DESTROY
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
registration.plugin.hooks.onDestroy(context);
|
|
235
|
-
} catch (error) {
|
|
236
|
-
_logger.logger.error(`插件销毁钩子执行失败: ${name}`, error);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
this.plugins.clear();
|
|
241
|
-
_logger.logger.debug('所有路由插件已清空');
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* 获取插件数量
|
|
245
|
-
*
|
|
246
|
-
* @returns 插件数量
|
|
247
|
-
*/ getCount() {
|
|
248
|
-
return this.plugins.size;
|
|
249
|
-
}
|
|
250
|
-
constructor(){
|
|
251
|
-
_define_property(this, "plugins", new Map());
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
/**
|
|
255
|
-
* 获取路由插件管理器单例
|
|
256
|
-
*/ let pluginManagerInstance = null;
|
|
257
|
-
function getRouterPluginManager() {
|
|
258
|
-
if (!pluginManagerInstance) {
|
|
259
|
-
pluginManagerInstance = new RouterPluginManager();
|
|
260
|
-
}
|
|
261
|
-
return pluginManagerInstance;
|
|
262
|
-
}
|
|
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 RouterPluginManager(){return RouterPluginManager},get getRouterPluginManager(){return getRouterPluginManager}});const _logger=require("@vlian/logger");const _types=require("./types");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let RouterPluginManager=class RouterPluginManager{register(plugin,options={}){if(!plugin.name){throw new Error("插件必须提供名称")}if(this.plugins.has(plugin.name)&&!options.overwrite){throw new Error(`插件 "${plugin.name}" 已存在`)}const pluginWithDefaults={priority:100,enabled:true,...plugin};if(pluginWithDefaults.dependencies){const missingDeps=pluginWithDefaults.dependencies.filter(dep=>!this.plugins.has(dep));if(missingDeps.length>0){throw new Error(`插件 "${plugin.name}" 缺少依赖: ${missingDeps.join(", ")}`)}}this.plugins.set(plugin.name,{plugin:pluginWithDefaults,status:"registered",registeredAt:Date.now()});_logger.logger.debug(`路由插件已注册: ${plugin.name}`);if(pluginWithDefaults.hooks?.onRegister){try{const context={config:{},meta:{stage:_types.PluginLifecycleStage.REGISTER}};pluginWithDefaults.hooks.onRegister(context)}catch(error){_logger.logger.error(`插件注册钩子执行失败: ${plugin.name}`,error)}}return()=>{this.unregister(plugin.name)}}registerBatch(plugins,options={}){const sortedPlugins=this.sortByDependencies(plugins);sortedPlugins.forEach(plugin=>{this.register(plugin,options)})}sortByDependencies(plugins){const sorted=[];const visited=new Set;const visiting=new Set;const visit=plugin=>{if(visiting.has(plugin.name||"")){throw new Error(`检测到循环依赖: ${plugin.name}`)}if(visited.has(plugin.name||"")){return}visiting.add(plugin.name||"");if(plugin.dependencies){plugin.dependencies.forEach(depName=>{const dep=plugins.find(p=>p.name===depName);if(dep){visit(dep)}})}visiting.delete(plugin.name||"");visited.add(plugin.name||"");sorted.push(plugin)};plugins.forEach(plugin=>{if(!visited.has(plugin.name||"")){visit(plugin)}});return sorted}unregister(name){const registration=this.plugins.get(name);if(!registration){return}if(registration.plugin.hooks?.onDestroy){try{const context={config:{},meta:{stage:_types.PluginLifecycleStage.DESTROY}};registration.plugin.hooks.onDestroy(context)}catch(error){_logger.logger.error(`插件销毁钩子执行失败: ${name}`,error)}}this.plugins.delete(name);_logger.logger.debug(`路由插件已取消注册: ${name}`)}async executeHooks(stage,context){const enabledPlugins=Array.from(this.plugins.values()).filter(reg=>reg.plugin.enabled!==false).sort((a,b)=>(a.plugin.priority||100)-(b.plugin.priority||100));const hookMap={[_types.PluginLifecycleStage.REGISTER]:"onRegister",[_types.PluginLifecycleStage.BEFORE_INIT]:"onBeforeInit",[_types.PluginLifecycleStage.AFTER_INIT]:"onAfterInit",[_types.PluginLifecycleStage.BEFORE_TRANSFORM]:"onBeforeTransform",[_types.PluginLifecycleStage.AFTER_TRANSFORM]:"onAfterTransform",[_types.PluginLifecycleStage.BEFORE_MATCH]:"onBeforeMatch",[_types.PluginLifecycleStage.AFTER_MATCH]:"onAfterMatch",[_types.PluginLifecycleStage.DESTROY]:"onDestroy"};const hookName=hookMap[stage];if(!hookName){return}for(const registration of enabledPlugins){const hook=registration.plugin.hooks?.[hookName];if(hook){try{await hook(context)}catch(error){_logger.logger.error(`插件钩子执行失败: ${registration.plugin.name}.${hookName}`,error)}}}}getPlugin(name){return this.plugins.get(name)?.plugin}getAllPlugins(){return Array.from(this.plugins.values()).map(reg=>reg.plugin)}getEnabledPlugins(){return Array.from(this.plugins.values()).filter(reg=>reg.plugin.enabled!==false).map(reg=>reg.plugin)}clear(){for(const[name,registration]of this.plugins.entries()){if(registration.plugin.hooks?.onDestroy){try{const context={config:{},meta:{stage:_types.PluginLifecycleStage.DESTROY}};registration.plugin.hooks.onDestroy(context)}catch(error){_logger.logger.error(`插件销毁钩子执行失败: ${name}`,error)}}}this.plugins.clear();_logger.logger.debug("所有路由插件已清空")}getCount(){return this.plugins.size}constructor(){_define_property(this,"plugins",new Map)}};let pluginManagerInstance=null;function getRouterPluginManager(){if(!pluginManagerInstance){pluginManagerInstance=new RouterPluginManager}return pluginManagerInstance}
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 路由插件模块入口
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
_export_star(require("./types"), exports);
|
|
8
|
-
_export_star(require("./RouterPluginManager"), exports);
|
|
9
|
-
function _export_star(from, to) {
|
|
10
|
-
Object.keys(from).forEach(function(k) {
|
|
11
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
12
|
-
Object.defineProperty(to, k, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function() {
|
|
15
|
-
return from[k];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return from;
|
|
21
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("./types"),exports);_export_star(require("./RouterPluginManager"),exports);function _export_star(from,to){Object.keys(from).forEach(function(k){if(k!=="default"&&!Object.prototype.hasOwnProperty.call(to,k)){Object.defineProperty(to,k,{enumerable:true,get:function(){return from[k]}})}});return from}
|
|
@@ -1,39 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 路由插件类型定义
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
Object.defineProperty(exports, "PluginLifecycleStage", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function() {
|
|
10
|
-
return PluginLifecycleStage;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
var PluginLifecycleStage = /*#__PURE__*/ function(PluginLifecycleStage) {
|
|
14
|
-
/**
|
|
15
|
-
* 插件注册阶段
|
|
16
|
-
*/ PluginLifecycleStage["REGISTER"] = "register";
|
|
17
|
-
/**
|
|
18
|
-
* 路由初始化前
|
|
19
|
-
*/ PluginLifecycleStage["BEFORE_INIT"] = "before-init";
|
|
20
|
-
/**
|
|
21
|
-
* 路由初始化后
|
|
22
|
-
*/ PluginLifecycleStage["AFTER_INIT"] = "after-init";
|
|
23
|
-
/**
|
|
24
|
-
* 路由转换前
|
|
25
|
-
*/ PluginLifecycleStage["BEFORE_TRANSFORM"] = "before-transform";
|
|
26
|
-
/**
|
|
27
|
-
* 路由转换后
|
|
28
|
-
*/ PluginLifecycleStage["AFTER_TRANSFORM"] = "after-transform";
|
|
29
|
-
/**
|
|
30
|
-
* 路由匹配前
|
|
31
|
-
*/ PluginLifecycleStage["BEFORE_MATCH"] = "before-match";
|
|
32
|
-
/**
|
|
33
|
-
* 路由匹配后
|
|
34
|
-
*/ PluginLifecycleStage["AFTER_MATCH"] = "after-match";
|
|
35
|
-
/**
|
|
36
|
-
* 插件销毁阶段
|
|
37
|
-
*/ PluginLifecycleStage["DESTROY"] = "destroy";
|
|
38
|
-
return PluginLifecycleStage;
|
|
39
|
-
}({});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"PluginLifecycleStage",{enumerable:true,get:function(){return PluginLifecycleStage}});var PluginLifecycleStage=/*#__PURE__*/function(PluginLifecycleStage){PluginLifecycleStage["REGISTER"]="register";PluginLifecycleStage["BEFORE_INIT"]="before-init";PluginLifecycleStage["AFTER_INIT"]="after-init";PluginLifecycleStage["BEFORE_TRANSFORM"]="before-transform";PluginLifecycleStage["AFTER_TRANSFORM"]="after-transform";PluginLifecycleStage["BEFORE_MATCH"]="before-match";PluginLifecycleStage["AFTER_MATCH"]="after-match";PluginLifecycleStage["DESTROY"]="destroy";return PluginLifecycleStage}({});
|
|
@@ -1,129 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "RouteErrorBoundary", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return RouteErrorBoundary;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
12
|
-
const _react = require("react");
|
|
13
|
-
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
14
|
-
const RouteErrorBoundary = ({ error, resetErrorBoundary })=>{
|
|
15
|
-
const [showDetails, setShowDetails] = (0, _react.useState)(false);
|
|
16
|
-
const errorObject = error !== null && typeof error === 'object' ? error : null;
|
|
17
|
-
const errorMessage = typeof errorObject?.message === 'string' && errorObject.message !== '' ? errorObject.message : '未知错误';
|
|
18
|
-
const hasCause = errorObject?.cause !== undefined;
|
|
19
|
-
const isNotFoundError = errorObject?.status === 404 || typeof errorObject?.statusText === 'string' && /not\s*found/i.test(errorObject.statusText) || /no routes matched location|not found|404/i.test(errorMessage);
|
|
20
|
-
const title = isNotFoundError ? '页面不存在(404)' : '出错了,请稍后再试';
|
|
21
|
-
const friendlyMessage = isNotFoundError ? '访问的路由未注册或不存在,请检查访问地址。' : '请稍后再试或联系技术支持';
|
|
22
|
-
const displayMessage = isDevelopment ? errorMessage : friendlyMessage;
|
|
23
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
24
|
-
role: "alert",
|
|
25
|
-
style: {
|
|
26
|
-
minHeight: '100vh',
|
|
27
|
-
display: 'flex',
|
|
28
|
-
justifyContent: 'center',
|
|
29
|
-
alignItems: 'center',
|
|
30
|
-
padding: 24
|
|
31
|
-
},
|
|
32
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
33
|
-
style: {
|
|
34
|
-
maxWidth: 760,
|
|
35
|
-
width: '100%',
|
|
36
|
-
border: '1px solid #dde5ec',
|
|
37
|
-
borderRadius: 10,
|
|
38
|
-
padding: 20
|
|
39
|
-
},
|
|
40
|
-
children: [
|
|
41
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h2", {
|
|
42
|
-
style: {
|
|
43
|
-
marginTop: 0
|
|
44
|
-
},
|
|
45
|
-
children: title
|
|
46
|
-
}),
|
|
47
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("p", {
|
|
48
|
-
children: displayMessage
|
|
49
|
-
}),
|
|
50
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
51
|
-
style: {
|
|
52
|
-
display: 'flex',
|
|
53
|
-
gap: 8,
|
|
54
|
-
marginBottom: 12
|
|
55
|
-
},
|
|
56
|
-
children: [
|
|
57
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
58
|
-
onClick: resetErrorBoundary,
|
|
59
|
-
style: {
|
|
60
|
-
border: 'none',
|
|
61
|
-
background: '#2f80ed',
|
|
62
|
-
color: '#fff',
|
|
63
|
-
borderRadius: 6,
|
|
64
|
-
padding: '8px 12px',
|
|
65
|
-
cursor: 'pointer'
|
|
66
|
-
},
|
|
67
|
-
children: "刷新重试"
|
|
68
|
-
}),
|
|
69
|
-
isDevelopment && /*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
70
|
-
onClick: ()=>setShowDetails(!showDetails),
|
|
71
|
-
style: {
|
|
72
|
-
border: '1px solid #cfd7df',
|
|
73
|
-
background: '#fff',
|
|
74
|
-
borderRadius: 6,
|
|
75
|
-
padding: '8px 12px',
|
|
76
|
-
cursor: 'pointer'
|
|
77
|
-
},
|
|
78
|
-
children: showDetails ? '收起详情' : '展开详情'
|
|
79
|
-
})
|
|
80
|
-
]
|
|
81
|
-
}),
|
|
82
|
-
isDevelopment && showDetails && /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
83
|
-
style: {
|
|
84
|
-
background: '#f7fafc',
|
|
85
|
-
borderRadius: 8,
|
|
86
|
-
padding: 12,
|
|
87
|
-
fontSize: 12,
|
|
88
|
-
fontFamily: 'monospace'
|
|
89
|
-
},
|
|
90
|
-
children: [
|
|
91
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
92
|
-
style: {
|
|
93
|
-
marginBottom: 10
|
|
94
|
-
},
|
|
95
|
-
children: [
|
|
96
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
97
|
-
children: "错误信息:"
|
|
98
|
-
}),
|
|
99
|
-
errorMessage
|
|
100
|
-
]
|
|
101
|
-
}),
|
|
102
|
-
errorObject?.stack && /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
103
|
-
style: {
|
|
104
|
-
marginBottom: 10,
|
|
105
|
-
whiteSpace: 'pre-wrap',
|
|
106
|
-
wordBreak: 'break-word'
|
|
107
|
-
},
|
|
108
|
-
children: [
|
|
109
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
110
|
-
children: "堆栈:"
|
|
111
|
-
}),
|
|
112
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("br", {}),
|
|
113
|
-
errorObject.stack
|
|
114
|
-
]
|
|
115
|
-
}),
|
|
116
|
-
hasCause && /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
117
|
-
children: [
|
|
118
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
119
|
-
children: "原因:"
|
|
120
|
-
}),
|
|
121
|
-
errorObject?.cause instanceof Error ? errorObject.cause.message : String(errorObject?.cause)
|
|
122
|
-
]
|
|
123
|
-
})
|
|
124
|
-
]
|
|
125
|
-
})
|
|
126
|
-
]
|
|
127
|
-
})
|
|
128
|
-
});
|
|
129
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"RouteErrorBoundary",{enumerable:true,get:function(){return RouteErrorBoundary}});const _jsxruntime=require("react/jsx-runtime");const _react=require("react");const isDevelopment=process.env.NODE_ENV==="development";const RouteErrorBoundary=({error,resetErrorBoundary})=>{const[showDetails,setShowDetails]=(0,_react.useState)(false);const errorObject=error!==null&&typeof error==="object"?error:null;const errorMessage=typeof errorObject?.message==="string"&&errorObject.message!==""?errorObject.message:"未知错误";const hasCause=errorObject?.cause!==undefined;const isNotFoundError=errorObject?.status===404||typeof errorObject?.statusText==="string"&&/not\s*found/i.test(errorObject.statusText)||/no routes matched location|not found|404/i.test(errorMessage);const title=isNotFoundError?"页面不存在(404)":"出错了,请稍后再试";const friendlyMessage=isNotFoundError?"访问的路由未注册或不存在,请检查访问地址。":"请稍后再试或联系技术支持";const displayMessage=isDevelopment?errorMessage:friendlyMessage;return(0,_jsxruntime.jsx)("div",{role:"alert",style:{minHeight:"100vh",display:"flex",justifyContent:"center",alignItems:"center",padding:24},children:(0,_jsxruntime.jsxs)("div",{style:{maxWidth:760,width:"100%",border:"1px solid #dde5ec",borderRadius:10,padding:20},children:[(0,_jsxruntime.jsx)("h2",{style:{marginTop:0},children:title}),(0,_jsxruntime.jsx)("p",{children:displayMessage}),(0,_jsxruntime.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:12},children:[(0,_jsxruntime.jsx)("button",{onClick:resetErrorBoundary,style:{border:"none",background:"#2f80ed",color:"#fff",borderRadius:6,padding:"8px 12px",cursor:"pointer"},children:"刷新重试"}),isDevelopment&&(0,_jsxruntime.jsx)("button",{onClick:()=>setShowDetails(!showDetails),style:{border:"1px solid #cfd7df",background:"#fff",borderRadius:6,padding:"8px 12px",cursor:"pointer"},children:showDetails?"收起详情":"展开详情"})]}),isDevelopment&&showDetails&&(0,_jsxruntime.jsxs)("div",{style:{background:"#f7fafc",borderRadius:8,padding:12,fontSize:12,fontFamily:"monospace"},children:[(0,_jsxruntime.jsxs)("div",{style:{marginBottom:10},children:[(0,_jsxruntime.jsx)("strong",{children:"错误信息:"}),errorMessage]}),errorObject?.stack&&(0,_jsxruntime.jsxs)("div",{style:{marginBottom:10,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:[(0,_jsxruntime.jsx)("strong",{children:"堆栈:"}),(0,_jsxruntime.jsx)("br",{}),errorObject.stack]}),hasCause&&(0,_jsxruntime.jsxs)("div",{children:[(0,_jsxruntime.jsx)("strong",{children:"原因:"}),errorObject?.cause instanceof Error?errorObject.cause.message:String(errorObject?.cause)]})]})]})})};
|