@micro-zoe/micro-app 1.0.0-alpha.3 → 1.0.0-alpha.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/README.md +0 -4
- package/README.zh-cn.md +1 -1
- package/lib/index.d.ts +26 -15
- package/lib/index.esm.js +1103 -482
- package/lib/index.esm.js.map +1 -1
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.map +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/index.umd.js.map +1 -1
- package/package.json +3 -1
- package/typings/global.d.ts +117 -67
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micro-zoe/micro-app",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"description": "A lightweight, efficient and powerful micro front-end framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "lib/index.min.js",
|
|
@@ -44,6 +44,8 @@
|
|
|
44
44
|
"test": "jest",
|
|
45
45
|
"test:watch": "jest --watch",
|
|
46
46
|
"test:coverage": "jest --coverage",
|
|
47
|
+
"test:unit": "jest src/__tests__/unit",
|
|
48
|
+
"test:unit:coverage": "npm run test:unit -- --coverage",
|
|
47
49
|
"prepublishOnly": "yarn build"
|
|
48
50
|
},
|
|
49
51
|
"repository": {
|
package/typings/global.d.ts
CHANGED
|
@@ -9,15 +9,31 @@ declare module '@micro-app/types' {
|
|
|
9
9
|
|
|
10
10
|
type appName = string
|
|
11
11
|
|
|
12
|
+
type SourceAddress = string
|
|
13
|
+
|
|
14
|
+
type AttrsType = Map<string, string>
|
|
15
|
+
|
|
16
|
+
type fiberTasks = Array<() => Promise<void>> | null
|
|
17
|
+
|
|
18
|
+
interface SandBoxStartParams {
|
|
19
|
+
umdMode: boolean
|
|
20
|
+
baseroute: string
|
|
21
|
+
useMemoryRouter: boolean
|
|
22
|
+
defaultPage: string
|
|
23
|
+
disablePatchRequest: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface SandBoxStopParams {
|
|
27
|
+
umdMode: boolean
|
|
28
|
+
keepRouteState: boolean
|
|
29
|
+
clearEventSource: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
interface SandBoxInterface {
|
|
13
33
|
proxyWindow: WindowProxy
|
|
14
34
|
microAppWindow: Window // Proxy target
|
|
15
|
-
start (
|
|
16
|
-
|
|
17
|
-
useMemoryRouter: boolean,
|
|
18
|
-
defaultPage: string,
|
|
19
|
-
): void
|
|
20
|
-
stop (keepRouteState: boolean, clearEventSource: boolean): void
|
|
35
|
+
start (startParams: SandBoxStartParams): void
|
|
36
|
+
stop (stopParams: SandBoxStopParams): void
|
|
21
37
|
// record umd snapshot before the first execution of umdHookMount
|
|
22
38
|
recordUmdSnapshot (): void
|
|
23
39
|
// rebuild umd snapshot before remount umd app
|
|
@@ -40,48 +56,71 @@ declare module '@micro-app/types' {
|
|
|
40
56
|
// injectReactHRMProperty (): void
|
|
41
57
|
}
|
|
42
58
|
|
|
43
|
-
type
|
|
44
|
-
code: string // code
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
type LinkSourceInfo = {
|
|
60
|
+
code: string, // source code
|
|
61
|
+
appSpace: Record<string, {
|
|
62
|
+
attrs: Map<string, string>, // active element.attributes
|
|
63
|
+
placeholder?: Comment | null, // placeholder comment
|
|
64
|
+
parsedCode?: string, // parsed code
|
|
65
|
+
prefix?: string, // micro-app[name=appName]
|
|
66
|
+
}>
|
|
47
67
|
}
|
|
48
68
|
|
|
49
|
-
type
|
|
50
|
-
code: string // code
|
|
51
|
-
isExternal: boolean // external script
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
type ScriptSourceInfo = {
|
|
70
|
+
code: string, // source code
|
|
71
|
+
isExternal: boolean, // external script
|
|
72
|
+
appSpace: Record<string, {
|
|
73
|
+
async: boolean, // async script
|
|
74
|
+
defer: boolean, // defer script
|
|
75
|
+
module: boolean, // module type script
|
|
76
|
+
inline: boolean, // run js with inline script
|
|
77
|
+
pure: boolean, // pure script
|
|
78
|
+
attrs: Map<string, string>, // element attributes
|
|
79
|
+
parsedCode?: string, // bind code
|
|
80
|
+
parsedFunction?: Function | null, // code to function
|
|
81
|
+
wrapInSandBox?: boolean // use sandbox
|
|
82
|
+
}>
|
|
58
83
|
}
|
|
59
84
|
|
|
60
|
-
|
|
61
|
-
html
|
|
62
|
-
links:
|
|
63
|
-
scripts:
|
|
85
|
+
type sourceType = {
|
|
86
|
+
html: HTMLElement | null, // html address
|
|
87
|
+
links: Set<string>, // style/link address list
|
|
88
|
+
scripts: Set<string>, // script address list
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface MountParam {
|
|
92
|
+
container: HTMLElement | ShadowRoot
|
|
93
|
+
inline: boolean
|
|
94
|
+
useMemoryRouter: boolean
|
|
95
|
+
baseroute: string
|
|
96
|
+
keepRouteState: boolean
|
|
97
|
+
defaultPage: string
|
|
98
|
+
hiddenRouter: boolean
|
|
99
|
+
disablePatchRequest: boolean
|
|
100
|
+
fiber: boolean
|
|
101
|
+
esmodule: boolean
|
|
64
102
|
}
|
|
65
103
|
|
|
66
104
|
// app instance
|
|
67
105
|
interface AppInterface {
|
|
68
|
-
|
|
69
|
-
|
|
106
|
+
source: sourceType // source list
|
|
107
|
+
sandBox: SandBoxInterface | null // sandbox
|
|
70
108
|
name: string // app name
|
|
71
109
|
url: string // app url
|
|
72
|
-
ssrUrl: string // html path in ssr mode
|
|
73
|
-
container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, DIV(keep-alive)
|
|
74
|
-
inline: boolean // whether js runs in inline script mode, default is false
|
|
75
110
|
scopecss: boolean // whether use css scoped, default is true
|
|
76
111
|
useSandbox: boolean // whether use js sandbox, default is true
|
|
77
|
-
|
|
78
|
-
|
|
112
|
+
inline: boolean // whether js runs in inline script mode, default is false
|
|
113
|
+
esmodule: boolean // support esmodule in script
|
|
114
|
+
ssrUrl: string // html path in ssr mode
|
|
115
|
+
isPrefetch: boolean // whether prefetch app, default is false
|
|
116
|
+
container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, div(keep-alive)
|
|
79
117
|
keepRouteState: boolean // keep route state when unmount, default is false
|
|
80
|
-
hiddenRouter: boolean // hide router info of child from browser url
|
|
81
|
-
source: sourceType // sources of css, js, html
|
|
82
|
-
sandBox: SandBoxInterface | null // sandbox
|
|
83
118
|
umdMode: boolean // is umd mode
|
|
84
|
-
|
|
119
|
+
fiber: boolean // fiber mode
|
|
120
|
+
useMemoryRouter: boolean // use virtual router
|
|
121
|
+
// defaultPage: string // default page when mount
|
|
122
|
+
// baseroute: string // route prefix, default is ''
|
|
123
|
+
// hiddenRouter: boolean // hide router info of child from browser url
|
|
85
124
|
|
|
86
125
|
// Load resources
|
|
87
126
|
loadSourceCode (): void
|
|
@@ -93,14 +132,7 @@ declare module '@micro-app/types' {
|
|
|
93
132
|
onLoadError (e: Error): void
|
|
94
133
|
|
|
95
134
|
// mount app
|
|
96
|
-
mount (
|
|
97
|
-
container?: HTMLElement | ShadowRoot,
|
|
98
|
-
inline?: boolean,
|
|
99
|
-
baseroute?: string,
|
|
100
|
-
keepRouteState?: boolean,
|
|
101
|
-
defaultPage?: string,
|
|
102
|
-
hiddenRouter?: boolean
|
|
103
|
-
): void
|
|
135
|
+
mount (mountParams: MountParam): void
|
|
104
136
|
|
|
105
137
|
// unmount app
|
|
106
138
|
unmount (destroy: boolean, unmountcb?: CallableFunction): void
|
|
@@ -146,7 +178,8 @@ declare module '@micro-app/types' {
|
|
|
146
178
|
// old config 👆
|
|
147
179
|
'disable-scopecss'?: boolean
|
|
148
180
|
'disable-sandbox'?: boolean
|
|
149
|
-
|
|
181
|
+
inline?: boolean
|
|
182
|
+
esmodule?: boolean
|
|
150
183
|
}
|
|
151
184
|
|
|
152
185
|
// prefetch params
|
|
@@ -159,8 +192,13 @@ declare module '@micro-app/types' {
|
|
|
159
192
|
mounted?(e?: CustomEvent): void
|
|
160
193
|
unmount?(e?: CustomEvent): void
|
|
161
194
|
error?(e?: CustomEvent): void
|
|
195
|
+
beforeshow?(e?: CustomEvent): void
|
|
196
|
+
aftershow?(e?: CustomEvent): void
|
|
197
|
+
afterhidden?(e?: CustomEvent): void
|
|
162
198
|
}
|
|
163
199
|
|
|
200
|
+
type AssetsChecker = (url: string) => boolean;
|
|
201
|
+
|
|
164
202
|
type plugins = {
|
|
165
203
|
// global plugin
|
|
166
204
|
global?: Array<{
|
|
@@ -168,10 +206,16 @@ declare module '@micro-app/types' {
|
|
|
168
206
|
scopeProperties?: Array<PropertyKey>
|
|
169
207
|
// Properties that can be escape to rawWindow
|
|
170
208
|
escapeProperties?: Array<PropertyKey>
|
|
209
|
+
// Exclude JS or CSS
|
|
210
|
+
excludeChecker?: AssetsChecker
|
|
211
|
+
// Ignore JS or CSS
|
|
212
|
+
ignoreChecker?: AssetsChecker
|
|
171
213
|
// options for plugin as the third parameter of loader
|
|
172
|
-
options?: unknown
|
|
214
|
+
options?: Record<string, unknown>
|
|
173
215
|
// handle function
|
|
174
|
-
loader?: (code: string, url: string
|
|
216
|
+
loader?: (code: string, url: string) => string
|
|
217
|
+
// html processor
|
|
218
|
+
processHtml?: (code: string, url: string) => string
|
|
175
219
|
}>
|
|
176
220
|
|
|
177
221
|
// plugin for special app
|
|
@@ -181,10 +225,16 @@ declare module '@micro-app/types' {
|
|
|
181
225
|
scopeProperties?: Array<PropertyKey>
|
|
182
226
|
// Properties that can be escape to rawWindow
|
|
183
227
|
escapeProperties?: Array<PropertyKey>
|
|
228
|
+
// Exclude JS or CSS
|
|
229
|
+
excludeChecker?: AssetsChecker
|
|
230
|
+
// Ignore JS or CSS
|
|
231
|
+
ignoreChecker?: AssetsChecker
|
|
184
232
|
// options for plugin as the third parameter of loader
|
|
185
|
-
options?: unknown
|
|
233
|
+
options?: Record<string, unknown>
|
|
186
234
|
// handle function
|
|
187
|
-
loader?: (code: string, url: string
|
|
235
|
+
loader?: (code: string, url: string) => string
|
|
236
|
+
// html processor
|
|
237
|
+
processHtml?: (code: string, url: string) => string
|
|
188
238
|
}>
|
|
189
239
|
}
|
|
190
240
|
}
|
|
@@ -198,9 +248,10 @@ declare module '@micro-app/types' {
|
|
|
198
248
|
|
|
199
249
|
type OptionsType = {
|
|
200
250
|
tagName?: string
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
251
|
+
shadowDOM?: boolean
|
|
252
|
+
destroy?: boolean
|
|
253
|
+
destory?: boolean
|
|
254
|
+
inline?: boolean
|
|
204
255
|
// old config 👇
|
|
205
256
|
disableScopecss?: boolean
|
|
206
257
|
disableSandbox?: boolean
|
|
@@ -208,30 +259,25 @@ declare module '@micro-app/types' {
|
|
|
208
259
|
'disable-scopecss'?: boolean
|
|
209
260
|
'disable-sandbox'?: boolean
|
|
210
261
|
'disable-memory-router'?: boolean
|
|
262
|
+
'disable-patch-request'?: boolean
|
|
211
263
|
'keep-router-state'?: boolean
|
|
212
264
|
'hidden-router'?: boolean
|
|
213
|
-
'
|
|
214
|
-
|
|
265
|
+
'keep-alive'?: boolean
|
|
266
|
+
esmodule?: boolean
|
|
267
|
+
ssr?: boolean
|
|
268
|
+
fiber?: boolean
|
|
215
269
|
lifeCycles?: lifeCyclesType
|
|
216
270
|
preFetchApps?: prefetchParamList
|
|
217
271
|
plugins?: plugins
|
|
218
272
|
fetch?: fetchType
|
|
219
273
|
globalAssets?: globalAssetsType,
|
|
274
|
+
excludeAssetFilter?: (assetUrl: string) => boolean
|
|
220
275
|
}
|
|
221
276
|
|
|
222
277
|
// MicroApp config
|
|
223
278
|
interface MicroAppConfigType {
|
|
224
279
|
tagName: string
|
|
225
|
-
|
|
226
|
-
destroy?: boolean
|
|
227
|
-
inline?: boolean
|
|
228
|
-
disableScopecss?: boolean
|
|
229
|
-
disableSandbox?: boolean
|
|
230
|
-
disableMemoryRouter?: boolean
|
|
231
|
-
ssr?: boolean
|
|
232
|
-
lifeCycles?: lifeCyclesType
|
|
233
|
-
plugins?: plugins
|
|
234
|
-
fetch?: fetchType
|
|
280
|
+
options: OptionsType
|
|
235
281
|
preFetch(apps: prefetchParamList): void
|
|
236
282
|
router: Router // eslint-disable-line
|
|
237
283
|
start(options?: OptionsType): void
|
|
@@ -297,10 +343,15 @@ declare module '@micro-app/types' {
|
|
|
297
343
|
[appName: string]: (to: GuardLocation, from: GuardLocation) => void
|
|
298
344
|
}
|
|
299
345
|
|
|
300
|
-
type GlobalNormalGuard = ((
|
|
346
|
+
type GlobalNormalGuard = ((to: GuardLocation, from: GuardLocation, appName: string) => void)
|
|
301
347
|
|
|
302
348
|
type RouterGuard = AccurateGuard | GlobalNormalGuard
|
|
303
349
|
|
|
350
|
+
type SetDefaultPageOptions = {
|
|
351
|
+
name: string,
|
|
352
|
+
path: string,
|
|
353
|
+
}
|
|
354
|
+
|
|
304
355
|
// Router API for developer
|
|
305
356
|
interface Router {
|
|
306
357
|
// current route of all apps
|
|
@@ -355,10 +406,9 @@ declare module '@micro-app/types' {
|
|
|
355
406
|
afterEach(guard: RouterGuard): () => boolean
|
|
356
407
|
/**
|
|
357
408
|
* Add defaultPage to control the first rendered page
|
|
358
|
-
* @param
|
|
359
|
-
* @param path default page path
|
|
409
|
+
* @param options SetDefaultPageOptions
|
|
360
410
|
*/
|
|
361
|
-
setDefaultPage(
|
|
411
|
+
setDefaultPage(options: SetDefaultPageOptions): () => boolean
|
|
362
412
|
/**
|
|
363
413
|
* Clear data of defaultPage that set by setDefaultPage
|
|
364
414
|
*/
|
|
@@ -366,7 +416,7 @@ declare module '@micro-app/types' {
|
|
|
366
416
|
/**
|
|
367
417
|
* Get defaultPage that set by setDefaultPage
|
|
368
418
|
*/
|
|
369
|
-
getDefaultPage(key: PropertyKey): string |
|
|
419
|
+
getDefaultPage(key: PropertyKey): string | void
|
|
370
420
|
/**
|
|
371
421
|
* Attach specified active app router info to browser url
|
|
372
422
|
*/
|