@xfe-repo/web-micro 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +61 -0
- package/dist/index.mjs +494 -0
- package/package.json +18 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as _micro_zoe_micro_app from '@micro-zoe/micro-app';
|
|
2
|
+
export * from '@micro-zoe/micro-app';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { LinkProps } from '@xfe-repo/web-router';
|
|
6
|
+
|
|
7
|
+
type MicroAppProps = {
|
|
8
|
+
name: string;
|
|
9
|
+
baseRoute?: string;
|
|
10
|
+
url: string;
|
|
11
|
+
keepAlive?: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
data?: Record<string, any>;
|
|
14
|
+
loadingFallback?: React.ReactNode;
|
|
15
|
+
errorFallback?: React.ReactNode;
|
|
16
|
+
};
|
|
17
|
+
declare const MicroAppRoute: React.MemoExoticComponent<(props: MicroAppProps) => react_jsx_runtime.JSX.Element>;
|
|
18
|
+
|
|
19
|
+
type MicroAppLinkProps = LinkProps & {
|
|
20
|
+
to?: string;
|
|
21
|
+
microApp?: string;
|
|
22
|
+
};
|
|
23
|
+
declare const MicroAppLink: React.MemoExoticComponent<(props: MicroAppLinkProps) => react_jsx_runtime.JSX.Element>;
|
|
24
|
+
|
|
25
|
+
declare enum MicroAppEventEnum {
|
|
26
|
+
DISPATCH_ACTION = "dispatchAction"
|
|
27
|
+
}
|
|
28
|
+
type MicroAppActionMetaType = {
|
|
29
|
+
source: string;
|
|
30
|
+
target: string;
|
|
31
|
+
transId: string;
|
|
32
|
+
error?: any;
|
|
33
|
+
};
|
|
34
|
+
type MicroAppActionType = {
|
|
35
|
+
type: string;
|
|
36
|
+
payload?: any;
|
|
37
|
+
meta?: MicroAppActionMetaType;
|
|
38
|
+
};
|
|
39
|
+
type MicroAppDispatchListener = (action: MicroAppActionType) => any | Promise<any>;
|
|
40
|
+
type MicroAppGlobalDataType = {
|
|
41
|
+
eventType: MicroAppEventEnum;
|
|
42
|
+
action?: MicroAppActionType;
|
|
43
|
+
};
|
|
44
|
+
type MicroAppEventCenterConfig = {
|
|
45
|
+
name: string;
|
|
46
|
+
isMain?: boolean;
|
|
47
|
+
};
|
|
48
|
+
declare class MicroAppEventCenter {
|
|
49
|
+
constructor(config: MicroAppEventCenterConfig);
|
|
50
|
+
private readonly config;
|
|
51
|
+
private readonly dispatchListeners;
|
|
52
|
+
private listener;
|
|
53
|
+
private emitDispatchListener;
|
|
54
|
+
dispatch(target: string, action: MicroAppActionType): Promise<any>;
|
|
55
|
+
addDispatchListener(type: string, listener: MicroAppDispatchListener): void;
|
|
56
|
+
removeDispatchListener(type: string, listener?: MicroAppDispatchListener): boolean | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare const microApp: _micro_zoe_micro_app.MicroApp;
|
|
60
|
+
|
|
61
|
+
export { type MicroAppActionMetaType, type MicroAppActionType, type MicroAppDispatchListener, MicroAppEventCenter, type MicroAppEventCenterConfig, MicroAppEventEnum, type MicroAppGlobalDataType, MicroAppLink, type MicroAppProps, MicroAppRoute, microApp };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_with_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return arr;
|
|
9
|
+
}
|
|
10
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
11
|
+
try {
|
|
12
|
+
var info = gen[key](arg);
|
|
13
|
+
var value = info.value;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
reject(error);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (info.done) {
|
|
19
|
+
resolve(value);
|
|
20
|
+
} else {
|
|
21
|
+
Promise.resolve(value).then(_next, _throw);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _async_to_generator(fn) {
|
|
25
|
+
return function() {
|
|
26
|
+
var self = this, args = arguments;
|
|
27
|
+
return new Promise(function(resolve, reject) {
|
|
28
|
+
var gen = fn.apply(self, args);
|
|
29
|
+
function _next(value) {
|
|
30
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
31
|
+
}
|
|
32
|
+
function _throw(err) {
|
|
33
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
34
|
+
}
|
|
35
|
+
_next(undefined);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function _class_call_check(instance, Constructor) {
|
|
40
|
+
if (!(instance instanceof Constructor)) {
|
|
41
|
+
throw new TypeError("Cannot call a class as a function");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function _defineProperties(target, props) {
|
|
45
|
+
for(var i = 0; i < props.length; i++){
|
|
46
|
+
var descriptor = props[i];
|
|
47
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
48
|
+
descriptor.configurable = true;
|
|
49
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
50
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
54
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
55
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
56
|
+
return Constructor;
|
|
57
|
+
}
|
|
58
|
+
function _define_property(obj, key, value) {
|
|
59
|
+
if (key in obj) {
|
|
60
|
+
Object.defineProperty(obj, key, {
|
|
61
|
+
value: value,
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
obj[key] = value;
|
|
68
|
+
}
|
|
69
|
+
return obj;
|
|
70
|
+
}
|
|
71
|
+
function _iterable_to_array_limit(arr, i) {
|
|
72
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
73
|
+
if (_i == null) return;
|
|
74
|
+
var _arr = [];
|
|
75
|
+
var _n = true;
|
|
76
|
+
var _d = false;
|
|
77
|
+
var _s, _e;
|
|
78
|
+
try {
|
|
79
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
80
|
+
_arr.push(_s.value);
|
|
81
|
+
if (i && _arr.length === i) break;
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
_d = true;
|
|
85
|
+
_e = err;
|
|
86
|
+
} finally{
|
|
87
|
+
try {
|
|
88
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
89
|
+
} finally{
|
|
90
|
+
if (_d) throw _e;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return _arr;
|
|
94
|
+
}
|
|
95
|
+
function _non_iterable_rest() {
|
|
96
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
97
|
+
}
|
|
98
|
+
function _object_spread(target) {
|
|
99
|
+
for(var i = 1; i < arguments.length; i++){
|
|
100
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
101
|
+
var ownKeys = Object.keys(source);
|
|
102
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
103
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
104
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
ownKeys.forEach(function(key) {
|
|
108
|
+
_define_property(target, key, source[key]);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return target;
|
|
112
|
+
}
|
|
113
|
+
function _sliced_to_array(arr, i) {
|
|
114
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
115
|
+
}
|
|
116
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
117
|
+
if (!o) return;
|
|
118
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
119
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
120
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
121
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
122
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
123
|
+
}
|
|
124
|
+
function _ts_generator(thisArg, body) {
|
|
125
|
+
var f, y, t, g, _ = {
|
|
126
|
+
label: 0,
|
|
127
|
+
sent: function() {
|
|
128
|
+
if (t[0] & 1) throw t[1];
|
|
129
|
+
return t[1];
|
|
130
|
+
},
|
|
131
|
+
trys: [],
|
|
132
|
+
ops: []
|
|
133
|
+
};
|
|
134
|
+
return g = {
|
|
135
|
+
next: verb(0),
|
|
136
|
+
"throw": verb(1),
|
|
137
|
+
"return": verb(2)
|
|
138
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
139
|
+
return this;
|
|
140
|
+
}), g;
|
|
141
|
+
function verb(n) {
|
|
142
|
+
return function(v) {
|
|
143
|
+
return step([
|
|
144
|
+
n,
|
|
145
|
+
v
|
|
146
|
+
]);
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function step(op) {
|
|
150
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
151
|
+
while(_)try {
|
|
152
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
153
|
+
if (y = 0, t) op = [
|
|
154
|
+
op[0] & 2,
|
|
155
|
+
t.value
|
|
156
|
+
];
|
|
157
|
+
switch(op[0]){
|
|
158
|
+
case 0:
|
|
159
|
+
case 1:
|
|
160
|
+
t = op;
|
|
161
|
+
break;
|
|
162
|
+
case 4:
|
|
163
|
+
_.label++;
|
|
164
|
+
return {
|
|
165
|
+
value: op[1],
|
|
166
|
+
done: false
|
|
167
|
+
};
|
|
168
|
+
case 5:
|
|
169
|
+
_.label++;
|
|
170
|
+
y = op[1];
|
|
171
|
+
op = [
|
|
172
|
+
0
|
|
173
|
+
];
|
|
174
|
+
continue;
|
|
175
|
+
case 7:
|
|
176
|
+
op = _.ops.pop();
|
|
177
|
+
_.trys.pop();
|
|
178
|
+
continue;
|
|
179
|
+
default:
|
|
180
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
181
|
+
_ = 0;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
185
|
+
_.label = op[1];
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
189
|
+
_.label = t[1];
|
|
190
|
+
t = op;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
if (t && _.label < t[2]) {
|
|
194
|
+
_.label = t[2];
|
|
195
|
+
_.ops.push(op);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
if (t[2]) _.ops.pop();
|
|
199
|
+
_.trys.pop();
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
op = body.call(thisArg, _);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
op = [
|
|
205
|
+
6,
|
|
206
|
+
e
|
|
207
|
+
];
|
|
208
|
+
y = 0;
|
|
209
|
+
} finally{
|
|
210
|
+
f = t = 0;
|
|
211
|
+
}
|
|
212
|
+
if (op[0] & 5) throw op[1];
|
|
213
|
+
return {
|
|
214
|
+
value: op[0] ? op[1] : void 0,
|
|
215
|
+
done: true
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
import originMicroApp, { EventCenterForMicroApp } from "@micro-zoe/micro-app";
|
|
220
|
+
import { isProduction } from "@xfe-repo/web-utils/env";
|
|
221
|
+
import { uuid } from "@xfe-repo/web-utils/tools";
|
|
222
|
+
export * from "@micro-zoe/micro-app";
|
|
223
|
+
// src/MicroAppRoute.tsx
|
|
224
|
+
import { memo, useCallback, useState } from "react";
|
|
225
|
+
import { useNavigate, useLocation } from "@xfe-repo/web-router";
|
|
226
|
+
import microApp from "@micro-zoe/micro-app";
|
|
227
|
+
import jsxCustomEvent from "@micro-zoe/micro-app/polyfill/jsx-custom-event.js";
|
|
228
|
+
var MicroAppRoute = memo(function(props) {
|
|
229
|
+
var name = props.name, baseRoute = props.baseRoute, url = props.url, keepAlive = props.keepAlive, className = props.className, data = props.data, loadingFallback = props.loadingFallback, errorFallback = props.errorFallback;
|
|
230
|
+
var navigate = useNavigate();
|
|
231
|
+
var location = useLocation();
|
|
232
|
+
var _useState = _sliced_to_array(useState(false), 2), microAppIsShow = _useState[0], setMicroAppIsShow = _useState[1];
|
|
233
|
+
var _useState1 = _sliced_to_array(useState(false), 2), microAppIsError = _useState1[0], setMicroAppIsError = _useState1[1];
|
|
234
|
+
var handleMicroAppMounted = useCallback(function() {
|
|
235
|
+
var path = location.pathname + location.search;
|
|
236
|
+
navigate(path, {
|
|
237
|
+
replace: true
|
|
238
|
+
});
|
|
239
|
+
setMicroAppIsShow(true);
|
|
240
|
+
}, [
|
|
241
|
+
location
|
|
242
|
+
]);
|
|
243
|
+
var handleMicroAppAfterShow = useCallback(function() {
|
|
244
|
+
var path = location.pathname + location.search;
|
|
245
|
+
microApp.router.push({
|
|
246
|
+
name: "dashboard",
|
|
247
|
+
path: path,
|
|
248
|
+
replace: true
|
|
249
|
+
}).catch(function(e) {
|
|
250
|
+
return console.error(e);
|
|
251
|
+
});
|
|
252
|
+
setMicroAppIsShow(true);
|
|
253
|
+
}, [
|
|
254
|
+
location
|
|
255
|
+
]);
|
|
256
|
+
var handleMicroAppError = useCallback(function() {
|
|
257
|
+
setMicroAppIsError(true);
|
|
258
|
+
}, []);
|
|
259
|
+
return /* @__PURE__ */ jsxCustomEvent("div", {
|
|
260
|
+
className: className
|
|
261
|
+
}, microAppIsError && errorFallback, !microAppIsShow && !microAppIsError && loadingFallback, /* @__PURE__ */ jsxCustomEvent("micro-app", {
|
|
262
|
+
style: {
|
|
263
|
+
width: "100%",
|
|
264
|
+
height: "100%",
|
|
265
|
+
display: microAppIsShow ? "block" : "none"
|
|
266
|
+
},
|
|
267
|
+
url: url,
|
|
268
|
+
name: name,
|
|
269
|
+
"router-mode": "native",
|
|
270
|
+
baseroute: baseRoute ? baseRoute : "/".concat(name),
|
|
271
|
+
"keep-alive": keepAlive,
|
|
272
|
+
data: data,
|
|
273
|
+
onMounted: handleMicroAppMounted,
|
|
274
|
+
onAftershow: keepAlive ? handleMicroAppAfterShow : void 0,
|
|
275
|
+
onError: handleMicroAppError
|
|
276
|
+
}));
|
|
277
|
+
});
|
|
278
|
+
// src/MicroAppLink.tsx
|
|
279
|
+
import { memo as memo2, useCallback as useCallback2 } from "react";
|
|
280
|
+
import { useNavigate as useNavigate2 } from "@xfe-repo/web-router";
|
|
281
|
+
import { jsx } from "react/jsx-runtime";
|
|
282
|
+
var MicroAppLink = memo2(function(props) {
|
|
283
|
+
var microAppBaseName = props.microApp, to = props.to, children = props.children, replace = props.replace, className = props.className;
|
|
284
|
+
var navigate = useNavigate2();
|
|
285
|
+
var handleLink = useCallback2(function(e) {
|
|
286
|
+
e.preventDefault();
|
|
287
|
+
navigate(to, {
|
|
288
|
+
replace: replace
|
|
289
|
+
});
|
|
290
|
+
if (!microAppBaseName) return;
|
|
291
|
+
var activeApps = microApp2.getActiveApps({
|
|
292
|
+
excludeHiddenApp: true
|
|
293
|
+
});
|
|
294
|
+
if (activeApps.includes(microAppBaseName)) microApp2.router.push({
|
|
295
|
+
name: microAppBaseName,
|
|
296
|
+
path: to,
|
|
297
|
+
replace: replace
|
|
298
|
+
}).catch(function(e2) {
|
|
299
|
+
return e2;
|
|
300
|
+
});
|
|
301
|
+
}, [
|
|
302
|
+
navigate,
|
|
303
|
+
microAppBaseName,
|
|
304
|
+
to,
|
|
305
|
+
replace
|
|
306
|
+
]);
|
|
307
|
+
return /* @__PURE__ */ jsx("a", {
|
|
308
|
+
className: className,
|
|
309
|
+
href: to,
|
|
310
|
+
onClick: handleLink,
|
|
311
|
+
children: children
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
// src/index.ts
|
|
315
|
+
var MicroAppEventEnum = /* @__PURE__ */ function(MicroAppEventEnum2) {
|
|
316
|
+
MicroAppEventEnum2["DISPATCH_ACTION"] = "dispatchAction";
|
|
317
|
+
return MicroAppEventEnum2;
|
|
318
|
+
}(MicroAppEventEnum || {});
|
|
319
|
+
var MicroAppEventCenter = /*#__PURE__*/ function() {
|
|
320
|
+
"use strict";
|
|
321
|
+
function MicroAppEventCenter(config) {
|
|
322
|
+
var _this = this;
|
|
323
|
+
_class_call_check(this, MicroAppEventCenter);
|
|
324
|
+
this.dispatchListeners = {};
|
|
325
|
+
this.config = config;
|
|
326
|
+
if (config.isMain) window.microGlobalEventCenter = new EventCenterForMicroApp("global");
|
|
327
|
+
if (!window.microGlobalEventCenter) throw new Error("microGlobalEventCenter is not defined, please check if the main app is loaded first");
|
|
328
|
+
window.microGlobalEventCenter.addGlobalDataListener(function(globalData) {
|
|
329
|
+
return _this.listener(globalData);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
_create_class(MicroAppEventCenter, [
|
|
333
|
+
{
|
|
334
|
+
// 监听函数
|
|
335
|
+
key: "listener",
|
|
336
|
+
value: function listener(globalData) {
|
|
337
|
+
var eventType = globalData.eventType, action = globalData.action;
|
|
338
|
+
switch(eventType){
|
|
339
|
+
case "dispatchAction" /* DISPATCH_ACTION */ :
|
|
340
|
+
this.emitDispatchListener(action);
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
// 触发事件
|
|
347
|
+
key: "emitDispatchListener",
|
|
348
|
+
value: function emitDispatchListener(action) {
|
|
349
|
+
var _this_dispatchListeners_type;
|
|
350
|
+
var name = this.config.name;
|
|
351
|
+
if (!action) return console.error("MicroAppMessage [".concat(name, "]: 未知消息类型 缺少action"));
|
|
352
|
+
var type = action.type, meta = action.meta;
|
|
353
|
+
if (!meta) return console.error("MicroAppMessage [".concat(name, "]: 未知消息类型 缺少meta"), action);
|
|
354
|
+
var source = meta.source, target = meta.target, transId = meta.transId;
|
|
355
|
+
if (source === name) return;
|
|
356
|
+
if (target !== "all" && target !== name) return;
|
|
357
|
+
if (!((_this_dispatchListeners_type = this.dispatchListeners[type]) === null || _this_dispatchListeners_type === void 0 ? void 0 : _this_dispatchListeners_type.length)) return;
|
|
358
|
+
var actionResponseType = "".concat(type, "___").concat(transId, "___response");
|
|
359
|
+
var _this = this;
|
|
360
|
+
this.dispatchListeners[type].forEach(function() {
|
|
361
|
+
var _ref = _async_to_generator(function(listener) {
|
|
362
|
+
var responseAction, error, isBroadcast, isResponse;
|
|
363
|
+
return _ts_generator(this, function(_state) {
|
|
364
|
+
switch(_state.label){
|
|
365
|
+
case 0:
|
|
366
|
+
responseAction = {
|
|
367
|
+
type: actionResponseType,
|
|
368
|
+
meta: {
|
|
369
|
+
source: name,
|
|
370
|
+
target: source,
|
|
371
|
+
transId: transId
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
_state.label = 1;
|
|
375
|
+
case 1:
|
|
376
|
+
_state.trys.push([
|
|
377
|
+
1,
|
|
378
|
+
3,
|
|
379
|
+
,
|
|
380
|
+
4
|
|
381
|
+
]);
|
|
382
|
+
return [
|
|
383
|
+
4,
|
|
384
|
+
listener(action)
|
|
385
|
+
];
|
|
386
|
+
case 2:
|
|
387
|
+
responseAction.payload = _state.sent();
|
|
388
|
+
return [
|
|
389
|
+
3,
|
|
390
|
+
4
|
|
391
|
+
];
|
|
392
|
+
case 3:
|
|
393
|
+
error = _state.sent();
|
|
394
|
+
if (responseAction.meta) responseAction.meta.error = error;
|
|
395
|
+
return [
|
|
396
|
+
3,
|
|
397
|
+
4
|
|
398
|
+
];
|
|
399
|
+
case 4:
|
|
400
|
+
isBroadcast = target === "all";
|
|
401
|
+
isResponse = type.endsWith("___response");
|
|
402
|
+
if (isBroadcast || isResponse) return [
|
|
403
|
+
2
|
|
404
|
+
];
|
|
405
|
+
return [
|
|
406
|
+
4,
|
|
407
|
+
_this.dispatch(source, responseAction)
|
|
408
|
+
];
|
|
409
|
+
case 5:
|
|
410
|
+
_state.sent();
|
|
411
|
+
return [
|
|
412
|
+
2
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
return function(listener) {
|
|
418
|
+
return _ref.apply(this, arguments);
|
|
419
|
+
};
|
|
420
|
+
}());
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
key: "dispatch",
|
|
425
|
+
value: // 远程调用
|
|
426
|
+
function dispatch(target, action) {
|
|
427
|
+
var _this = this;
|
|
428
|
+
return _async_to_generator(function() {
|
|
429
|
+
var name, type, payload, meta, transId, newAction, globalData, isBroadcast, isResponse, actionResponseType, actionResponsePromise;
|
|
430
|
+
return _ts_generator(this, function(_state) {
|
|
431
|
+
name = _this.config.name;
|
|
432
|
+
type = action.type, payload = action.payload, meta = action.meta;
|
|
433
|
+
transId = (meta === null || meta === void 0 ? void 0 : meta.transId) || uuid();
|
|
434
|
+
newAction = {
|
|
435
|
+
type: type,
|
|
436
|
+
payload: payload,
|
|
437
|
+
meta: _object_spread({
|
|
438
|
+
source: name,
|
|
439
|
+
target: target,
|
|
440
|
+
transId: transId
|
|
441
|
+
}, meta)
|
|
442
|
+
};
|
|
443
|
+
globalData = {
|
|
444
|
+
eventType: "dispatchAction" /* DISPATCH_ACTION */ ,
|
|
445
|
+
action: newAction
|
|
446
|
+
};
|
|
447
|
+
if (!isProduction) console.log("MicroAppMessage [".concat(name, "]: dispatch ").concat(type, " to [").concat(target, "]"), globalData);
|
|
448
|
+
isBroadcast = target === "all";
|
|
449
|
+
isResponse = type.endsWith("___response");
|
|
450
|
+
if (isBroadcast || isResponse) return [
|
|
451
|
+
2,
|
|
452
|
+
window.microGlobalEventCenter.forceSetGlobalData(globalData)
|
|
453
|
+
];
|
|
454
|
+
actionResponseType = "".concat(type, "___").concat(transId, "___response");
|
|
455
|
+
actionResponsePromise = new Promise(function(resolve, reject) {
|
|
456
|
+
var listener = function(responseAction) {
|
|
457
|
+
var payload2 = responseAction.payload, meta2 = responseAction.meta;
|
|
458
|
+
(meta2 === null || meta2 === void 0 ? void 0 : meta2.error) ? reject(meta2.error) : resolve(payload2);
|
|
459
|
+
_this.removeDispatchListener(actionResponseType, listener);
|
|
460
|
+
};
|
|
461
|
+
_this.addDispatchListener(actionResponseType, listener);
|
|
462
|
+
});
|
|
463
|
+
window.microGlobalEventCenter.forceSetGlobalData(globalData);
|
|
464
|
+
return [
|
|
465
|
+
2,
|
|
466
|
+
actionResponsePromise
|
|
467
|
+
];
|
|
468
|
+
});
|
|
469
|
+
})();
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
// 添加监听
|
|
474
|
+
key: "addDispatchListener",
|
|
475
|
+
value: function addDispatchListener(type, listener) {
|
|
476
|
+
if (!this.dispatchListeners[type]) this.dispatchListeners[type] = [];
|
|
477
|
+
this.dispatchListeners[type].push(listener);
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
// 移除监听 如果不传listener则移除所有监听
|
|
482
|
+
key: "removeDispatchListener",
|
|
483
|
+
value: function removeDispatchListener(type, listener) {
|
|
484
|
+
if (!this.dispatchListeners[type]) return;
|
|
485
|
+
if (!listener) return delete this.dispatchListeners[type];
|
|
486
|
+
var index = this.dispatchListeners[type].indexOf(listener);
|
|
487
|
+
if (index !== -1) this.dispatchListeners[type].splice(index, 1);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
]);
|
|
491
|
+
return MicroAppEventCenter;
|
|
492
|
+
}();
|
|
493
|
+
var microApp2 = originMicroApp;
|
|
494
|
+
export { MicroAppEventCenter, MicroAppEventEnum, MicroAppLink, MicroAppRoute, microApp2 as microApp };
|
package/package.json
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-micro",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
7
19
|
"files": [
|
|
8
20
|
"dist"
|
|
9
21
|
],
|
|
10
22
|
"dependencies": {
|
|
11
23
|
"@micro-zoe/micro-app": "1.0.0-rc.13",
|
|
12
|
-
"@xfe-repo/web-router": "1.2.
|
|
13
|
-
"@xfe-repo/web-utils": "1.
|
|
24
|
+
"@xfe-repo/web-router": "1.2.2",
|
|
25
|
+
"@xfe-repo/web-utils": "1.3.5"
|
|
14
26
|
},
|
|
15
27
|
"devDependencies": {
|
|
16
28
|
"@types/node": "^20.16.5",
|
|
@@ -18,6 +30,9 @@
|
|
|
18
30
|
"@xfe-repo/eslint-config": "0.0.5",
|
|
19
31
|
"@xfe-repo/typescript-config": "0.0.6"
|
|
20
32
|
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
},
|
|
21
36
|
"scripts": {
|
|
22
37
|
"build": "tsup",
|
|
23
38
|
"dev": "tsup --watch",
|