@vlian/framework 1.2.61 → 1.2.63

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.
Files changed (268) hide show
  1. package/dist/analytics.umd.js +1 -1
  2. package/dist/components/index.cjs +1 -1
  3. package/dist/components/index.d.ts +0 -4
  4. package/dist/components/index.js +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +1 -1
  8. package/dist/index.umd.js +31 -246
  9. package/dist/kernel/types.d.ts +46 -3
  10. package/dist/state.umd.js +1 -1
  11. package/package.json +21 -16
  12. package/dist/components/LocaleSwitch.cjs +0 -1
  13. package/dist/components/LocaleSwitch.d.ts +0 -21
  14. package/dist/components/LocaleSwitch.js +0 -1
  15. package/dist/components/ThemeSwitch.cjs +0 -1
  16. package/dist/components/ThemeSwitch.d.ts +0 -20
  17. package/dist/components/ThemeSwitch.js +0 -1
  18. package/dist/core/Test.cjs +0 -1
  19. package/dist/core/Test.d.ts +0 -5
  20. package/dist/core/Test.js +0 -1
  21. package/dist/core/app/AppContext.cjs +0 -1
  22. package/dist/core/app/AppContext.d.ts +0 -113
  23. package/dist/core/app/AppContext.js +0 -1
  24. package/dist/core/app/AppContext.types.cjs +0 -1
  25. package/dist/core/app/AppContext.types.d.ts +0 -146
  26. package/dist/core/app/AppContext.types.js +0 -1
  27. package/dist/core/app/BasicLayout.cjs +0 -1
  28. package/dist/core/app/BasicLayout.d.ts +0 -15
  29. package/dist/core/app/BasicLayout.js +0 -1
  30. package/dist/core/app/DefaultApp.cjs +0 -1
  31. package/dist/core/app/DefaultApp.d.ts +0 -10
  32. package/dist/core/app/DefaultApp.js +0 -1
  33. package/dist/core/app/index.cjs +0 -1
  34. package/dist/core/app/index.d.ts +0 -8
  35. package/dist/core/app/index.js +0 -1
  36. package/dist/core/config/AppConfig.cjs +0 -1
  37. package/dist/core/config/AppConfig.d.ts +0 -88
  38. package/dist/core/config/AppConfig.js +0 -1
  39. package/dist/core/config/ConfigLoader.cjs +0 -1
  40. package/dist/core/config/ConfigLoader.d.ts +0 -118
  41. package/dist/core/config/ConfigLoader.js +0 -1
  42. package/dist/core/config/ConfigValidator.cjs +0 -2
  43. package/dist/core/config/ConfigValidator.d.ts +0 -84
  44. package/dist/core/config/ConfigValidator.js +0 -2
  45. package/dist/core/config/index.cjs +0 -1
  46. package/dist/core/config/index.d.ts +0 -6
  47. package/dist/core/config/index.js +0 -1
  48. package/dist/core/dev/DevTools.cjs +0 -1
  49. package/dist/core/dev/DevTools.d.ts +0 -16
  50. package/dist/core/dev/DevTools.js +0 -1
  51. package/dist/core/error/ErrorBoundary.cjs +0 -1
  52. package/dist/core/error/ErrorBoundary.d.ts +0 -121
  53. package/dist/core/error/ErrorBoundary.js +0 -1
  54. package/dist/core/error/ErrorHandler.cjs +0 -1
  55. package/dist/core/error/ErrorHandler.d.ts +0 -171
  56. package/dist/core/error/ErrorHandler.js +0 -1
  57. package/dist/core/error/index.cjs +0 -1
  58. package/dist/core/error/index.d.ts +0 -7
  59. package/dist/core/error/index.js +0 -1
  60. package/dist/core/event/AppEventBus.cjs +0 -1
  61. package/dist/core/event/AppEventBus.d.ts +0 -178
  62. package/dist/core/event/AppEventBus.js +0 -1
  63. package/dist/core/event/frameworkEvents.cjs +0 -1
  64. package/dist/core/event/frameworkEvents.d.ts +0 -69
  65. package/dist/core/event/frameworkEvents.js +0 -1
  66. package/dist/core/event/hooks.cjs +0 -1
  67. package/dist/core/event/hooks.d.ts +0 -57
  68. package/dist/core/event/hooks.js +0 -1
  69. package/dist/core/event/index.cjs +0 -1
  70. package/dist/core/event/index.d.ts +0 -10
  71. package/dist/core/event/index.js +0 -1
  72. package/dist/core/event/types.cjs +0 -1
  73. package/dist/core/event/types.d.ts +0 -269
  74. package/dist/core/event/types.js +0 -1
  75. package/dist/core/event/useEventBus.cjs +0 -1
  76. package/dist/core/event/useEventBus.d.ts +0 -28
  77. package/dist/core/event/useEventBus.js +0 -1
  78. package/dist/core/index.cjs +0 -1
  79. package/dist/core/index.d.ts +0 -54
  80. package/dist/core/index.js +0 -1
  81. package/dist/core/initialization/InitializationErrorThrower.cjs +0 -1
  82. package/dist/core/initialization/InitializationErrorThrower.d.ts +0 -7
  83. package/dist/core/initialization/InitializationErrorThrower.js +0 -1
  84. package/dist/core/initialization/index.cjs +0 -1
  85. package/dist/core/initialization/index.d.ts +0 -7
  86. package/dist/core/initialization/index.js +0 -1
  87. package/dist/core/initialization/initialization.cjs +0 -1
  88. package/dist/core/initialization/initialization.d.ts +0 -69
  89. package/dist/core/initialization/initialization.js +0 -1
  90. package/dist/core/initialization/initializationErrorState.cjs +0 -1
  91. package/dist/core/initialization/initializationErrorState.d.ts +0 -35
  92. package/dist/core/initialization/initializationErrorState.js +0 -1
  93. package/dist/core/kernel/defaultAdapters.cjs +0 -1
  94. package/dist/core/kernel/defaultAdapters.d.ts +0 -2
  95. package/dist/core/kernel/defaultAdapters.js +0 -1
  96. package/dist/core/kernel/errors.cjs +0 -1
  97. package/dist/core/kernel/errors.d.ts +0 -18
  98. package/dist/core/kernel/errors.js +0 -1
  99. package/dist/core/kernel/index.cjs +0 -1
  100. package/dist/core/kernel/index.d.ts +0 -3
  101. package/dist/core/kernel/index.js +0 -1
  102. package/dist/core/kernel/startKernel.cjs +0 -1
  103. package/dist/core/kernel/startKernel.d.ts +0 -2
  104. package/dist/core/kernel/startKernel.js +0 -1
  105. package/dist/core/kernel/types.cjs +0 -1
  106. package/dist/core/kernel/types.d.ts +0 -114
  107. package/dist/core/kernel/types.js +0 -1
  108. package/dist/core/middleware.cjs +0 -1
  109. package/dist/core/middleware.d.ts +0 -36
  110. package/dist/core/middleware.js +0 -1
  111. package/dist/core/plugin/PluginEventBus.cjs +0 -1
  112. package/dist/core/plugin/PluginEventBus.d.ts +0 -169
  113. package/dist/core/plugin/PluginEventBus.js +0 -1
  114. package/dist/core/plugin/PluginSandbox.cjs +0 -1
  115. package/dist/core/plugin/PluginSandbox.d.ts +0 -101
  116. package/dist/core/plugin/PluginSandbox.js +0 -1
  117. package/dist/core/plugin.cjs +0 -1
  118. package/dist/core/plugin.d.ts +0 -224
  119. package/dist/core/plugin.js +0 -1
  120. package/dist/core/router/RouterManager.cjs +0 -1
  121. package/dist/core/router/RouterManager.d.ts +0 -87
  122. package/dist/core/router/RouterManager.js +0 -1
  123. package/dist/core/router/adapter/AdapterManager.cjs +0 -1
  124. package/dist/core/router/adapter/AdapterManager.d.ts +0 -94
  125. package/dist/core/router/adapter/AdapterManager.js +0 -1
  126. package/dist/core/router/adapter/index.cjs +0 -1
  127. package/dist/core/router/adapter/index.d.ts +0 -6
  128. package/dist/core/router/adapter/index.js +0 -1
  129. package/dist/core/router/adapter/react-router/ReactRouterAdapter.cjs +0 -1
  130. package/dist/core/router/adapter/react-router/ReactRouterAdapter.d.ts +0 -43
  131. package/dist/core/router/adapter/react-router/ReactRouterAdapter.js +0 -1
  132. package/dist/core/router/adapter/react-router/index.cjs +0 -1
  133. package/dist/core/router/adapter/react-router/index.d.ts +0 -4
  134. package/dist/core/router/adapter/react-router/index.js +0 -1
  135. package/dist/core/router/adapter/types.cjs +0 -1
  136. package/dist/core/router/adapter/types.d.ts +0 -111
  137. package/dist/core/router/adapter/types.js +0 -1
  138. package/dist/core/router/dev/RouterDevTools.cjs +0 -1
  139. package/dist/core/router/dev/RouterDevTools.d.ts +0 -5
  140. package/dist/core/router/dev/RouterDevTools.js +0 -1
  141. package/dist/core/router/dev/index.cjs +0 -1
  142. package/dist/core/router/dev/index.d.ts +0 -4
  143. package/dist/core/router/dev/index.js +0 -1
  144. package/dist/core/router/dynamic/DynamicRouteManager.cjs +0 -1
  145. package/dist/core/router/dynamic/DynamicRouteManager.d.ts +0 -71
  146. package/dist/core/router/dynamic/DynamicRouteManager.js +0 -1
  147. package/dist/core/router/dynamic/index.cjs +0 -1
  148. package/dist/core/router/dynamic/index.d.ts +0 -4
  149. package/dist/core/router/dynamic/index.js +0 -1
  150. package/dist/core/router/errors/RouterError.cjs +0 -1
  151. package/dist/core/router/errors/RouterError.d.ts +0 -48
  152. package/dist/core/router/errors/RouterError.js +0 -1
  153. package/dist/core/router/errors/index.cjs +0 -1
  154. package/dist/core/router/errors/index.d.ts +0 -4
  155. package/dist/core/router/errors/index.js +0 -1
  156. package/dist/core/router/index.cjs +0 -1
  157. package/dist/core/router/index.d.ts +0 -16
  158. package/dist/core/router/index.js +0 -1
  159. package/dist/core/router/lifecycle/RouterLifecycleManager.cjs +0 -1
  160. package/dist/core/router/lifecycle/RouterLifecycleManager.d.ts +0 -56
  161. package/dist/core/router/lifecycle/RouterLifecycleManager.js +0 -1
  162. package/dist/core/router/lifecycle/index.cjs +0 -1
  163. package/dist/core/router/lifecycle/index.d.ts +0 -4
  164. package/dist/core/router/lifecycle/index.js +0 -1
  165. package/dist/core/router/middleware/RouterMiddlewareManager.cjs +0 -1
  166. package/dist/core/router/middleware/RouterMiddlewareManager.d.ts +0 -61
  167. package/dist/core/router/middleware/RouterMiddlewareManager.js +0 -1
  168. package/dist/core/router/middleware/auth.cjs +0 -1
  169. package/dist/core/router/middleware/auth.d.ts +0 -54
  170. package/dist/core/router/middleware/auth.js +0 -1
  171. package/dist/core/router/middleware/index.cjs +0 -1
  172. package/dist/core/router/middleware/index.d.ts +0 -6
  173. package/dist/core/router/middleware/index.js +0 -1
  174. package/dist/core/router/middleware/types.cjs +0 -1
  175. package/dist/core/router/middleware/types.d.ts +0 -82
  176. package/dist/core/router/middleware/types.js +0 -1
  177. package/dist/core/router/monitoring/RouterMonitoring.cjs +0 -1
  178. package/dist/core/router/monitoring/RouterMonitoring.d.ts +0 -134
  179. package/dist/core/router/monitoring/RouterMonitoring.js +0 -1
  180. package/dist/core/router/monitoring/index.cjs +0 -1
  181. package/dist/core/router/monitoring/index.d.ts +0 -4
  182. package/dist/core/router/monitoring/index.js +0 -1
  183. package/dist/core/router/navigation/RouterNavigation.cjs +0 -1
  184. package/dist/core/router/navigation/RouterNavigation.d.ts +0 -43
  185. package/dist/core/router/navigation/RouterNavigation.js +0 -1
  186. package/dist/core/router/navigation/index.cjs +0 -1
  187. package/dist/core/router/navigation/index.d.ts +0 -4
  188. package/dist/core/router/navigation/index.js +0 -1
  189. package/dist/core/router/performance/RouteCache.cjs +0 -1
  190. package/dist/core/router/performance/RouteCache.d.ts +0 -113
  191. package/dist/core/router/performance/RouteCache.js +0 -1
  192. package/dist/core/router/performance/RoutePreloader.cjs +0 -1
  193. package/dist/core/router/performance/RoutePreloader.d.ts +0 -111
  194. package/dist/core/router/performance/RoutePreloader.js +0 -1
  195. package/dist/core/router/performance/index.cjs +0 -1
  196. package/dist/core/router/performance/index.d.ts +0 -5
  197. package/dist/core/router/performance/index.js +0 -1
  198. package/dist/core/router/plugin/RouterPluginManager.cjs +0 -1
  199. package/dist/core/router/plugin/RouterPluginManager.d.ts +0 -74
  200. package/dist/core/router/plugin/RouterPluginManager.js +0 -1
  201. package/dist/core/router/plugin/index.cjs +0 -1
  202. package/dist/core/router/plugin/index.d.ts +0 -5
  203. package/dist/core/router/plugin/index.js +0 -1
  204. package/dist/core/router/plugin/types.cjs +0 -1
  205. package/dist/core/router/plugin/types.d.ts +0 -153
  206. package/dist/core/router/plugin/types.js +0 -1
  207. package/dist/core/router/types.cjs +0 -1
  208. package/dist/core/router/types.d.ts +0 -464
  209. package/dist/core/router/types.js +0 -1
  210. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +0 -1
  211. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.d.ts +0 -2
  212. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.js +0 -1
  213. package/dist/core/router/utils/adapters/react-router/transform.cjs +0 -1
  214. package/dist/core/router/utils/adapters/react-router/transform.d.ts +0 -5
  215. package/dist/core/router/utils/adapters/react-router/transform.js +0 -1
  216. package/dist/core/router/utils/transform.cjs +0 -1
  217. package/dist/core/router/utils/transform.d.ts +0 -348
  218. package/dist/core/router/utils/transform.js +0 -1
  219. package/dist/core/router/validation/RouterConfigValidator.cjs +0 -2
  220. package/dist/core/router/validation/RouterConfigValidator.d.ts +0 -121
  221. package/dist/core/router/validation/RouterConfigValidator.js +0 -2
  222. package/dist/core/router/validation/index.cjs +0 -1
  223. package/dist/core/router/validation/index.d.ts +0 -5
  224. package/dist/core/router/validation/index.js +0 -1
  225. package/dist/core/router/validation/schema.cjs +0 -1
  226. package/dist/core/router/validation/schema.d.ts +0 -180
  227. package/dist/core/router/validation/schema.js +0 -1
  228. package/dist/core/router/version/RouteVersionManager.cjs +0 -1
  229. package/dist/core/router/version/RouteVersionManager.d.ts +0 -124
  230. package/dist/core/router/version/RouteVersionManager.js +0 -1
  231. package/dist/core/router/version/index.cjs +0 -1
  232. package/dist/core/router/version/index.d.ts +0 -4
  233. package/dist/core/router/version/index.js +0 -1
  234. package/dist/core/splash/SplashScreen.cjs +0 -1
  235. package/dist/core/splash/SplashScreen.d.ts +0 -14
  236. package/dist/core/splash/SplashScreen.js +0 -1
  237. package/dist/core/splash/index.cjs +0 -1
  238. package/dist/core/splash/index.d.ts +0 -5
  239. package/dist/core/splash/index.js +0 -1
  240. package/dist/core/splash/splashScreenUtils.cjs +0 -1
  241. package/dist/core/splash/splashScreenUtils.d.ts +0 -7
  242. package/dist/core/splash/splashScreenUtils.js +0 -1
  243. package/dist/core/startup/AppInstance.cjs +0 -1
  244. package/dist/core/startup/AppInstance.d.ts +0 -138
  245. package/dist/core/startup/AppInstance.js +0 -1
  246. package/dist/core/startup/environment.cjs +0 -1
  247. package/dist/core/startup/environment.d.ts +0 -87
  248. package/dist/core/startup/environment.js +0 -1
  249. package/dist/core/startup/index.cjs +0 -1
  250. package/dist/core/startup/index.d.ts +0 -7
  251. package/dist/core/startup/index.js +0 -1
  252. package/dist/core/startup/initializeServices.cjs +0 -1
  253. package/dist/core/startup/initializeServices.d.ts +0 -68
  254. package/dist/core/startup/initializeServices.js +0 -1
  255. package/dist/core/startup/performanceTracker.cjs +0 -1
  256. package/dist/core/startup/performanceTracker.d.ts +0 -104
  257. package/dist/core/startup/performanceTracker.js +0 -1
  258. package/dist/core/startup/renderApp.cjs +0 -1
  259. package/dist/core/startup/renderApp.d.ts +0 -70
  260. package/dist/core/startup/renderApp.js +0 -1
  261. package/dist/core/startup/startApp.cjs +0 -1
  262. package/dist/core/startup/startApp.d.ts +0 -14
  263. package/dist/core/startup/startApp.js +0 -1
  264. package/dist/core/types.cjs +0 -1
  265. package/dist/core/types.d.ts +0 -501
  266. package/dist/core/types.js +0 -1
  267. package/dist/index.umd.cjs +0 -1
  268. package/dist/index.umd.d.ts +0 -7
