@ice/mf-runtime 1.0.3-beta.2 → 1.0.3-beta.3

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.
@@ -1,201 +0,0 @@
1
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
5
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
- import * as React from "react";
7
- /**
8
- * 增强插件管理器 - 专门负责管理和执行增强运行时插件
9
- * 标准 MF 插件交由底层 @module-federation/runtime 管理
10
- */ export var EnhancedPluginManager = /*#__PURE__*/ function() {
11
- "use strict";
12
- function EnhancedPluginManager() {
13
- _class_call_check(this, EnhancedPluginManager);
14
- _define_property(this, "plugins", []);
15
- }
16
- _create_class(EnhancedPluginManager, [
17
- {
18
- /**
19
- * 注册增强插件
20
- * @param plugin 增强运行时插件
21
- */ key: "register",
22
- value: function register(plugin) {
23
- // 检查是否已存在同名插件
24
- var existingIndex = this.plugins.findIndex(function(p) {
25
- return p.name === plugin.name;
26
- });
27
- if (existingIndex >= 0) {
28
- console.warn('Enhanced plugin "'.concat(plugin.name, '" already exists, replacing it.'));
29
- this.plugins[existingIndex] = plugin;
30
- } else {
31
- this.plugins.push(plugin);
32
- }
33
- }
34
- },
35
- {
36
- /**
37
- * 注册多个增强插件
38
- * @param plugins 增强插件数组
39
- */ key: "registerPlugins",
40
- value: function registerPlugins(plugins) {
41
- var _this = this;
42
- plugins.forEach(function(plugin) {
43
- return _this.register(plugin);
44
- });
45
- }
46
- },
47
- {
48
- /**
49
- * 获取所有增强插件列表
50
- * @returns 增强插件数组
51
- */ key: "getPlugins",
52
- value: function getPlugins() {
53
- return _to_consumable_array(this.plugins);
54
- }
55
- },
56
- {
57
- /**
58
- * 应用组件包装器
59
- * 按插件注册顺序依次应用所有组件包装器
60
- * @param Component 原始组件
61
- * @param context 包装器上下文
62
- * @returns 包装后的组件
63
- */ key: "wrapComponent",
64
- value: function wrapComponent(Component, context) {
65
- var WrappedComponent = Component;
66
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
67
- try {
68
- // 按数组顺序依次应用所有组件包装器
69
- for(var _iterator = this.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
70
- var plugin = _step.value;
71
- if (plugin.wrapComponent) {
72
- try {
73
- WrappedComponent = plugin.wrapComponent(WrappedComponent, context);
74
- } catch (error) {
75
- console.error('Error applying wrapper from plugin "'.concat(plugin.name, '":'), error);
76
- }
77
- }
78
- }
79
- } catch (err) {
80
- _didIteratorError = true;
81
- _iteratorError = err;
82
- } finally{
83
- try {
84
- if (!_iteratorNormalCompletion && _iterator.return != null) {
85
- _iterator.return();
86
- }
87
- } finally{
88
- if (_didIteratorError) {
89
- throw _iteratorError;
90
- }
91
- }
92
- }
93
- return WrappedComponent;
94
- }
95
- },
96
- {
97
- /**
98
- * 注入属性
99
- * 按插件注册顺序依次应用所有属性注入器
100
- * @param props 原始属性
101
- * @param context 注入上下文
102
- * @returns 注入后的属性
103
- */ key: "injectProps",
104
- value: function injectProps(props, context) {
105
- var injectedProps = _object_spread({}, props);
106
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
107
- try {
108
- // 按数组顺序依次应用所有属性注入器
109
- for(var _iterator = this.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
110
- var plugin = _step.value;
111
- if (plugin.injectProps) {
112
- try {
113
- injectedProps = plugin.injectProps(injectedProps, context);
114
- } catch (error) {
115
- console.error('Error injecting props from plugin "'.concat(plugin.name, '":'), error);
116
- }
117
- }
118
- }
119
- } catch (err) {
120
- _didIteratorError = true;
121
- _iteratorError = err;
122
- } finally{
123
- try {
124
- if (!_iteratorNormalCompletion && _iterator.return != null) {
125
- _iterator.return();
126
- }
127
- } finally{
128
- if (_didIteratorError) {
129
- throw _iteratorError;
130
- }
131
- }
132
- }
133
- return injectedProps;
134
- }
135
- },
136
- {
137
- /**
138
- * 获取所有插件信息
139
- * @returns 插件信息数组
140
- */ key: "getPluginInfo",
141
- value: function getPluginInfo() {
142
- return this.plugins.map(function(plugin) {
143
- return {
144
- name: plugin.name,
145
- hasWrapper: !!plugin.wrapComponent,
146
- hasInjector: !!plugin.injectProps
147
- };
148
- });
149
- }
150
- },
151
- {
152
- /**
153
- * 移除插件
154
- * @param name 插件名称
155
- * @returns 是否成功移除
156
- */ key: "removePlugin",
157
- value: function removePlugin(name) {
158
- var index = this.plugins.findIndex(function(p) {
159
- return p.name === name;
160
- });
161
- if (index !== -1) {
162
- this.plugins.splice(index, 1);
163
- return true;
164
- }
165
- return false;
166
- }
167
- },
168
- {
169
- /**
170
- * 清空所有插件
171
- */ key: "clear",
172
- value: function clear() {
173
- this.plugins = [];
174
- }
175
- }
176
- ]);
177
- return EnhancedPluginManager;
178
- }();
179
- // 全局增强插件管理器实例
180
- var globalEnhancedPluginManager = null;
181
- /**
182
- * 获取全局增强插件管理器实例
183
- * @returns 增强插件管理器实例
184
- */ export function getEnhancedPluginManager() {
185
- if (!globalEnhancedPluginManager) {
186
- globalEnhancedPluginManager = new EnhancedPluginManager();
187
- }
188
- return globalEnhancedPluginManager;
189
- }
190
- /**
191
- * 注册多个增强插件(便捷函数)
192
- * @param plugins 增强插件数组
193
- */ export function registerEnhancedPlugins(plugins) {
194
- getEnhancedPluginManager().registerPlugins(plugins);
195
- }
196
- /**
197
- * React Hook:使用增强插件管理器
198
- * @returns 增强插件管理器实例
199
- */ export function useEnhancedPluginManager() {
200
- return getEnhancedPluginManager();
201
- }