@hhfenpm/micro-app 1.0.2 → 1.0.4
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.esm.js +93 -100
- package/dist/index.js +93 -100
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var uiHandler = vm => ({
|
|
2
|
+
$message: (...args) => vm.$message(...args),
|
|
3
|
+
$success: msg => vm.$message.success(msg),
|
|
4
|
+
$warning: msg => vm.$message.warning(msg),
|
|
5
|
+
$error: msg => vm.$message.error(msg),
|
|
6
|
+
$notify: options => vm.$notify(options),
|
|
7
|
+
$confirm: (...args) =>
|
|
8
|
+
vm
|
|
9
|
+
.$confirm(...args)
|
|
10
|
+
.then(() => true)
|
|
11
|
+
.catch(() => false),
|
|
12
|
+
$alert: (...args) =>
|
|
13
|
+
vm
|
|
14
|
+
.$alert(...args)
|
|
15
|
+
.then(() => true)
|
|
16
|
+
.catch(() => false),
|
|
17
|
+
$prompt: (...args) =>
|
|
18
|
+
vm
|
|
19
|
+
.$prompt(...args)
|
|
20
|
+
.then(res => res.value)
|
|
21
|
+
.catch(() => null),
|
|
22
|
+
$loading: options => {
|
|
23
|
+
const loading = vm.$loading(options);
|
|
24
|
+
return () => loading.close()
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const noop = () => console.warn('[bridge] electron 不可用');
|
|
29
|
+
|
|
30
|
+
const KEYS = [
|
|
31
|
+
'renderer_listen',
|
|
32
|
+
'web_send',
|
|
33
|
+
'web_send_path',
|
|
34
|
+
'show',
|
|
35
|
+
'hide',
|
|
36
|
+
'quit',
|
|
37
|
+
'showAlertDialog',
|
|
38
|
+
'closeAlertDialog',
|
|
39
|
+
'closeAlertDialogAndJump',
|
|
40
|
+
'set_bounds',
|
|
41
|
+
'get_bounds',
|
|
42
|
+
'workarea',
|
|
43
|
+
'center',
|
|
44
|
+
'maximize',
|
|
45
|
+
'unmaximize',
|
|
46
|
+
'is_maximized',
|
|
47
|
+
'minimize',
|
|
48
|
+
'open_top',
|
|
49
|
+
'close_top',
|
|
50
|
+
'update',
|
|
51
|
+
'collapse',
|
|
52
|
+
'unfold',
|
|
53
|
+
'unfoldMax',
|
|
54
|
+
'get_version',
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
function createCs(electron = {}) {
|
|
58
|
+
const base = Object.fromEntries(
|
|
59
|
+
KEYS.map(k => [k, typeof electron[k] === 'function' ? electron[k] : noop])
|
|
60
|
+
);
|
|
61
|
+
return {
|
|
62
|
+
...electron,
|
|
63
|
+
...base,
|
|
64
|
+
is_app:
|
|
65
|
+
typeof electron.is_app === 'function'
|
|
66
|
+
? electron.is_app()
|
|
67
|
+
: !!electron.is_app,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const BRIDGE$1 = { INVOKE: 'bridge-invoke', CALLBACK: 'bridge-callback' };
|
|
5
72
|
|
|
6
73
|
const post = (target, message) =>
|
|
7
74
|
target?.postMessage(message, window.location.origin);
|
|
@@ -19,6 +86,17 @@ const safeClone = value => {
|
|
|
19
86
|
}
|
|
20
87
|
};
|
|
21
88
|
|
|
89
|
+
function createRegisterHandlers(getElectron) {
|
|
90
|
+
const electron = (() => {
|
|
91
|
+
try {
|
|
92
|
+
return typeof getElectron === 'function' ? getElectron() : {}
|
|
93
|
+
} catch {
|
|
94
|
+
return {}
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
97
|
+
return vm => ({ ui: uiHandler(vm), cs: createCs(electron) })
|
|
98
|
+
}
|
|
99
|
+
|
|
22
100
|
const initBridge = ({
|
|
23
101
|
isParent = false,
|
|
24
102
|
vm,
|
|
@@ -79,7 +157,7 @@ const initBridge = ({
|
|
|
79
157
|
result: safeClone(payload),
|
|
80
158
|
});
|
|
81
159
|
|
|
82
|
-
result
|
|
160
|
+
Promise.resolve(result).then(done).catch(done);
|
|
83
161
|
} catch (err) {
|
|
84
162
|
post(iframeWindow, {
|
|
85
163
|
type: BRIDGE$1.CALLBACK,
|
|
@@ -106,88 +184,6 @@ const initBridge = ({
|
|
|
106
184
|
});
|
|
107
185
|
};
|
|
108
186
|
|
|
109
|
-
var uiHandler = vm => ({
|
|
110
|
-
$message: (...args) => vm.$message(...args),
|
|
111
|
-
$success: msg => vm.$message.success(msg),
|
|
112
|
-
$warning: msg => vm.$message.warning(msg),
|
|
113
|
-
$error: msg => vm.$message.error(msg),
|
|
114
|
-
$notify: options => vm.$notify(options),
|
|
115
|
-
$confirm: (...args) =>
|
|
116
|
-
vm
|
|
117
|
-
.$confirm(...args)
|
|
118
|
-
.then(() => true)
|
|
119
|
-
.catch(() => false),
|
|
120
|
-
$alert: (...args) =>
|
|
121
|
-
vm
|
|
122
|
-
.$alert(...args)
|
|
123
|
-
.then(() => true)
|
|
124
|
-
.catch(() => false),
|
|
125
|
-
$prompt: (...args) =>
|
|
126
|
-
vm
|
|
127
|
-
.$prompt(...args)
|
|
128
|
-
.then(res => res.value)
|
|
129
|
-
.catch(() => null),
|
|
130
|
-
$loading: options => {
|
|
131
|
-
const loading = vm.$loading(options);
|
|
132
|
-
return () => loading.close()
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const noop = () => console.warn('[bridge] electron 不可用');
|
|
137
|
-
|
|
138
|
-
const KEYS = [
|
|
139
|
-
'renderer_listen',
|
|
140
|
-
'web_send',
|
|
141
|
-
'web_send_path',
|
|
142
|
-
'show',
|
|
143
|
-
'hide',
|
|
144
|
-
'quit',
|
|
145
|
-
'showAlertDialog',
|
|
146
|
-
'closeAlertDialog',
|
|
147
|
-
'closeAlertDialogAndJump',
|
|
148
|
-
'set_bounds',
|
|
149
|
-
'get_bounds',
|
|
150
|
-
'workarea',
|
|
151
|
-
'center',
|
|
152
|
-
'maximize',
|
|
153
|
-
'unmaximize',
|
|
154
|
-
'is_maximized',
|
|
155
|
-
'minimize',
|
|
156
|
-
'open_top',
|
|
157
|
-
'close_top',
|
|
158
|
-
'update',
|
|
159
|
-
'collapse',
|
|
160
|
-
'unfold',
|
|
161
|
-
'unfoldMax',
|
|
162
|
-
'get_version',
|
|
163
|
-
];
|
|
164
|
-
|
|
165
|
-
function createCs(electron = {}) {
|
|
166
|
-
const base = Object.fromEntries(
|
|
167
|
-
KEYS.map(k => [k, typeof electron[k] === 'function' ? electron[k] : noop])
|
|
168
|
-
);
|
|
169
|
-
return {
|
|
170
|
-
...electron,
|
|
171
|
-
...base,
|
|
172
|
-
is_app:
|
|
173
|
-
typeof electron.is_app === 'function'
|
|
174
|
-
? electron.is_app()
|
|
175
|
-
: !!electron.is_app,
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function createRegisterHandlers(getElectron) {
|
|
180
|
-
let electron = {};
|
|
181
|
-
try {
|
|
182
|
-
if (typeof getElectron === 'function') electron = getElectron();
|
|
183
|
-
} catch {}
|
|
184
|
-
|
|
185
|
-
return vm => ({
|
|
186
|
-
ui: uiHandler(vm),
|
|
187
|
-
cs: createCs(electron),
|
|
188
|
-
})
|
|
189
|
-
}
|
|
190
|
-
|
|
191
187
|
function createMicroAppCore({
|
|
192
188
|
modelMap,
|
|
193
189
|
enabledModules,
|
|
@@ -213,9 +209,9 @@ function createMicroAppCore({
|
|
|
213
209
|
|
|
214
210
|
const microAppModule = path => {
|
|
215
211
|
const value = path.split('?')[0];
|
|
216
|
-
const key = Object.keys(MAP).find(
|
|
217
|
-
const
|
|
218
|
-
return
|
|
212
|
+
const key = Object.keys(MAP).find(k => MAP[k].includes(value));
|
|
213
|
+
const mods = getEnabledModules();
|
|
214
|
+
return mods?.includes(key) ? key : null
|
|
219
215
|
};
|
|
220
216
|
|
|
221
217
|
const microAppSrc = path => {
|
|
@@ -226,12 +222,9 @@ function createMicroAppCore({
|
|
|
226
222
|
|
|
227
223
|
const microAppDeployed = async module => {
|
|
228
224
|
try {
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
});
|
|
233
|
-
return result.ok
|
|
234
|
-
} catch (error) {
|
|
225
|
+
const res = await fetch(`/${module}`, { method: 'GET', cache: 'no-store' });
|
|
226
|
+
return res.ok
|
|
227
|
+
} catch {
|
|
235
228
|
return false
|
|
236
229
|
}
|
|
237
230
|
};
|
|
@@ -261,11 +254,11 @@ const BRIDGE = { INVOKE: 'bridge-invoke', CALLBACK: 'bridge-callback' };
|
|
|
261
254
|
const LIFE_CYCLE_TYPES = Object.values(LIFE_CYCLE);
|
|
262
255
|
const BRIDGE_TYPES = Object.values(BRIDGE);
|
|
263
256
|
|
|
264
|
-
const getIframe = selector => document.querySelector(selector);
|
|
265
|
-
|
|
266
257
|
const postToChild = (iframeSelector, message) => {
|
|
267
|
-
|
|
268
|
-
|
|
258
|
+
document.querySelector(iframeSelector)?.contentWindow?.postMessage(
|
|
259
|
+
message,
|
|
260
|
+
window.location.origin
|
|
261
|
+
);
|
|
269
262
|
};
|
|
270
263
|
|
|
271
264
|
const postToParent = message => {
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,77 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
var uiHandler = vm => ({
|
|
6
|
+
$message: (...args) => vm.$message(...args),
|
|
7
|
+
$success: msg => vm.$message.success(msg),
|
|
8
|
+
$warning: msg => vm.$message.warning(msg),
|
|
9
|
+
$error: msg => vm.$message.error(msg),
|
|
10
|
+
$notify: options => vm.$notify(options),
|
|
11
|
+
$confirm: (...args) =>
|
|
12
|
+
vm
|
|
13
|
+
.$confirm(...args)
|
|
14
|
+
.then(() => true)
|
|
15
|
+
.catch(() => false),
|
|
16
|
+
$alert: (...args) =>
|
|
17
|
+
vm
|
|
18
|
+
.$alert(...args)
|
|
19
|
+
.then(() => true)
|
|
20
|
+
.catch(() => false),
|
|
21
|
+
$prompt: (...args) =>
|
|
22
|
+
vm
|
|
23
|
+
.$prompt(...args)
|
|
24
|
+
.then(res => res.value)
|
|
25
|
+
.catch(() => null),
|
|
26
|
+
$loading: options => {
|
|
27
|
+
const loading = vm.$loading(options);
|
|
28
|
+
return () => loading.close()
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const noop = () => console.warn('[bridge] electron 不可用');
|
|
33
|
+
|
|
34
|
+
const KEYS = [
|
|
35
|
+
'renderer_listen',
|
|
36
|
+
'web_send',
|
|
37
|
+
'web_send_path',
|
|
38
|
+
'show',
|
|
39
|
+
'hide',
|
|
40
|
+
'quit',
|
|
41
|
+
'showAlertDialog',
|
|
42
|
+
'closeAlertDialog',
|
|
43
|
+
'closeAlertDialogAndJump',
|
|
44
|
+
'set_bounds',
|
|
45
|
+
'get_bounds',
|
|
46
|
+
'workarea',
|
|
47
|
+
'center',
|
|
48
|
+
'maximize',
|
|
49
|
+
'unmaximize',
|
|
50
|
+
'is_maximized',
|
|
51
|
+
'minimize',
|
|
52
|
+
'open_top',
|
|
53
|
+
'close_top',
|
|
54
|
+
'update',
|
|
55
|
+
'collapse',
|
|
56
|
+
'unfold',
|
|
57
|
+
'unfoldMax',
|
|
58
|
+
'get_version',
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
function createCs(electron = {}) {
|
|
62
|
+
const base = Object.fromEntries(
|
|
63
|
+
KEYS.map(k => [k, typeof electron[k] === 'function' ? electron[k] : noop])
|
|
64
|
+
);
|
|
65
|
+
return {
|
|
66
|
+
...electron,
|
|
67
|
+
...base,
|
|
68
|
+
is_app:
|
|
69
|
+
typeof electron.is_app === 'function'
|
|
70
|
+
? electron.is_app()
|
|
71
|
+
: !!electron.is_app,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const BRIDGE$1 = { INVOKE: 'bridge-invoke', CALLBACK: 'bridge-callback' };
|
|
9
76
|
|
|
10
77
|
const post = (target, message) =>
|
|
11
78
|
target?.postMessage(message, window.location.origin);
|
|
@@ -23,6 +90,17 @@ const safeClone = value => {
|
|
|
23
90
|
}
|
|
24
91
|
};
|
|
25
92
|
|
|
93
|
+
function createRegisterHandlers(getElectron) {
|
|
94
|
+
const electron = (() => {
|
|
95
|
+
try {
|
|
96
|
+
return typeof getElectron === 'function' ? getElectron() : {}
|
|
97
|
+
} catch {
|
|
98
|
+
return {}
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
return vm => ({ ui: uiHandler(vm), cs: createCs(electron) })
|
|
102
|
+
}
|
|
103
|
+
|
|
26
104
|
const initBridge = ({
|
|
27
105
|
isParent = false,
|
|
28
106
|
vm,
|
|
@@ -83,7 +161,7 @@ const initBridge = ({
|
|
|
83
161
|
result: safeClone(payload),
|
|
84
162
|
});
|
|
85
163
|
|
|
86
|
-
result
|
|
164
|
+
Promise.resolve(result).then(done).catch(done);
|
|
87
165
|
} catch (err) {
|
|
88
166
|
post(iframeWindow, {
|
|
89
167
|
type: BRIDGE$1.CALLBACK,
|
|
@@ -110,88 +188,6 @@ const initBridge = ({
|
|
|
110
188
|
});
|
|
111
189
|
};
|
|
112
190
|
|
|
113
|
-
var uiHandler = vm => ({
|
|
114
|
-
$message: (...args) => vm.$message(...args),
|
|
115
|
-
$success: msg => vm.$message.success(msg),
|
|
116
|
-
$warning: msg => vm.$message.warning(msg),
|
|
117
|
-
$error: msg => vm.$message.error(msg),
|
|
118
|
-
$notify: options => vm.$notify(options),
|
|
119
|
-
$confirm: (...args) =>
|
|
120
|
-
vm
|
|
121
|
-
.$confirm(...args)
|
|
122
|
-
.then(() => true)
|
|
123
|
-
.catch(() => false),
|
|
124
|
-
$alert: (...args) =>
|
|
125
|
-
vm
|
|
126
|
-
.$alert(...args)
|
|
127
|
-
.then(() => true)
|
|
128
|
-
.catch(() => false),
|
|
129
|
-
$prompt: (...args) =>
|
|
130
|
-
vm
|
|
131
|
-
.$prompt(...args)
|
|
132
|
-
.then(res => res.value)
|
|
133
|
-
.catch(() => null),
|
|
134
|
-
$loading: options => {
|
|
135
|
-
const loading = vm.$loading(options);
|
|
136
|
-
return () => loading.close()
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const noop = () => console.warn('[bridge] electron 不可用');
|
|
141
|
-
|
|
142
|
-
const KEYS = [
|
|
143
|
-
'renderer_listen',
|
|
144
|
-
'web_send',
|
|
145
|
-
'web_send_path',
|
|
146
|
-
'show',
|
|
147
|
-
'hide',
|
|
148
|
-
'quit',
|
|
149
|
-
'showAlertDialog',
|
|
150
|
-
'closeAlertDialog',
|
|
151
|
-
'closeAlertDialogAndJump',
|
|
152
|
-
'set_bounds',
|
|
153
|
-
'get_bounds',
|
|
154
|
-
'workarea',
|
|
155
|
-
'center',
|
|
156
|
-
'maximize',
|
|
157
|
-
'unmaximize',
|
|
158
|
-
'is_maximized',
|
|
159
|
-
'minimize',
|
|
160
|
-
'open_top',
|
|
161
|
-
'close_top',
|
|
162
|
-
'update',
|
|
163
|
-
'collapse',
|
|
164
|
-
'unfold',
|
|
165
|
-
'unfoldMax',
|
|
166
|
-
'get_version',
|
|
167
|
-
];
|
|
168
|
-
|
|
169
|
-
function createCs(electron = {}) {
|
|
170
|
-
const base = Object.fromEntries(
|
|
171
|
-
KEYS.map(k => [k, typeof electron[k] === 'function' ? electron[k] : noop])
|
|
172
|
-
);
|
|
173
|
-
return {
|
|
174
|
-
...electron,
|
|
175
|
-
...base,
|
|
176
|
-
is_app:
|
|
177
|
-
typeof electron.is_app === 'function'
|
|
178
|
-
? electron.is_app()
|
|
179
|
-
: !!electron.is_app,
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function createRegisterHandlers(getElectron) {
|
|
184
|
-
let electron = {};
|
|
185
|
-
try {
|
|
186
|
-
if (typeof getElectron === 'function') electron = getElectron();
|
|
187
|
-
} catch {}
|
|
188
|
-
|
|
189
|
-
return vm => ({
|
|
190
|
-
ui: uiHandler(vm),
|
|
191
|
-
cs: createCs(electron),
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
|
|
195
191
|
function createMicroAppCore({
|
|
196
192
|
modelMap,
|
|
197
193
|
enabledModules,
|
|
@@ -217,9 +213,9 @@ function createMicroAppCore({
|
|
|
217
213
|
|
|
218
214
|
const microAppModule = path => {
|
|
219
215
|
const value = path.split('?')[0];
|
|
220
|
-
const key = Object.keys(MAP).find(
|
|
221
|
-
const
|
|
222
|
-
return
|
|
216
|
+
const key = Object.keys(MAP).find(k => MAP[k].includes(value));
|
|
217
|
+
const mods = getEnabledModules();
|
|
218
|
+
return mods?.includes(key) ? key : null
|
|
223
219
|
};
|
|
224
220
|
|
|
225
221
|
const microAppSrc = path => {
|
|
@@ -230,12 +226,9 @@ function createMicroAppCore({
|
|
|
230
226
|
|
|
231
227
|
const microAppDeployed = async module => {
|
|
232
228
|
try {
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
return result.ok
|
|
238
|
-
} catch (error) {
|
|
229
|
+
const res = await fetch(`/${module}`, { method: 'GET', cache: 'no-store' });
|
|
230
|
+
return res.ok
|
|
231
|
+
} catch {
|
|
239
232
|
return false
|
|
240
233
|
}
|
|
241
234
|
};
|
|
@@ -265,11 +258,11 @@ const BRIDGE = { INVOKE: 'bridge-invoke', CALLBACK: 'bridge-callback' };
|
|
|
265
258
|
const LIFE_CYCLE_TYPES = Object.values(LIFE_CYCLE);
|
|
266
259
|
const BRIDGE_TYPES = Object.values(BRIDGE);
|
|
267
260
|
|
|
268
|
-
const getIframe = selector => document.querySelector(selector);
|
|
269
|
-
|
|
270
261
|
const postToChild = (iframeSelector, message) => {
|
|
271
|
-
|
|
272
|
-
|
|
262
|
+
document.querySelector(iframeSelector)?.contentWindow?.postMessage(
|
|
263
|
+
message,
|
|
264
|
+
window.location.origin
|
|
265
|
+
);
|
|
273
266
|
};
|
|
274
267
|
|
|
275
268
|
const postToParent = message => {
|