@micro-zoe/micro-app 1.0.0-alpha.4 → 1.0.0-alpha.7
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 +98 -29
- package/lib/index.esm.js +1316 -521
- 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 +1 -1
- package/typings/global.d.ts +120 -84
package/package.json
CHANGED
package/typings/global.d.ts
CHANGED
|
@@ -7,23 +7,34 @@ declare module '@micro-app/types' {
|
|
|
7
7
|
|
|
8
8
|
type microAppWindowType = Window & any
|
|
9
9
|
|
|
10
|
-
type
|
|
10
|
+
type AppName = string
|
|
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
|
+
clearData: boolean
|
|
31
|
+
}
|
|
11
32
|
|
|
12
33
|
interface SandBoxInterface {
|
|
13
34
|
proxyWindow: WindowProxy
|
|
14
35
|
microAppWindow: Window // Proxy target
|
|
15
|
-
start (
|
|
16
|
-
|
|
17
|
-
baseRoute: string,
|
|
18
|
-
useMemoryRouter: boolean,
|
|
19
|
-
defaultPage: string,
|
|
20
|
-
disablePatchRequest: boolean,
|
|
21
|
-
): void
|
|
22
|
-
stop (
|
|
23
|
-
umdMode: boolean,
|
|
24
|
-
keepRouteState: boolean,
|
|
25
|
-
clearEventSource: boolean,
|
|
26
|
-
): void
|
|
36
|
+
start (startParams: SandBoxStartParams): void
|
|
37
|
+
stop (stopParams: SandBoxStopParams): void
|
|
27
38
|
// record umd snapshot before the first execution of umdHookMount
|
|
28
39
|
recordUmdSnapshot (): void
|
|
29
40
|
// rebuild umd snapshot before remount umd app
|
|
@@ -46,48 +57,78 @@ declare module '@micro-app/types' {
|
|
|
46
57
|
// injectReactHRMProperty (): void
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
type
|
|
50
|
-
code: string // code
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
type LinkSourceInfo = {
|
|
61
|
+
code: string, // source code
|
|
62
|
+
appSpace: Record<string, {
|
|
63
|
+
attrs: Map<string, string>, // active element.attributes
|
|
64
|
+
placeholder?: Comment | null, // placeholder comment
|
|
65
|
+
parsedCode?: string, // parsed code
|
|
66
|
+
prefix?: string, // micro-app[name=appName]
|
|
67
|
+
}>
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
type
|
|
56
|
-
code: string // code
|
|
57
|
-
isExternal: boolean // external script
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
type ScriptSourceInfo = {
|
|
71
|
+
code: string, // source code
|
|
72
|
+
isExternal: boolean, // external script
|
|
73
|
+
appSpace: Record<string, {
|
|
74
|
+
async: boolean, // async script
|
|
75
|
+
defer: boolean, // defer script
|
|
76
|
+
module: boolean, // module type script
|
|
77
|
+
inline: boolean, // run js with inline script
|
|
78
|
+
pure: boolean, // pure script
|
|
79
|
+
attrs: Map<string, string>, // element attributes
|
|
80
|
+
parsedCode?: string, // bind code
|
|
81
|
+
parsedFunction?: Function | null, // code to function
|
|
82
|
+
wrapInSandBox?: boolean // use sandbox
|
|
83
|
+
}>
|
|
64
84
|
}
|
|
65
85
|
|
|
66
|
-
|
|
67
|
-
html
|
|
68
|
-
links:
|
|
69
|
-
scripts:
|
|
86
|
+
type sourceType = {
|
|
87
|
+
html: HTMLElement | null, // html address
|
|
88
|
+
links: Set<string>, // style/link address list
|
|
89
|
+
scripts: Set<string>, // script address list
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface MountParam {
|
|
93
|
+
container: HTMLElement | ShadowRoot
|
|
94
|
+
inline: boolean
|
|
95
|
+
useMemoryRouter: boolean
|
|
96
|
+
baseroute: string
|
|
97
|
+
keepRouteState: boolean
|
|
98
|
+
defaultPage: string
|
|
99
|
+
hiddenRouter: boolean
|
|
100
|
+
disablePatchRequest: boolean
|
|
101
|
+
fiber: boolean
|
|
102
|
+
esmodule: boolean
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface UnmountParam {
|
|
107
|
+
destroy: boolean,
|
|
108
|
+
clearData: boolean
|
|
109
|
+
unmountcb?: CallableFunction
|
|
70
110
|
}
|
|
71
111
|
|
|
72
112
|
// app instance
|
|
73
113
|
interface AppInterface {
|
|
74
|
-
|
|
75
|
-
|
|
114
|
+
source: sourceType // source list
|
|
115
|
+
sandBox: SandBoxInterface | null // sandbox
|
|
76
116
|
name: string // app name
|
|
77
117
|
url: string // app url
|
|
78
|
-
ssrUrl: string // html path in ssr mode
|
|
79
|
-
container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, DIV(keep-alive)
|
|
80
|
-
inline: boolean // whether js runs in inline script mode, default is false
|
|
81
118
|
scopecss: boolean // whether use css scoped, default is true
|
|
82
119
|
useSandbox: boolean // whether use js sandbox, default is true
|
|
83
|
-
|
|
84
|
-
|
|
120
|
+
inline: boolean // whether js runs in inline script mode, default is false
|
|
121
|
+
esmodule: boolean // support esmodule in script
|
|
122
|
+
ssrUrl: string // html path in ssr mode
|
|
123
|
+
isPrefetch: boolean // whether prefetch app, default is false
|
|
124
|
+
container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, div(keep-alive)
|
|
85
125
|
keepRouteState: boolean // keep route state when unmount, default is false
|
|
86
|
-
hiddenRouter: boolean // hide router info of child from browser url
|
|
87
|
-
source: sourceType // sources of css, js, html
|
|
88
|
-
sandBox: SandBoxInterface | null // sandbox
|
|
89
126
|
umdMode: boolean // is umd mode
|
|
90
|
-
|
|
127
|
+
fiber: boolean // fiber mode
|
|
128
|
+
useMemoryRouter: boolean // use virtual router
|
|
129
|
+
// defaultPage: string // default page when mount
|
|
130
|
+
// baseroute: string // route prefix, default is ''
|
|
131
|
+
// hiddenRouter: boolean // hide router info of child from browser url
|
|
91
132
|
|
|
92
133
|
// Load resources
|
|
93
134
|
loadSourceCode (): void
|
|
@@ -99,18 +140,10 @@ declare module '@micro-app/types' {
|
|
|
99
140
|
onLoadError (e: Error): void
|
|
100
141
|
|
|
101
142
|
// mount app
|
|
102
|
-
mount (
|
|
103
|
-
container?: HTMLElement | ShadowRoot,
|
|
104
|
-
inline?: boolean,
|
|
105
|
-
baseroute?: string,
|
|
106
|
-
keepRouteState?: boolean,
|
|
107
|
-
defaultPage?: string,
|
|
108
|
-
hiddenRouter?: boolean,
|
|
109
|
-
disablePatchRequest?: boolean,
|
|
110
|
-
): void
|
|
143
|
+
mount (mountParams: MountParam): void
|
|
111
144
|
|
|
112
145
|
// unmount app
|
|
113
|
-
unmount (
|
|
146
|
+
unmount (unmountParam: UnmountParam): void
|
|
114
147
|
|
|
115
148
|
// app rendering error
|
|
116
149
|
onerror (e: Error): void
|
|
@@ -124,7 +157,7 @@ declare module '@micro-app/types' {
|
|
|
124
157
|
actionsForCompletelyDestroy (): void
|
|
125
158
|
|
|
126
159
|
// hidden app when disconnectedCallback with keep-alive
|
|
127
|
-
hiddenKeepAliveApp (): void
|
|
160
|
+
hiddenKeepAliveApp (callback?: CallableFunction): void
|
|
128
161
|
|
|
129
162
|
// show app when connectedCallback with keep-alive
|
|
130
163
|
showKeepAliveApp (container: HTMLElement | ShadowRoot): void
|
|
@@ -153,7 +186,8 @@ declare module '@micro-app/types' {
|
|
|
153
186
|
// old config 👆
|
|
154
187
|
'disable-scopecss'?: boolean
|
|
155
188
|
'disable-sandbox'?: boolean
|
|
156
|
-
|
|
189
|
+
inline?: boolean
|
|
190
|
+
esmodule?: boolean
|
|
157
191
|
}
|
|
158
192
|
|
|
159
193
|
// prefetch params
|
|
@@ -161,11 +195,14 @@ declare module '@micro-app/types' {
|
|
|
161
195
|
|
|
162
196
|
// lifeCycles
|
|
163
197
|
interface lifeCyclesType {
|
|
164
|
-
created
|
|
165
|
-
beforemount
|
|
166
|
-
mounted
|
|
167
|
-
unmount
|
|
168
|
-
error
|
|
198
|
+
created(e: CustomEvent): void
|
|
199
|
+
beforemount(e: CustomEvent): void
|
|
200
|
+
mounted(e: CustomEvent): void
|
|
201
|
+
unmount(e: CustomEvent): void
|
|
202
|
+
error(e: CustomEvent): void
|
|
203
|
+
beforeshow(e: CustomEvent): void
|
|
204
|
+
aftershow(e: CustomEvent): void
|
|
205
|
+
afterhidden(e: CustomEvent): void
|
|
169
206
|
}
|
|
170
207
|
|
|
171
208
|
type AssetsChecker = (url: string) => boolean;
|
|
@@ -182,11 +219,11 @@ declare module '@micro-app/types' {
|
|
|
182
219
|
// Ignore JS or CSS
|
|
183
220
|
ignoreChecker?: AssetsChecker
|
|
184
221
|
// options for plugin as the third parameter of loader
|
|
185
|
-
options?: unknown
|
|
222
|
+
options?: Record<string, unknown>
|
|
186
223
|
// handle function
|
|
187
|
-
loader?: (code: string, url: string
|
|
224
|
+
loader?: (code: string, url: string) => string
|
|
188
225
|
// html processor
|
|
189
|
-
processHtml?: (code: string, url: string
|
|
226
|
+
processHtml?: (code: string, url: string) => string
|
|
190
227
|
}>
|
|
191
228
|
|
|
192
229
|
// plugin for special app
|
|
@@ -201,11 +238,11 @@ declare module '@micro-app/types' {
|
|
|
201
238
|
// Ignore JS or CSS
|
|
202
239
|
ignoreChecker?: AssetsChecker
|
|
203
240
|
// options for plugin as the third parameter of loader
|
|
204
|
-
options?: unknown
|
|
241
|
+
options?: Record<string, unknown>
|
|
205
242
|
// handle function
|
|
206
|
-
loader?: (code: string, url: string
|
|
243
|
+
loader?: (code: string, url: string) => string
|
|
207
244
|
// html processor
|
|
208
|
-
processHtml?: (code: string, url: string
|
|
245
|
+
processHtml?: (code: string, url: string) => string
|
|
209
246
|
}>
|
|
210
247
|
}
|
|
211
248
|
}
|
|
@@ -217,11 +254,11 @@ declare module '@micro-app/types' {
|
|
|
217
254
|
css?: string[],
|
|
218
255
|
}
|
|
219
256
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
257
|
+
interface MicroAppConfig {
|
|
258
|
+
shadowDOM?: boolean
|
|
259
|
+
destroy?: boolean
|
|
260
|
+
destory?: boolean
|
|
261
|
+
inline?: boolean
|
|
225
262
|
// old config 👇
|
|
226
263
|
disableScopecss?: boolean
|
|
227
264
|
disableSandbox?: boolean
|
|
@@ -232,28 +269,27 @@ declare module '@micro-app/types' {
|
|
|
232
269
|
'disable-patch-request'?: boolean
|
|
233
270
|
'keep-router-state'?: boolean
|
|
234
271
|
'hidden-router'?: boolean
|
|
235
|
-
'
|
|
236
|
-
'
|
|
272
|
+
'keep-alive'?: boolean
|
|
273
|
+
'clear-data'?: boolean
|
|
274
|
+
esmodule?: boolean
|
|
275
|
+
ssr?: boolean
|
|
276
|
+
fiber?: boolean
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface OptionsType extends MicroAppConfig {
|
|
280
|
+
tagName?: string
|
|
237
281
|
lifeCycles?: lifeCyclesType
|
|
238
282
|
preFetchApps?: prefetchParamList
|
|
239
283
|
plugins?: plugins
|
|
240
284
|
fetch?: fetchType
|
|
241
285
|
globalAssets?: globalAssetsType,
|
|
286
|
+
excludeAssetFilter?: (assetUrl: string) => boolean
|
|
242
287
|
}
|
|
243
288
|
|
|
244
289
|
// MicroApp config
|
|
245
|
-
interface
|
|
290
|
+
interface MicroAppBaseType {
|
|
246
291
|
tagName: string
|
|
247
|
-
|
|
248
|
-
destroy?: boolean
|
|
249
|
-
inline?: boolean
|
|
250
|
-
disableScopecss?: boolean
|
|
251
|
-
disableSandbox?: boolean
|
|
252
|
-
disableMemoryRouter?: boolean
|
|
253
|
-
ssr?: boolean
|
|
254
|
-
lifeCycles?: lifeCyclesType
|
|
255
|
-
plugins?: plugins
|
|
256
|
-
fetch?: fetchType
|
|
292
|
+
options: OptionsType
|
|
257
293
|
preFetch(apps: prefetchParamList): void
|
|
258
294
|
router: Router // eslint-disable-line
|
|
259
295
|
start(options?: OptionsType): void
|
|
@@ -319,7 +355,7 @@ declare module '@micro-app/types' {
|
|
|
319
355
|
[appName: string]: (to: GuardLocation, from: GuardLocation) => void
|
|
320
356
|
}
|
|
321
357
|
|
|
322
|
-
type GlobalNormalGuard = ((
|
|
358
|
+
type GlobalNormalGuard = ((to: GuardLocation, from: GuardLocation, appName: string) => void)
|
|
323
359
|
|
|
324
360
|
type RouterGuard = AccurateGuard | GlobalNormalGuard
|
|
325
361
|
|
|
@@ -392,7 +428,7 @@ declare module '@micro-app/types' {
|
|
|
392
428
|
/**
|
|
393
429
|
* Get defaultPage that set by setDefaultPage
|
|
394
430
|
*/
|
|
395
|
-
getDefaultPage(key: PropertyKey): string |
|
|
431
|
+
getDefaultPage(key: PropertyKey): string | void
|
|
396
432
|
/**
|
|
397
433
|
* Attach specified active app router info to browser url
|
|
398
434
|
*/
|