@xfe-repo/web-micro 1.1.4 → 1.1.6
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.ts +1 -8
- package/dist/index.js +3 -26
- package/package.json +4 -16
- package/dist/index.d.mts +0 -60
- package/dist/index.mjs +0 -473
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ type MicroAppProps = {
|
|
|
15
15
|
declare const MicroAppRoute: React.MemoExoticComponent<(props: MicroAppProps) => react_jsx_runtime.JSX.Element>;
|
|
16
16
|
|
|
17
17
|
declare enum MicroAppEventEnum {
|
|
18
|
-
SET_GLOBAL_STATE = "setGlobalState",
|
|
19
18
|
DISPATCH_ACTION = "dispatchAction"
|
|
20
19
|
}
|
|
21
20
|
type MicroAppActionMetaType = {
|
|
@@ -30,24 +29,18 @@ type MicroAppActionType = {
|
|
|
30
29
|
meta?: MicroAppActionMetaType;
|
|
31
30
|
};
|
|
32
31
|
type MicroAppDispatchListener = (action: MicroAppActionType) => any | Promise<any>;
|
|
33
|
-
type MicroAppGlobalStateType = Record<string, string | number | boolean>;
|
|
34
32
|
type MicroAppGlobalDataType = {
|
|
35
33
|
eventType: MicroAppEventEnum;
|
|
36
|
-
globalState?: MicroAppGlobalStateType;
|
|
37
34
|
action?: MicroAppActionType;
|
|
38
35
|
};
|
|
39
36
|
type MicroAppEventCenterConfig = {
|
|
40
37
|
name: string;
|
|
41
38
|
isMain?: boolean;
|
|
42
|
-
onGlobalStateChange?: (globalState: any) => void;
|
|
43
39
|
};
|
|
44
40
|
declare class MicroAppEventCenter {
|
|
45
41
|
constructor(config: MicroAppEventCenterConfig);
|
|
46
42
|
private readonly config;
|
|
47
43
|
private readonly dispatchListeners;
|
|
48
|
-
private _globalState;
|
|
49
|
-
set globalState(globalState: MicroAppGlobalStateType);
|
|
50
|
-
get globalState(): MicroAppGlobalStateType;
|
|
51
44
|
private listener;
|
|
52
45
|
private emitDispatchListener;
|
|
53
46
|
dispatch(target: string, action: MicroAppActionType): Promise<any>;
|
|
@@ -57,4 +50,4 @@ declare class MicroAppEventCenter {
|
|
|
57
50
|
|
|
58
51
|
declare const microApp: _micro_zoe_micro_app.MicroApp;
|
|
59
52
|
|
|
60
|
-
export { type MicroAppActionMetaType, type MicroAppActionType, type MicroAppDispatchListener, MicroAppEventCenter, type MicroAppEventCenterConfig, MicroAppEventEnum, type MicroAppGlobalDataType, type
|
|
53
|
+
export { type MicroAppActionMetaType, type MicroAppActionType, type MicroAppDispatchListener, MicroAppEventCenter, type MicroAppEventCenterConfig, MicroAppEventEnum, type MicroAppGlobalDataType, type MicroAppProps, MicroAppRoute, microApp };
|
package/dist/index.js
CHANGED
|
@@ -330,7 +330,7 @@ var MicroAppRoute = (0, import_react.memo)(function(props) {
|
|
|
330
330
|
}, []);
|
|
331
331
|
return /* @__PURE__ */ (0, import_jsx_custom_event.default)("div", {
|
|
332
332
|
className: className
|
|
333
|
-
}, microAppIsError && errorFallback, !microAppIsShow && loadingFallback, /* @__PURE__ */ (0, import_jsx_custom_event.default)("micro-app", {
|
|
333
|
+
}, microAppIsError && errorFallback, !microAppIsShow && !microAppIsError && loadingFallback, /* @__PURE__ */ (0, import_jsx_custom_event.default)("micro-app", {
|
|
334
334
|
style: {
|
|
335
335
|
display: microAppIsShow ? "block" : "none"
|
|
336
336
|
},
|
|
@@ -347,7 +347,6 @@ var MicroAppRoute = (0, import_react.memo)(function(props) {
|
|
|
347
347
|
});
|
|
348
348
|
// src/index.ts
|
|
349
349
|
var MicroAppEventEnum = /* @__PURE__ */ function(MicroAppEventEnum2) {
|
|
350
|
-
MicroAppEventEnum2["SET_GLOBAL_STATE"] = "setGlobalState";
|
|
351
350
|
MicroAppEventEnum2["DISPATCH_ACTION"] = "dispatchAction";
|
|
352
351
|
return MicroAppEventEnum2;
|
|
353
352
|
}(MicroAppEventEnum || {});
|
|
@@ -356,42 +355,20 @@ var MicroAppEventCenter = /*#__PURE__*/ function() {
|
|
|
356
355
|
var _this = this;
|
|
357
356
|
_class_call_check(this, MicroAppEventCenter);
|
|
358
357
|
this.dispatchListeners = {};
|
|
359
|
-
this._globalState = {};
|
|
360
358
|
this.config = config;
|
|
361
359
|
if (config.isMain) window.microGlobalEventCenter = new import_micro_app2.EventCenterForMicroApp("global");
|
|
360
|
+
if (!window.microGlobalEventCenter) throw new Error("microGlobalEventCenter is not defined, please check if the main app is loaded first");
|
|
362
361
|
window.microGlobalEventCenter.addGlobalDataListener(function(globalData) {
|
|
363
362
|
return _this.listener(globalData);
|
|
364
363
|
});
|
|
365
364
|
}
|
|
366
365
|
_create_class(MicroAppEventCenter, [
|
|
367
|
-
{
|
|
368
|
-
key: "globalState",
|
|
369
|
-
get: function get() {
|
|
370
|
-
return this._globalState;
|
|
371
|
-
},
|
|
372
|
-
set: function set(globalState) {
|
|
373
|
-
var name = this.config.name;
|
|
374
|
-
var newGlobalState = _object_spread({}, globalState);
|
|
375
|
-
var globalData = {
|
|
376
|
-
eventType: "setGlobalState" /* SET_GLOBAL_STATE */ ,
|
|
377
|
-
globalState: newGlobalState
|
|
378
|
-
};
|
|
379
|
-
if (!import_env.isProduction) console.log("MicroAppMessage [".concat(name, "]: setGlobalData"), globalData);
|
|
380
|
-
this._globalState = newGlobalState;
|
|
381
|
-
window.microGlobalEventCenter.forceSetGlobalData(globalData);
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
366
|
{
|
|
385
367
|
// 监听函数
|
|
386
368
|
key: "listener",
|
|
387
369
|
value: function listener(globalData) {
|
|
388
|
-
var
|
|
389
|
-
var eventType = globalData.eventType, action = globalData.action, globalState = globalData.globalState;
|
|
370
|
+
var eventType = globalData.eventType, action = globalData.action;
|
|
390
371
|
switch(eventType){
|
|
391
|
-
case "setGlobalState" /* SET_GLOBAL_STATE */ :
|
|
392
|
-
this._globalState = globalState || {};
|
|
393
|
-
onGlobalStateChange === null || onGlobalStateChange === void 0 ? void 0 : onGlobalStateChange(globalState);
|
|
394
|
-
break;
|
|
395
372
|
case "dispatchAction" /* DISPATCH_ACTION */ :
|
|
396
373
|
this.emitDispatchListener(action);
|
|
397
374
|
break;
|
package/package.json
CHANGED
|
@@ -1,34 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-micro",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
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
|
-
},
|
|
19
7
|
"files": [
|
|
20
8
|
"dist"
|
|
21
9
|
],
|
|
22
10
|
"dependencies": {
|
|
23
11
|
"@micro-zoe/micro-app": "1.0.0-rc.13",
|
|
24
12
|
"@xfe-repo/web-router": "1.1.5",
|
|
25
|
-
"@xfe-repo/web-utils": "1.1.
|
|
13
|
+
"@xfe-repo/web-utils": "1.1.4"
|
|
26
14
|
},
|
|
27
15
|
"devDependencies": {
|
|
28
16
|
"@types/node": "^20.16.5",
|
|
29
17
|
"@types/react": "^18",
|
|
30
|
-
"@xfe-repo/
|
|
31
|
-
"@xfe-repo/
|
|
18
|
+
"@xfe-repo/eslint-config": "0.0.4",
|
|
19
|
+
"@xfe-repo/typescript-config": "0.0.6"
|
|
32
20
|
},
|
|
33
21
|
"scripts": {
|
|
34
22
|
"build": "tsup",
|
package/dist/index.d.mts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
|
|
6
|
-
type MicroAppProps = {
|
|
7
|
-
name: string;
|
|
8
|
-
baseRoute?: string;
|
|
9
|
-
url: string;
|
|
10
|
-
keepAlive?: boolean;
|
|
11
|
-
className?: string;
|
|
12
|
-
loadingFallback?: React.ReactNode;
|
|
13
|
-
errorFallback?: React.ReactNode;
|
|
14
|
-
};
|
|
15
|
-
declare const MicroAppRoute: React.MemoExoticComponent<(props: MicroAppProps) => react_jsx_runtime.JSX.Element>;
|
|
16
|
-
|
|
17
|
-
declare enum MicroAppEventEnum {
|
|
18
|
-
SET_GLOBAL_STATE = "setGlobalState",
|
|
19
|
-
DISPATCH_ACTION = "dispatchAction"
|
|
20
|
-
}
|
|
21
|
-
type MicroAppActionMetaType = {
|
|
22
|
-
source: string;
|
|
23
|
-
target: string;
|
|
24
|
-
transId: string;
|
|
25
|
-
error?: any;
|
|
26
|
-
};
|
|
27
|
-
type MicroAppActionType = {
|
|
28
|
-
type: string;
|
|
29
|
-
payload?: any;
|
|
30
|
-
meta?: MicroAppActionMetaType;
|
|
31
|
-
};
|
|
32
|
-
type MicroAppDispatchListener = (action: MicroAppActionType) => any | Promise<any>;
|
|
33
|
-
type MicroAppGlobalStateType = Record<string, string | number | boolean>;
|
|
34
|
-
type MicroAppGlobalDataType = {
|
|
35
|
-
eventType: MicroAppEventEnum;
|
|
36
|
-
globalState?: MicroAppGlobalStateType;
|
|
37
|
-
action?: MicroAppActionType;
|
|
38
|
-
};
|
|
39
|
-
type MicroAppEventCenterConfig = {
|
|
40
|
-
name: string;
|
|
41
|
-
isMain?: boolean;
|
|
42
|
-
onGlobalStateChange?: (globalState: any) => void;
|
|
43
|
-
};
|
|
44
|
-
declare class MicroAppEventCenter {
|
|
45
|
-
constructor(config: MicroAppEventCenterConfig);
|
|
46
|
-
private readonly config;
|
|
47
|
-
private readonly dispatchListeners;
|
|
48
|
-
private _globalState;
|
|
49
|
-
set globalState(globalState: MicroAppGlobalStateType);
|
|
50
|
-
get globalState(): MicroAppGlobalStateType;
|
|
51
|
-
private listener;
|
|
52
|
-
private emitDispatchListener;
|
|
53
|
-
dispatch(target: string, action: MicroAppActionType): Promise<any>;
|
|
54
|
-
addDispatchListener(type: string, listener: MicroAppDispatchListener): void;
|
|
55
|
-
removeDispatchListener(type: string, listener?: MicroAppDispatchListener): boolean | undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
declare const microApp: _micro_zoe_micro_app.MicroApp;
|
|
59
|
-
|
|
60
|
-
export { type MicroAppActionMetaType, type MicroAppActionType, type MicroAppDispatchListener, MicroAppEventCenter, type MicroAppEventCenterConfig, MicroAppEventEnum, type MicroAppGlobalDataType, type MicroAppGlobalStateType, type MicroAppProps, MicroAppRoute, microApp };
|
package/dist/index.mjs
DELETED
|
@@ -1,473 +0,0 @@
|
|
|
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 { 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, loadingFallback = props.loadingFallback, errorFallback = props.errorFallback;
|
|
230
|
-
var location = useLocation();
|
|
231
|
-
var defaultPage = location.pathname + location.search;
|
|
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
|
-
setMicroAppIsShow(true);
|
|
236
|
-
}, []);
|
|
237
|
-
var handleMicroAppAfterShow = useCallback(function() {
|
|
238
|
-
var path = location.pathname + location.search;
|
|
239
|
-
microApp.router.push({
|
|
240
|
-
name: "dashboard",
|
|
241
|
-
path: path,
|
|
242
|
-
replace: true
|
|
243
|
-
}).catch(function(e) {
|
|
244
|
-
return e;
|
|
245
|
-
});
|
|
246
|
-
setMicroAppIsShow(true);
|
|
247
|
-
}, [
|
|
248
|
-
location
|
|
249
|
-
]);
|
|
250
|
-
var handleMicroAppError = useCallback(function() {
|
|
251
|
-
setMicroAppIsError(true);
|
|
252
|
-
}, []);
|
|
253
|
-
return /* @__PURE__ */ jsxCustomEvent("div", {
|
|
254
|
-
className: className
|
|
255
|
-
}, microAppIsError && errorFallback, !microAppIsShow && loadingFallback, /* @__PURE__ */ jsxCustomEvent("micro-app", {
|
|
256
|
-
style: {
|
|
257
|
-
display: microAppIsShow ? "block" : "none"
|
|
258
|
-
},
|
|
259
|
-
url: url,
|
|
260
|
-
name: name,
|
|
261
|
-
"router-mode": "native",
|
|
262
|
-
baseroute: baseRoute ? baseRoute : "/".concat(name),
|
|
263
|
-
"keep-alive": keepAlive,
|
|
264
|
-
"default-page": defaultPage,
|
|
265
|
-
onMounted: handleMicroAppMounted,
|
|
266
|
-
onAftershow: keepAlive ? handleMicroAppAfterShow : void 0,
|
|
267
|
-
onError: handleMicroAppError
|
|
268
|
-
}));
|
|
269
|
-
});
|
|
270
|
-
// src/index.ts
|
|
271
|
-
var MicroAppEventEnum = /* @__PURE__ */ function(MicroAppEventEnum2) {
|
|
272
|
-
MicroAppEventEnum2["SET_GLOBAL_STATE"] = "setGlobalState";
|
|
273
|
-
MicroAppEventEnum2["DISPATCH_ACTION"] = "dispatchAction";
|
|
274
|
-
return MicroAppEventEnum2;
|
|
275
|
-
}(MicroAppEventEnum || {});
|
|
276
|
-
var MicroAppEventCenter = /*#__PURE__*/ function() {
|
|
277
|
-
"use strict";
|
|
278
|
-
function MicroAppEventCenter(config) {
|
|
279
|
-
var _this = this;
|
|
280
|
-
_class_call_check(this, MicroAppEventCenter);
|
|
281
|
-
this.dispatchListeners = {};
|
|
282
|
-
this._globalState = {};
|
|
283
|
-
this.config = config;
|
|
284
|
-
if (config.isMain) window.microGlobalEventCenter = new EventCenterForMicroApp("global");
|
|
285
|
-
window.microGlobalEventCenter.addGlobalDataListener(function(globalData) {
|
|
286
|
-
return _this.listener(globalData);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
_create_class(MicroAppEventCenter, [
|
|
290
|
-
{
|
|
291
|
-
key: "globalState",
|
|
292
|
-
get: function get() {
|
|
293
|
-
return this._globalState;
|
|
294
|
-
},
|
|
295
|
-
set: function set(globalState) {
|
|
296
|
-
var name = this.config.name;
|
|
297
|
-
var newGlobalState = _object_spread({}, globalState);
|
|
298
|
-
var globalData = {
|
|
299
|
-
eventType: "setGlobalState" /* SET_GLOBAL_STATE */ ,
|
|
300
|
-
globalState: newGlobalState
|
|
301
|
-
};
|
|
302
|
-
if (!isProduction) console.log("MicroAppMessage [".concat(name, "]: setGlobalData"), globalData);
|
|
303
|
-
this._globalState = newGlobalState;
|
|
304
|
-
window.microGlobalEventCenter.forceSetGlobalData(globalData);
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
// 监听函数
|
|
309
|
-
key: "listener",
|
|
310
|
-
value: function listener(globalData) {
|
|
311
|
-
var onGlobalStateChange = this.config.onGlobalStateChange;
|
|
312
|
-
var eventType = globalData.eventType, action = globalData.action, globalState = globalData.globalState;
|
|
313
|
-
switch(eventType){
|
|
314
|
-
case "setGlobalState" /* SET_GLOBAL_STATE */ :
|
|
315
|
-
this._globalState = globalState || {};
|
|
316
|
-
onGlobalStateChange === null || onGlobalStateChange === void 0 ? void 0 : onGlobalStateChange(globalState);
|
|
317
|
-
break;
|
|
318
|
-
case "dispatchAction" /* DISPATCH_ACTION */ :
|
|
319
|
-
this.emitDispatchListener(action);
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
// 触发事件
|
|
326
|
-
key: "emitDispatchListener",
|
|
327
|
-
value: function emitDispatchListener(action) {
|
|
328
|
-
var _this_dispatchListeners_type;
|
|
329
|
-
var name = this.config.name;
|
|
330
|
-
if (!action) return console.error("MicroAppMessage [".concat(name, "]: 未知消息类型 缺少action"));
|
|
331
|
-
var type = action.type, meta = action.meta;
|
|
332
|
-
if (!meta) return console.error("MicroAppMessage [".concat(name, "]: 未知消息类型 缺少meta"), action);
|
|
333
|
-
var source = meta.source, target = meta.target, transId = meta.transId;
|
|
334
|
-
if (source === name) return;
|
|
335
|
-
if (target !== "all" && target !== name) return;
|
|
336
|
-
if (!((_this_dispatchListeners_type = this.dispatchListeners[type]) === null || _this_dispatchListeners_type === void 0 ? void 0 : _this_dispatchListeners_type.length)) return;
|
|
337
|
-
var actionResponseType = "".concat(type, "___").concat(transId, "___response");
|
|
338
|
-
var _this = this;
|
|
339
|
-
this.dispatchListeners[type].forEach(function() {
|
|
340
|
-
var _ref = _async_to_generator(function(listener) {
|
|
341
|
-
var responseAction, error, isBroadcast, isResponse;
|
|
342
|
-
return _ts_generator(this, function(_state) {
|
|
343
|
-
switch(_state.label){
|
|
344
|
-
case 0:
|
|
345
|
-
responseAction = {
|
|
346
|
-
type: actionResponseType,
|
|
347
|
-
meta: {
|
|
348
|
-
source: name,
|
|
349
|
-
target: source,
|
|
350
|
-
transId: transId
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
_state.label = 1;
|
|
354
|
-
case 1:
|
|
355
|
-
_state.trys.push([
|
|
356
|
-
1,
|
|
357
|
-
3,
|
|
358
|
-
,
|
|
359
|
-
4
|
|
360
|
-
]);
|
|
361
|
-
return [
|
|
362
|
-
4,
|
|
363
|
-
listener(action)
|
|
364
|
-
];
|
|
365
|
-
case 2:
|
|
366
|
-
responseAction.payload = _state.sent();
|
|
367
|
-
return [
|
|
368
|
-
3,
|
|
369
|
-
4
|
|
370
|
-
];
|
|
371
|
-
case 3:
|
|
372
|
-
error = _state.sent();
|
|
373
|
-
if (responseAction.meta) responseAction.meta.error = error;
|
|
374
|
-
return [
|
|
375
|
-
3,
|
|
376
|
-
4
|
|
377
|
-
];
|
|
378
|
-
case 4:
|
|
379
|
-
isBroadcast = target === "all";
|
|
380
|
-
isResponse = type.endsWith("___response");
|
|
381
|
-
if (isBroadcast || isResponse) return [
|
|
382
|
-
2
|
|
383
|
-
];
|
|
384
|
-
return [
|
|
385
|
-
4,
|
|
386
|
-
_this.dispatch(source, responseAction)
|
|
387
|
-
];
|
|
388
|
-
case 5:
|
|
389
|
-
_state.sent();
|
|
390
|
-
return [
|
|
391
|
-
2
|
|
392
|
-
];
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
return function(listener) {
|
|
397
|
-
return _ref.apply(this, arguments);
|
|
398
|
-
};
|
|
399
|
-
}());
|
|
400
|
-
}
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
key: "dispatch",
|
|
404
|
-
value: // 远程调用
|
|
405
|
-
function dispatch(target, action) {
|
|
406
|
-
var _this = this;
|
|
407
|
-
return _async_to_generator(function() {
|
|
408
|
-
var name, type, payload, meta, transId, newAction, globalData, isBroadcast, isResponse, actionResponseType, actionResponsePromise;
|
|
409
|
-
return _ts_generator(this, function(_state) {
|
|
410
|
-
name = _this.config.name;
|
|
411
|
-
type = action.type, payload = action.payload, meta = action.meta;
|
|
412
|
-
transId = (meta === null || meta === void 0 ? void 0 : meta.transId) || uuid();
|
|
413
|
-
newAction = {
|
|
414
|
-
type: type,
|
|
415
|
-
payload: payload,
|
|
416
|
-
meta: _object_spread({
|
|
417
|
-
source: name,
|
|
418
|
-
target: target,
|
|
419
|
-
transId: transId
|
|
420
|
-
}, meta)
|
|
421
|
-
};
|
|
422
|
-
globalData = {
|
|
423
|
-
eventType: "dispatchAction" /* DISPATCH_ACTION */ ,
|
|
424
|
-
action: newAction
|
|
425
|
-
};
|
|
426
|
-
if (!isProduction) console.log("MicroAppMessage [".concat(name, "]: dispatch ").concat(type, " to [").concat(target, "]"), globalData);
|
|
427
|
-
isBroadcast = target === "all";
|
|
428
|
-
isResponse = type.endsWith("___response");
|
|
429
|
-
if (isBroadcast || isResponse) return [
|
|
430
|
-
2,
|
|
431
|
-
window.microGlobalEventCenter.forceSetGlobalData(globalData)
|
|
432
|
-
];
|
|
433
|
-
actionResponseType = "".concat(type, "___").concat(transId, "___response");
|
|
434
|
-
actionResponsePromise = new Promise(function(resolve, reject) {
|
|
435
|
-
var listener = function(responseAction) {
|
|
436
|
-
var payload2 = responseAction.payload, meta2 = responseAction.meta;
|
|
437
|
-
(meta2 === null || meta2 === void 0 ? void 0 : meta2.error) ? reject(meta2.error) : resolve(payload2);
|
|
438
|
-
_this.removeDispatchListener(actionResponseType, listener);
|
|
439
|
-
};
|
|
440
|
-
_this.addDispatchListener(actionResponseType, listener);
|
|
441
|
-
});
|
|
442
|
-
window.microGlobalEventCenter.forceSetGlobalData(globalData);
|
|
443
|
-
return [
|
|
444
|
-
2,
|
|
445
|
-
actionResponsePromise
|
|
446
|
-
];
|
|
447
|
-
});
|
|
448
|
-
})();
|
|
449
|
-
}
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
// 添加监听
|
|
453
|
-
key: "addDispatchListener",
|
|
454
|
-
value: function addDispatchListener(type, listener) {
|
|
455
|
-
if (!this.dispatchListeners[type]) this.dispatchListeners[type] = [];
|
|
456
|
-
this.dispatchListeners[type].push(listener);
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
// 移除监听 如果不传listener则移除所有监听
|
|
461
|
-
key: "removeDispatchListener",
|
|
462
|
-
value: function removeDispatchListener(type, listener) {
|
|
463
|
-
if (!this.dispatchListeners[type]) return;
|
|
464
|
-
if (!listener) return delete this.dispatchListeners[type];
|
|
465
|
-
var index = this.dispatchListeners[type].indexOf(listener);
|
|
466
|
-
if (index !== -1) this.dispatchListeners[type].splice(index, 1);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
]);
|
|
470
|
-
return MicroAppEventCenter;
|
|
471
|
-
}();
|
|
472
|
-
var microApp2 = originMicroApp;
|
|
473
|
-
export { MicroAppEventCenter, MicroAppEventEnum, MicroAppRoute, microApp2 as microApp };
|