@@ -1,224 +0,0 @@
1
- import type { StartOptions } from './types';
2
- import type { InitializationContext } from './initialization';
3
- import { PluginSandbox, type PluginSandboxConfig } from './plugin/PluginSandbox';
4
- import { type PluginEventBus } from './plugin/PluginEventBus';
5
- /**
6
- * 插件接口
7
- */
8
- export interface Plugin<TOption = unknown> {
9
- /**
10
- * 插件名称
11
- */
12
- name: string;
13
- /**
14
- * 插件版本
15
- */
16
- version?: string;
17
- /**
18
- * 插件依赖列表(插件名称数组)
19
- * 优化:支持插件依赖管理
20
- */
21
- dependencies?: string[];
22
- /**
23
- * 插件优先级(数字越小优先级越高)
24
- * 优化:支持插件加载顺序控制
25
- */
26
- priority?: number;
27
- /**
28
- * 插件沙箱配置(用于权限控制)
29
- */
30
- sandbox?: PluginSandboxConfig;
31
- /**
32
- * 初始化前钩子
33
- */
34
- beforeInit?: (options: Partial<StartOptions>, sandbox: PluginSandbox, eventBus: PluginEventBus) => Promise<void> | void;
35
- /**
36
- * 初始化钩子
37
- */
38
- init?: (options: Partial<StartOptions>, context: InitializationContext, sandbox: PluginSandbox, eventBus: PluginEventBus) => Promise<void> | void;
39
- /**
40
- * 初始化后钩子
41
- */
42
- afterInit?: (options: Partial<StartOptions>, context: InitializationContext, sandbox: PluginSandbox, eventBus: PluginEventBus) => Promise<void> | void;
43
- /**
44
- * 销毁钩子
45
- */
46
- destroy?: () => Promise<void> | void;
47
- /**
48
- * 自定义属性
49
- */
50
- readonly option?: Readonly<TOption>;
51
- }
52
- /**
53
- * 插件加载选项
54
- */
55
- export interface PluginLoadOptions {
56
- /**
57
- * 插件URL(用于动态加载)
58
- */
59
- url?: string;
60
- /**
61
- * 插件模块路径(用于动态导入)
62
- */
63
- modulePath?: string;
64
- /**
65
- * 是否立即初始化
66
- */
67
- initialize?: boolean;
68
- /**
69
- * 初始化上下文(如果立即初始化)
70
- */
71
- initContext?: InitializationContext;
72
- /**
73
- * 启动选项(如果立即初始化)
74
- */
75
- startOptions?: StartOptions;
76
- }
77
- /**
78
- * 插件管理器
79
- *
80
- * 优化:
81
- * 1. 支持插件依赖管理
82
- * 2. 支持插件优先级控制
83
- * 3. 支持插件生命周期管理
84
- * 4. 支持插件热插拔(动态加载/卸载)
85
- */
86
- export declare class PluginManager {
87
- private plugins;
88
- private sandboxes;
89
- private pluginStatus;
90
- private pluginLoaders;
91
- /**
92
- * 注册插件
93
- *
94
- * 优化:检查插件依赖是否已注册
95
- */
96
- register(plugin: Plugin): void;
97
- /**
98
- * 获取插件加载顺序(考虑依赖和优先级)
99
- *
100
- * @returns 插件名称数组,按加载顺序排列
101
- */
102
- private getLoadOrder;
103
- /**
104
- * 注销插件
105
- */
106
- unregister(name: string): void;
107
- /**
108
- * 动态加载插件(热插拔)
109
- *
110
- * @param options - 插件加载选项
111
- * @returns 加载的插件
112
- */
113
- loadPlugin(options: PluginLoadOptions): Promise<Plugin>;
114
- /**
115
- * 初始化单个插件
116
- *
117
- * @param name - 插件名称
118
- * @param options - 启动选项
119
- * @param context - 初始化上下文
120
- */
121
- initializePlugin(name: string, options: StartOptions, context: InitializationContext): Promise<void>;
122
- /**
123
- * 卸载插件(热插拔)
124
- *
125
- * @param name - 插件名称
126
- * @param force - 是否强制卸载(即使有依赖)
127
- */
128
- unloadPlugin(name: string, force?: boolean): Promise<void>;
129
- /**
130
- * 检查插件是否可以热加载
131
- *
132
- * @param plugin - 插件
133
- * @returns 是否可以热加载
134
- */
135
- canHotLoad(plugin: Plugin): boolean;
136
- /**
137
- * 注册插件加载器(用于延迟加载)
138
- *
139
- * @param name - 插件名称
140
- * @param loader - 加载器函数
141
- */
142
- registerLoader(name: string, loader: () => Promise<Plugin>): void;
143
- /**
144
- * 使用加载器加载插件
145
- *
146
- * @param name - 插件名称
147
- * @param options - 加载选项
148
- * @returns 加载的插件
149
- */
150
- loadPluginByLoader(name: string, options?: Omit<PluginLoadOptions, 'url' | 'modulePath'>): Promise<Plugin>;
151
- /**
152
- * 获取插件
153
- */
154
- get(name: string): Plugin | undefined;
155
- /**
156
- * 获取所有插件
157
- */
158
- getAll(): Plugin[];
159
- /**
160
- * 执行初始化前钩子
161
- *
162
- * 优化:按依赖顺序执行
163
- */
164
- executeBeforeInit(options: StartOptions): Promise<void>;
165
- /**
166
- * 执行初始化钩子
167
- *
168
- * 优化:按依赖顺序执行,并更新插件状态
169
- */
170
- executeInit(options: StartOptions, context: InitializationContext): Promise<void>;
171
- /**
172
- * 执行初始化后钩子
173
- *
174
- * 优化:按依赖顺序执行(逆序,确保依赖插件先执行)
175
- */
176
- executeAfterInit(options: StartOptions, context: InitializationContext): Promise<void>;
177
- /**
178
- * 获取插件状态
179
- *
180
- * @param name - 插件名称
181
- * @returns 插件状态
182
- */
183
- getPluginStatus(name: string): 'registered' | 'initialized' | 'destroyed' | 'loading' | undefined;
184
- /**
185
- * 检查插件是否已加载
186
- *
187
- * @param name - 插件名称
188
- * @returns 是否已加载
189
- */
190
- isLoaded(name: string): boolean;
191
- /**
192
- * 获取已加载的插件列表
193
- *
194
- * @returns 插件名称数组
195
- */
196
- getLoadedPlugins(): string[];
197
- /**
198
- * 获取所有插件状态
199
- *
200
- * @returns 插件状态映射
201
- */
202
- getAllPluginStatus(): Map<string, 'registered' | 'initialized' | 'destroyed' | 'loading'>;
203
- /**
204
- * 获取插件沙箱
205
- *
206
- * @param name - 插件名称
207
- * @returns 插件沙箱或undefined
208
- */
209
- getSandbox(name: string): PluginSandbox | undefined;
210
- /**
211
- * 获取事件总线
212
- */
213
- getEventBus(): PluginEventBus;
214
- /**
215
- * 销毁所有插件
216
- */
217
- destroyAll(): Promise<void>;
218
- }
219
- /**
220
- * 默认插件管理器
221
- */
222
- export declare const pluginManager: PluginManager;
223
- export { PluginSandbox, PluginPermission, type PluginSandboxConfig } from './plugin/PluginSandbox';
224
- export { PluginEventBus, pluginEventBus, type EventListener, type EventMetadata, type EventWrapper, type PluginEventBusConfig, } from './plugin/PluginEventBus';
@@ -1 +0,0 @@
1
- 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}import{PluginSandbox}from"./plugin/PluginSandbox";import{pluginEventBus}from"./plugin/PluginEventBus";export class PluginManager{register(plugin){if(this.plugins.has(plugin.name)){console.warn(`插件 ${plugin.name} 已存在,将被覆盖`)}if(plugin.dependencies&&plugin.dependencies.length>0){const missingDeps=plugin.dependencies.filter(dep=>!this.plugins.has(dep));if(missingDeps.length>0){console.warn(`插件 ${plugin.name} 的依赖未注册: ${missingDeps.join(", ")}`)}}this.plugins.set(plugin.name,plugin);this.pluginStatus.set(plugin.name,"registered");if(plugin.sandbox){const sandbox=new PluginSandbox({...plugin.sandbox,name:plugin.name});this.sandboxes.set(plugin.name,sandbox)}else{const sandbox=new PluginSandbox({strictMode:false,name:plugin.name});this.sandboxes.set(plugin.name,sandbox)}}getLoadOrder(){const plugins=Array.from(this.plugins.values());const sortedPlugins=plugins.sort((a,b)=>{const priorityA=a.priority??100;const priorityB=b.priority??100;return priorityA-priorityB});const visited=new Set;const visiting=new Set;const result=[];const visit=pluginName=>{if(visiting.has(pluginName)){console.warn(`检测到循环依赖,涉及插件: ${pluginName}`);return}if(visited.has(pluginName)){return}visiting.add(pluginName);const plugin=this.plugins.get(pluginName);if(plugin?.dependencies){for(const dep of plugin.dependencies){visit(dep)}}visiting.delete(pluginName);visited.add(pluginName);result.push(pluginName)};for(const plugin of sortedPlugins){visit(plugin.name)}return result}unregister(name){const plugin=this.plugins.get(name);if(plugin&&plugin.destroy){plugin.destroy()}this.plugins.delete(name);this.sandboxes.delete(name);this.pluginStatus.delete(name);this.pluginLoaders.delete(name)}async loadPlugin(options){let plugin;if(options.url){const response=await fetch(options.url);if(!response.ok){throw new Error(`无法加载插件: ${options.url} (${response.status})`)}const pluginModule=await response.json();plugin=pluginModule.default||pluginModule}else if(options.modulePath){const pluginModule=await import(options.modulePath);plugin=pluginModule.default||pluginModule}else{throw new Error("必须提供 url 或 modulePath")}if(!plugin||!plugin.name){throw new Error("插件格式无效:必须包含 name 属性")}if(this.plugins.has(plugin.name)){throw new Error(`插件 ${plugin.name} 已加载`)}this.pluginStatus.set(plugin.name,"loading");try{this.register(plugin);if(options.initialize&&options.initContext&&options.startOptions){await this.initializePlugin(plugin.name,options.startOptions,options.initContext)}return plugin}catch(error){this.pluginStatus.delete(plugin.name);throw error}}async initializePlugin(name,options,context){const plugin=this.plugins.get(name);if(!plugin){throw new Error(`插件 ${name} 未注册`)}const status=this.pluginStatus.get(name);if(status==="initialized"){return}try{const sandbox=this.sandboxes.get(name);if(!sandbox){throw new Error(`插件 ${name} 的沙箱未找到`)}if(plugin.init){const filteredOptions=sandbox.filterConfig(options);await plugin.init(filteredOptions,context,sandbox,pluginEventBus)}this.pluginStatus.set(name,"initialized")}catch(error){console.error(`插件 ${name} 初始化失败:`,error);throw error}}async unloadPlugin(name,force=false){const plugin=this.plugins.get(name);if(!plugin){throw new Error(`插件 ${name} 未加载`)}if(!force){const dependents=Array.from(this.plugins.values()).filter(p=>p.dependencies&&p.dependencies.includes(name));if(dependents.length>0){throw new Error(`无法卸载插件 ${name},以下插件依赖它: ${dependents.map(p=>p.name).join(", ")}`)}}if(plugin.destroy){try{await plugin.destroy()}catch(error){console.error(`插件 ${name} 的 destroy 钩子执行失败:`,error)}}this.unregister(name);this.pluginStatus.set(name,"destroyed")}canHotLoad(plugin){if(plugin.dependencies&&plugin.dependencies.length>0){const missingDeps=plugin.dependencies.filter(dep=>!this.plugins.has(dep));if(missingDeps.length>0){return false}}return true}registerLoader(name,loader){this.pluginLoaders.set(name,loader)}async loadPluginByLoader(name,options){const loader=this.pluginLoaders.get(name);if(!loader){throw new Error(`插件 ${name} 的加载器未注册`)}const plugin=await loader();if(!plugin||!plugin.name){throw new Error("插件格式无效:必须包含 name 属性")}if(plugin.name!==name){throw new Error(`插件名称不匹配: 期望 ${name},实际 ${plugin.name}`)}if(this.plugins.has(plugin.name)){return this.plugins.get(plugin.name)}this.pluginStatus.set(plugin.name,"loading");try{this.register(plugin);if(options?.initialize&&options.initContext&&options.startOptions){await this.initializePlugin(plugin.name,options.startOptions,options.initContext)}return plugin}catch(error){this.pluginStatus.delete(plugin.name);throw error}}get(name){return this.plugins.get(name)}getAll(){return Array.from(this.plugins.values())}async executeBeforeInit(options){const loadOrder=this.getLoadOrder();for(const pluginName of loadOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.beforeInit){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.beforeInit(filteredOptions,sandbox,pluginEventBus)}catch(error){console.error(`插件 ${plugin.name} 的 beforeInit 钩子执行失败:`,error)}}}async executeInit(options,context){const loadOrder=this.getLoadOrder();for(const pluginName of loadOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.init){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.init(filteredOptions,context,sandbox,pluginEventBus);this.pluginStatus.set(plugin.name,"initialized")}catch(error){console.error(`插件 ${plugin.name} 的 init 钩子执行失败:`,error)}}}async executeAfterInit(options,context){const loadOrder=this.getLoadOrder();const reverseOrder=[...loadOrder].reverse();for(const pluginName of reverseOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.afterInit){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.afterInit(filteredOptions,context,sandbox,pluginEventBus)}catch(error){console.error(`插件 ${plugin.name} 的 afterInit 钩子执行失败:`,error)}}}getPluginStatus(name){return this.pluginStatus.get(name)}isLoaded(name){return this.plugins.has(name)}getLoadedPlugins(){return Array.from(this.plugins.keys())}getAllPluginStatus(){return new Map(this.pluginStatus)}getSandbox(name){return this.sandboxes.get(name)}getEventBus(){return pluginEventBus}async destroyAll(){for(const plugin of this.plugins.values()){if(plugin.destroy){try{await plugin.destroy()}catch(error){console.error(`插件 ${plugin.name} 的 destroy 钩子执行失败:`,error)}}}this.plugins.clear()}constructor(){_define_property(this,"plugins",new Map);_define_property(this,"sandboxes",new Map);_define_property(this,"pluginStatus",new Map);_define_property(this,"pluginLoaders",new Map)}}export const pluginManager=new PluginManager;export{PluginSandbox,PluginPermission}from"./plugin/PluginSandbox";export{PluginEventBus,pluginEventBus}from"./plugin/PluginEventBus";
@@ -1 +0,0 @@
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 RouterManager(){return RouterManager},get getRouterManager(){return getRouterManager}});const _logger=require("@vlian/logger");const _transform=require("./utils/transform");const _transform1=require("./utils/adapters/react-router/transform");const _reactrouterdom=require("react-router-dom");const _validation=require("./validation");const _lifecycle=require("./lifecycle");const _middleware=require("./middleware");const _errors=require("./errors");const _RouteCache=require("./performance/RouteCache");const _RoutePreloader=require("./performance/RoutePreloader");const _plugin=require("./plugin");const _monitoring=require("./monitoring");const _adapter=require("./adapter");const _reactrouter=require("./adapter/react-router");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 RouterManager=class RouterManager{static getInstance(){if(!RouterManager.instance){RouterManager.instance=new RouterManager}return RouterManager.instance}async initialize(config){if(config.enabled===false||config.enabled==="disabled"){_logger.logger.info("路由系统已禁用");return}if(config.enableValidation!==false){try{_validation.RouterConfigValidator.validate(config);_logger.logger.debug("路由配置验证通过")}catch(error){_logger.logger.error("路由配置验证失败",error);if(process.env.NODE_ENV==="development"){throw error}}}await this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.BEFORE_INIT,{config});if(config.hooks){const lifecycleManager=(0,_lifecycle.getRouterLifecycleManager)();lifecycleManager.register(config.hooks);_logger.logger.debug("路由生命周期钩子已注册")}if(!config.routes){throw new _errors.RouterError("路由配置不能为空",_errors.RouterErrorCode.ROUTER_CONFIG_ERROR)}this.preloader.updateConfig(config.preload);this.preloader.clear();let result;const cacheKey=config.routes;const cachedResult=this.cache.get(cacheKey);if(cachedResult){_logger.logger.debug("使用缓存的路由转换结果");result=cachedResult}else{await this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.BEFORE_TRANSFORM,{config});result=await (0,_transform.transformRoutes)(config.routes,config.transformOptions);await this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.AFTER_TRANSFORM,{config,routes:result.routes});this.cache.set(cacheKey,result)}const enableHydrateFallback=config.enableHydrateFallback??Boolean(config.options?.hydrationData);const reactRoutes=await (0,_transform1.transformRoutesToReactRoutes)(result.routes,result,config.defaultRouteErrorComponent,config.defaultRouteLoadingComponent,enableHydrateFallback);if(result.routes){this.preloader.registerRoutes(result.routes,result);this.preloader.startPreload()}await this.resolveInitialLazyRoutes(reactRoutes,!enableHydrateFallback);let routerInstance=null;if(config.mode==="browser"){routerInstance=(0,_reactrouterdom.createBrowserRouter)(reactRoutes,config.options)}else if(config.mode==="hash"){routerInstance=(0,_reactrouterdom.createHashRouter)(reactRoutes,config.options)}else if(config.mode==="memory"){routerInstance=(0,_reactrouterdom.createMemoryRouter)(reactRoutes,config.options)}if(!routerInstance){throw new _errors.RouterError("路由模式不支持",_errors.RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{mode:config.mode})}this.router=routerInstance;this.initialized=true;await this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.AFTER_INIT,{config,routes:result.routes});const initialPath=typeof window!=="undefined"?`${window.location.pathname}${window.location.search}${window.location.hash}`:this.router?.state?.location?.pathname??"/";this.monitoring.trackRouteAccess({path:initialPath,meta:{name:"router-init"}},undefined,true);_logger.logger.info("路由管理器初始化完成")}async resolveInitialLazyRoutes(routes,resolveAll=false){if(typeof window==="undefined"){return}let targetRoutes=[];if(resolveAll){const stack=[...routes];while(stack.length>0){const current=stack.shift();if(!current){continue}targetRoutes.push(current);if(current.children&&current.children.length>0){stack.push(...current.children)}}}else{const matches=(0,_reactrouterdom.matchRoutes)(routes,window.location.pathname)??[];if(matches.length===0){return}targetRoutes=matches.map(match=>match.route)}await Promise.all(targetRoutes.map(async route=>{const lazy=route.lazy;if(typeof lazy!=="function"){return}try{const resolved=await lazy();Object.assign(route,resolved);delete route.lazy}catch(error){_logger.logger.warn("首屏路由懒加载预解析失败,回退到 Router 默认懒加载",error)}}))}getRouter(){return this.router}isInitialized(){return this.initialized}destroy(){this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.DESTROY,{config:{}});this.preloader.stopPreload();this.router=null;this.initialized=false;const lifecycleManager=(0,_lifecycle.getRouterLifecycleManager)();lifecycleManager.clear();const middlewareManager=(0,_middleware.getRouterMiddlewareManager)();middlewareManager.clear();_logger.logger.info("路由管理器已销毁")}getCache(){return this.cache}getPreloader(){return this.preloader}getPluginManager(){return this.pluginManager}getMonitoring(){return this.monitoring}constructor(){_define_property(this,"router",null);_define_property(this,"initialized",false);_define_property(this,"cache",(0,_RouteCache.getRouteCache)());_define_property(this,"preloader",(0,_RoutePreloader.getRoutePreloader)());_define_property(this,"pluginManager",(0,_plugin.getRouterPluginManager)());_define_property(this,"monitoring",(0,_monitoring.getRouterMonitoring)());_define_property(this,"adapterManager",(0,_adapter.getAdapterManager)());this.adapterManager.register({name:"react-router",factory:(0,_reactrouter.createReactRouterAdapter)(),priority:10})}};_define_property(RouterManager,"instance",null);function getRouterManager(){return RouterManager.getInstance()}
@@ -1,87 +0,0 @@
1
- import type { RouterConfig } from './types';
2
- import { createBrowserRouter } from 'react-router-dom';
3
- export declare class RouterManager {
4
- private static instance;
5
- /**
6
- * 路由实例
7
- * 只能在 initialize 方法中赋值
8
- */
9
- private router;
10
- /**
11
- * 是否已初始化
12
- */
13
- private initialized;
14
- /**
15
- * 路由缓存实例
16
- */
17
- private cache;
18
- /**
19
- * 路由预加载器实例
20
- */
21
- private preloader;
22
- /**
23
- * 路由插件管理器实例
24
- */
25
- private pluginManager;
26
- /**
27
- * 路由监控服务实例
28
- */
29
- private monitoring;
30
- /**
31
- * 路由适配器管理器实例
32
- */
33
- private adapterManager;
34
- private constructor();
35
- /**
36
- * 获取单例实例
37
- */
38
- static getInstance(): RouterManager;
39
- /**
40
- * 初始化路由管理器
41
- *
42
- * @param config - 路由配置
43
- * @param _appInstance - 应用实例(保留用于兼容性,当前未使用)
44
- */
45
- initialize(config: RouterConfig): Promise<void>;
46
- /**
47
- * 预解析 lazy 路由,避免首屏或重定向链路长时间停留在 hydrate fallback。
48
- * resolveAll=true 时会在初始化阶段解析全部 lazy 路由。
49
- */
50
- private resolveInitialLazyRoutes;
51
- /**
52
- * 获取路由实例
53
- *
54
- * @returns 路由实例,如果未初始化则返回 null
55
- */
56
- getRouter(): ReturnType<typeof createBrowserRouter> | null;
57
- /**
58
- * 检查是否已初始化
59
- *
60
- * @returns 如果已初始化返回 true,否则返回 false
61
- */
62
- isInitialized(): boolean;
63
- /**
64
- * 销毁路由管理器
65
- */
66
- destroy(): void;
67
- /**
68
- * 获取路由缓存实例
69
- */
70
- getCache(): import("./performance").RouteCache;
71
- /**
72
- * 获取路由预加载器实例
73
- */
74
- getPreloader(): import("./performance").RoutePreloader;
75
- /**
76
- * 获取路由插件管理器实例
77
- */
78
- getPluginManager(): import("./plugin").RouterPluginManager;
79
- /**
80
- * 获取路由监控服务实例
81
- */
82
- getMonitoring(): import("./monitoring").RouterMonitoring;
83
- }
84
- /**
85
- * 获取路由管理器
86
- */
87
- export declare function getRouterManager(): RouterManager;
@@ -1 +0,0 @@
1
- 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}import{logger}from"@vlian/logger";import{transformRoutes}from"./utils/transform";import{transformRoutesToReactRoutes}from"./utils/adapters/react-router/transform";import{createBrowserRouter,createHashRouter,createMemoryRouter,matchRoutes}from"react-router-dom";import{RouterConfigValidator}from"./validation";import{getRouterLifecycleManager}from"./lifecycle";import{getRouterMiddlewareManager}from"./middleware";import{RouterError,RouterErrorCode}from"./errors";import{getRouteCache}from"./performance/RouteCache";import{getRoutePreloader}from"./performance/RoutePreloader";import{getRouterPluginManager,PluginLifecycleStage}from"./plugin";import{getRouterMonitoring}from"./monitoring";import{getAdapterManager}from"./adapter";import{createReactRouterAdapter}from"./adapter/react-router";export class RouterManager{static getInstance(){if(!RouterManager.instance){RouterManager.instance=new RouterManager}return RouterManager.instance}async initialize(config){if(config.enabled===false||config.enabled==="disabled"){logger.info("路由系统已禁用");return}if(config.enableValidation!==false){try{RouterConfigValidator.validate(config);logger.debug("路由配置验证通过")}catch(error){logger.error("路由配置验证失败",error);if(process.env.NODE_ENV==="development"){throw error}}}await this.pluginManager.executeHooks(PluginLifecycleStage.BEFORE_INIT,{config});if(config.hooks){const lifecycleManager=getRouterLifecycleManager();lifecycleManager.register(config.hooks);logger.debug("路由生命周期钩子已注册")}if(!config.routes){throw new RouterError("路由配置不能为空",RouterErrorCode.ROUTER_CONFIG_ERROR)}this.preloader.updateConfig(config.preload);this.preloader.clear();let result;const cacheKey=config.routes;const cachedResult=this.cache.get(cacheKey);if(cachedResult){logger.debug("使用缓存的路由转换结果");result=cachedResult}else{await this.pluginManager.executeHooks(PluginLifecycleStage.BEFORE_TRANSFORM,{config});result=await transformRoutes(config.routes,config.transformOptions);await this.pluginManager.executeHooks(PluginLifecycleStage.AFTER_TRANSFORM,{config,routes:result.routes});this.cache.set(cacheKey,result)}const enableHydrateFallback=config.enableHydrateFallback??Boolean(config.options?.hydrationData);const reactRoutes=await transformRoutesToReactRoutes(result.routes,result,config.defaultRouteErrorComponent,config.defaultRouteLoadingComponent,enableHydrateFallback);if(result.routes){this.preloader.registerRoutes(result.routes,result);this.preloader.startPreload()}await this.resolveInitialLazyRoutes(reactRoutes,!enableHydrateFallback);let routerInstance=null;if(config.mode==="browser"){routerInstance=createBrowserRouter(reactRoutes,config.options)}else if(config.mode==="hash"){routerInstance=createHashRouter(reactRoutes,config.options)}else if(config.mode==="memory"){routerInstance=createMemoryRouter(reactRoutes,config.options)}if(!routerInstance){throw new RouterError("路由模式不支持",RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{mode:config.mode})}this.router=routerInstance;this.initialized=true;await this.pluginManager.executeHooks(PluginLifecycleStage.AFTER_INIT,{config,routes:result.routes});const initialPath=typeof window!=="undefined"?`${window.location.pathname}${window.location.search}${window.location.hash}`:this.router?.state?.location?.pathname??"/";this.monitoring.trackRouteAccess({path:initialPath,meta:{name:"router-init"}},undefined,true);logger.info("路由管理器初始化完成")}async resolveInitialLazyRoutes(routes,resolveAll=false){if(typeof window==="undefined"){return}let targetRoutes=[];if(resolveAll){const stack=[...routes];while(stack.length>0){const current=stack.shift();if(!current){continue}targetRoutes.push(current);if(current.children&&current.children.length>0){stack.push(...current.children)}}}else{const matches=matchRoutes(routes,window.location.pathname)??[];if(matches.length===0){return}targetRoutes=matches.map(match=>match.route)}await Promise.all(targetRoutes.map(async route=>{const lazy=route.lazy;if(typeof lazy!=="function"){return}try{const resolved=await lazy();Object.assign(route,resolved);delete route.lazy}catch(error){logger.warn("首屏路由懒加载预解析失败,回退到 Router 默认懒加载",error)}}))}getRouter(){return this.router}isInitialized(){return this.initialized}destroy(){this.pluginManager.executeHooks(PluginLifecycleStage.DESTROY,{config:{}});this.preloader.stopPreload();this.router=null;this.initialized=false;const lifecycleManager=getRouterLifecycleManager();lifecycleManager.clear();const middlewareManager=getRouterMiddlewareManager();middlewareManager.clear();logger.info("路由管理器已销毁")}getCache(){return this.cache}getPreloader(){return this.preloader}getPluginManager(){return this.pluginManager}getMonitoring(){return this.monitoring}constructor(){_define_property(this,"router",null);_define_property(this,"initialized",false);_define_property(this,"cache",getRouteCache());_define_property(this,"preloader",getRoutePreloader());_define_property(this,"pluginManager",getRouterPluginManager());_define_property(this,"monitoring",getRouterMonitoring());_define_property(this,"adapterManager",getAdapterManager());this.adapterManager.register({name:"react-router",factory:createReactRouterAdapter(),priority:10})}}_define_property(RouterManager,"instance",null);export function getRouterManager(){return RouterManager.getInstance()}
@@ -1 +0,0 @@
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 AdapterManager(){return AdapterManager},get getAdapterManager(){return getAdapterManager}});const _logger=require("@vlian/logger");const _errors=require("../errors");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 AdapterManager=class AdapterManager{register(registration){if(!registration.name){throw new Error("适配器必须提供名称")}if(!registration.factory||typeof registration.factory!=="function"){throw new Error("适配器必须提供工厂函数")}const adapterRegistration={priority:100,enabled:true,...registration};this.adapters.set(registration.name,adapterRegistration);_logger.logger.debug(`路由适配器已注册: ${registration.name}`);if(!this.defaultAdapterName){this.defaultAdapterName=registration.name}return()=>{this.unregister(registration.name)}}registerBatch(registrations){registrations.forEach(registration=>this.register(registration))}unregister(name){if(this.adapters.has(name)){this.adapters.delete(name);_logger.logger.debug(`路由适配器已取消注册: ${name}`);if(this.defaultAdapterName===name){const firstAdapter=Array.from(this.adapters.keys())[0];this.defaultAdapterName=firstAdapter||null}}}async createAdapter(config,name){const adapterName=name||this.defaultAdapterName;if(!adapterName){throw new _errors.RouterError("没有可用的路由适配器",_errors.RouterErrorCode.ROUTER_NOT_INITIALIZED)}const registration=this.adapters.get(adapterName);if(!registration){throw new _errors.RouterError(`路由适配器不存在: ${adapterName}`,_errors.RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{adapterName})}if(!registration.enabled){throw new _errors.RouterError(`路由适配器已禁用: ${adapterName}`,_errors.RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{adapterName})}try{const adapter=await registration.factory(config);if(!adapter||typeof adapter.initialize!=="function"){throw new Error("适配器实例无效")}await adapter.initialize(config);_logger.logger.info(`路由适配器已创建并初始化: ${adapterName}`);return adapter}catch(error){_logger.logger.error(`创建路由适配器失败: ${adapterName}`,error);const errorContext={adapterName};if(error instanceof Error){errorContext.originalError=error}throw new _errors.RouterError(`创建路由适配器失败: ${adapterName}`,_errors.RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,error instanceof Error?error:undefined,errorContext)}}setCurrentAdapter(adapter){if(this.currentAdapter&&this.currentAdapter.destroy){try{this.currentAdapter.destroy()}catch(error){_logger.logger.warn("销毁旧适配器失败",error)}}this.currentAdapter=adapter;_logger.logger.debug(`当前路由适配器已设置: ${adapter.name}`)}getCurrentAdapter(){return this.currentAdapter}setDefaultAdapter(name){if(!this.adapters.has(name)){throw new Error(`适配器不存在: ${name}`)}this.defaultAdapterName=name;_logger.logger.debug(`默认路由适配器已设置: ${name}`)}getDefaultAdapterName(){return this.defaultAdapterName}getAllAdapters(){return Array.from(this.adapters.values())}getEnabledAdapters(){return Array.from(this.adapters.values()).filter(a=>a.enabled!==false)}getAdapter(name){return this.adapters.get(name)}clear(){if(this.currentAdapter&&this.currentAdapter.destroy){try{this.currentAdapter.destroy()}catch(error){_logger.logger.warn("销毁适配器失败",error)}}this.adapters.clear();this.currentAdapter=null;this.defaultAdapterName=null;_logger.logger.debug("所有路由适配器已清空")}getCount(){return this.adapters.size}constructor(){_define_property(this,"adapters",new Map);_define_property(this,"currentAdapter",null);_define_property(this,"defaultAdapterName",null)}};let adapterManagerInstance=null;function getAdapterManager(){if(!adapterManagerInstance){adapterManagerInstance=new AdapterManager}return adapterManagerInstance}
@@ -1,94 +0,0 @@
1
- /**
2
- * 路由适配器管理器
3
- * 负责管理路由适配器的注册、创建和切换
4
- */
5
- import type { IRouterAdapter, AdapterRegistration, RouterAdapterConfig } from './types';
6
- /**
7
- * 路由适配器管理器
8
- */
9
- export declare class AdapterManager {
10
- private adapters;
11
- private currentAdapter;
12
- private defaultAdapterName;
13
- /**
14
- * 注册适配器
15
- *
16
- * @param registration - 适配器注册信息
17
- * @returns 取消注册函数
18
- */
19
- register(registration: AdapterRegistration): () => void;
20
- /**
21
- * 批量注册适配器
22
- *
23
- * @param registrations - 适配器注册信息数组
24
- */
25
- registerBatch(registrations: AdapterRegistration[]): void;
26
- /**
27
- * 取消注册适配器
28
- *
29
- * @param name - 适配器名称
30
- */
31
- unregister(name: string): void;
32
- /**
33
- * 创建适配器实例
34
- *
35
- * @param name - 适配器名称(可选,使用默认适配器)
36
- * @param config - 适配器配置
37
- * @returns 适配器实例
38
- */
39
- createAdapter(config: RouterAdapterConfig, name?: string): Promise<IRouterAdapter>;
40
- /**
41
- * 设置当前适配器
42
- *
43
- * @param adapter - 适配器实例
44
- */
45
- setCurrentAdapter(adapter: IRouterAdapter): void;
46
- /**
47
- * 获取当前适配器
48
- *
49
- * @returns 当前适配器实例,如果不存在返回 null
50
- */
51
- getCurrentAdapter(): IRouterAdapter | null;
52
- /**
53
- * 设置默认适配器
54
- *
55
- * @param name - 适配器名称
56
- */
57
- setDefaultAdapter(name: string): void;
58
- /**
59
- * 获取默认适配器名称
60
- *
61
- * @returns 默认适配器名称
62
- */
63
- getDefaultAdapterName(): string | null;
64
- /**
65
- * 获取所有适配器
66
- *
67
- * @returns 适配器注册信息数组
68
- */
69
- getAllAdapters(): AdapterRegistration[];
70
- /**
71
- * 获取启用的适配器
72
- *
73
- * @returns 启用的适配器注册信息数组
74
- */
75
- getEnabledAdapters(): AdapterRegistration[];
76
- /**
77
- * 获取适配器
78
- *
79
- * @param name - 适配器名称
80
- * @returns 适配器注册信息,如果不存在返回 undefined
81
- */
82
- getAdapter(name: string): AdapterRegistration | undefined;
83
- /**
84
- * 清空所有适配器
85
- */
86
- clear(): void;
87
- /**
88
- * 获取适配器数量
89
- *
90
- * @returns 适配器数量
91
- */
92
- getCount(): number;
93
- }
94
- export declare function getAdapterManager(): AdapterManager;
@@ -1 +0,0 @@
1
- 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}import{logger}from"@vlian/logger";import{RouterError,RouterErrorCode}from"../errors";export class AdapterManager{register(registration){if(!registration.name){throw new Error("适配器必须提供名称")}if(!registration.factory||typeof registration.factory!=="function"){throw new Error("适配器必须提供工厂函数")}const adapterRegistration={priority:100,enabled:true,...registration};this.adapters.set(registration.name,adapterRegistration);logger.debug(`路由适配器已注册: ${registration.name}`);if(!this.defaultAdapterName){this.defaultAdapterName=registration.name}return()=>{this.unregister(registration.name)}}registerBatch(registrations){registrations.forEach(registration=>this.register(registration))}unregister(name){if(this.adapters.has(name)){this.adapters.delete(name);logger.debug(`路由适配器已取消注册: ${name}`);if(this.defaultAdapterName===name){const firstAdapter=Array.from(this.adapters.keys())[0];this.defaultAdapterName=firstAdapter||null}}}async createAdapter(config,name){const adapterName=name||this.defaultAdapterName;if(!adapterName){throw new RouterError("没有可用的路由适配器",RouterErrorCode.ROUTER_NOT_INITIALIZED)}const registration=this.adapters.get(adapterName);if(!registration){throw new RouterError(`路由适配器不存在: ${adapterName}`,RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{adapterName})}if(!registration.enabled){throw new RouterError(`路由适配器已禁用: ${adapterName}`,RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{adapterName})}try{const adapter=await registration.factory(config);if(!adapter||typeof adapter.initialize!=="function"){throw new Error("适配器实例无效")}await adapter.initialize(config);logger.info(`路由适配器已创建并初始化: ${adapterName}`);return adapter}catch(error){logger.error(`创建路由适配器失败: ${adapterName}`,error);const errorContext={adapterName};if(error instanceof Error){errorContext.originalError=error}throw new RouterError(`创建路由适配器失败: ${adapterName}`,RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,error instanceof Error?error:undefined,errorContext)}}setCurrentAdapter(adapter){if(this.currentAdapter&&this.currentAdapter.destroy){try{this.currentAdapter.destroy()}catch(error){logger.warn("销毁旧适配器失败",error)}}this.currentAdapter=adapter;logger.debug(`当前路由适配器已设置: ${adapter.name}`)}getCurrentAdapter(){return this.currentAdapter}setDefaultAdapter(name){if(!this.adapters.has(name)){throw new Error(`适配器不存在: ${name}`)}this.defaultAdapterName=name;logger.debug(`默认路由适配器已设置: ${name}`)}getDefaultAdapterName(){return this.defaultAdapterName}getAllAdapters(){return Array.from(this.adapters.values())}getEnabledAdapters(){return Array.from(this.adapters.values()).filter(a=>a.enabled!==false)}getAdapter(name){return this.adapters.get(name)}clear(){if(this.currentAdapter&&this.currentAdapter.destroy){try{this.currentAdapter.destroy()}catch(error){logger.warn("销毁适配器失败",error)}}this.adapters.clear();this.currentAdapter=null;this.defaultAdapterName=null;logger.debug("所有路由适配器已清空")}getCount(){return this.adapters.size}constructor(){_define_property(this,"adapters",new Map);_define_property(this,"currentAdapter",null);_define_property(this,"defaultAdapterName",null)}}let adapterManagerInstance=null;export function getAdapterManager(){if(!adapterManagerInstance){adapterManagerInstance=new AdapterManager}return adapterManagerInstance}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("./types"),exports);_export_star(require("./AdapterManager"),exports);_export_star(require("./react-router"),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,6 +0,0 @@
1
- /**
2
- * 路由适配器模块入口
3
- */
4
- export * from './types';
5
- export * from './AdapterManager';
6
- export * from './react-router';
@@ -1 +0,0 @@
1
- export*from"./types";export*from"./AdapterManager";export*from"./react-router";
@@ -1 +0,0 @@
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 ReactRouterAdapter(){return ReactRouterAdapter},get createReactRouterAdapter(){return createReactRouterAdapter}});const _reactrouterdom=require("react-router-dom");const _transform=require("../../utils/adapters/react-router/transform");const _transform1=require("../../utils/transform");const _logger=require("@vlian/logger");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 ReactRouterAdapter=class ReactRouterAdapter{async initialize(config){const transformResult=await (0,_transform1.transformRoutes)(config.routes);const reactRoutes=await (0,_transform.transformRoutesToReactRoutes)(transformResult.routes,transformResult,config.defaultRouteErrorComponent,config.defaultRouteLoadingComponent,Boolean(config.options?.hydrationData));const mode=config.mode||"browser";if(mode==="browser"){this.router=(0,_reactrouterdom.createBrowserRouter)(reactRoutes,config.options)}else if(mode==="hash"){this.router=(0,_reactrouterdom.createHashRouter)(reactRoutes,config.options)}else if(mode==="memory"){this.router=(0,_reactrouterdom.createMemoryRouter)(reactRoutes,config.options)}else{throw new Error(`不支持的路由模式: ${mode}`)}_logger.logger.debug("React Router 适配器初始化完成")}mount(_app){if(!this.router){throw new Error("适配器未初始化")}_logger.logger.debug("React Router 适配器已挂载")}navigate(to,options){if(!this.router){throw new Error("适配器未初始化")}if(options?.replace){this.router.navigate(to,{replace:true,state:options.state})}else{this.router.navigate(to,{state:options?.state})}}getCurrentRoute(){if(!this.router){throw new Error("适配器未初始化")}const state=this.router.state;const location=state.location;const query={};if(location.search){const params=new URLSearchParams(location.search);params.forEach((value,key)=>{query[key]=value})}return{path:location.pathname+location.hash,query,params:location.state}}getRouter(){return this.router}destroy(){this.router=null;_logger.logger.debug("React Router 适配器已销毁")}constructor(){_define_property(this,"name","react-router");_define_property(this,"version","6.0.0");_define_property(this,"router",null)}};function createReactRouterAdapter(){return _config=>{return new ReactRouterAdapter}}
@@ -1,43 +0,0 @@
1
- /**
2
- * React Router 适配器实现
3
- */
4
- import type { IRouterAdapter, RouterAdapterConfig } from '../types';
5
- import type { RouteLocation, NavigateOptions } from '../../types';
6
- import type { AppInstance } from '../../../startup/AppInstance';
7
- import { createBrowserRouter } from 'react-router-dom';
8
- /**
9
- * React Router 适配器
10
- */
11
- export declare class ReactRouterAdapter implements IRouterAdapter {
12
- readonly name = "react-router";
13
- readonly version = "6.0.0";
14
- private router;
15
- /**
16
- * 初始化适配器
17
- */
18
- initialize(config: RouterAdapterConfig): Promise<void>;
19
- /**
20
- * 挂载到应用实例
21
- */
22
- mount(_app: AppInstance): void;
23
- /**
24
- * 导航到指定路径
25
- */
26
- navigate(to: string, options?: NavigateOptions): void;
27
- /**
28
- * 获取当前路由信息
29
- */
30
- getCurrentRoute(): RouteLocation;
31
- /**
32
- * 获取路由实例(用于 RouterProvider)
33
- */
34
- getRouter(): ReturnType<typeof createBrowserRouter> | null;
35
- /**
36
- * 销毁适配器
37
- */
38
- destroy(): void;
39
- }
40
- /**
41
- * 创建 React Router 适配器工厂函数
42
- */
43
- export declare function createReactRouterAdapter(): (_config: RouterAdapterConfig) => IRouterAdapter;
@@ -1 +0,0 @@
1
- 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}import{createBrowserRouter,createHashRouter,createMemoryRouter}from"react-router-dom";import{transformRoutesToReactRoutes}from"../../utils/adapters/react-router/transform";import{transformRoutes}from"../../utils/transform";import{logger}from"@vlian/logger";export class ReactRouterAdapter{async initialize(config){const transformResult=await transformRoutes(config.routes);const reactRoutes=await transformRoutesToReactRoutes(transformResult.routes,transformResult,config.defaultRouteErrorComponent,config.defaultRouteLoadingComponent,Boolean(config.options?.hydrationData));const mode=config.mode||"browser";if(mode==="browser"){this.router=createBrowserRouter(reactRoutes,config.options)}else if(mode==="hash"){this.router=createHashRouter(reactRoutes,config.options)}else if(mode==="memory"){this.router=createMemoryRouter(reactRoutes,config.options)}else{throw new Error(`不支持的路由模式: ${mode}`)}logger.debug("React Router 适配器初始化完成")}mount(_app){if(!this.router){throw new Error("适配器未初始化")}logger.debug("React Router 适配器已挂载")}navigate(to,options){if(!this.router){throw new Error("适配器未初始化")}if(options?.replace){this.router.navigate(to,{replace:true,state:options.state})}else{this.router.navigate(to,{state:options?.state})}}getCurrentRoute(){if(!this.router){throw new Error("适配器未初始化")}const state=this.router.state;const location=state.location;const query={};if(location.search){const params=new URLSearchParams(location.search);params.forEach((value,key)=>{query[key]=value})}return{path:location.pathname+location.hash,query,params:location.state}}getRouter(){return this.router}destroy(){this.router=null;logger.debug("React Router 适配器已销毁")}constructor(){_define_property(this,"name","react-router");_define_property(this,"version","6.0.0");_define_property(this,"router",null)}}export function createReactRouterAdapter(){return _config=>{return new ReactRouterAdapter}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("./ReactRouterAdapter"),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,4 +0,0 @@
1
- /**
2
- * React Router 适配器模块入口
3
- */
4
- export * from './ReactRouterAdapter';
@@ -1 +0,0 @@
1
- export*from"./ReactRouterAdapter";
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});