@micro-zoe/micro-app 1.0.0-alpha.5 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micro-zoe/micro-app",
3
- "version": "1.0.0-alpha.5",
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",
@@ -9,21 +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
- umdMode: boolean,
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
35
+ start (startParams: SandBoxStartParams): void
36
+ stop (stopParams: SandBoxStopParams): void
27
37
  // record umd snapshot before the first execution of umdHookMount
28
38
  recordUmdSnapshot (): void
29
39
  // rebuild umd snapshot before remount umd app
@@ -46,48 +56,71 @@ declare module '@micro-app/types' {
46
56
  // injectReactHRMProperty (): void
47
57
  }
48
58
 
49
- type sourceLinkInfo = {
50
- code: string // code
51
- placeholder?: Comment | null // placeholder comment
52
- isGlobal: boolean // is global asset
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
+ }>
53
67
  }
54
68
 
55
- type sourceScriptInfo = {
56
- code: string // code
57
- isExternal: boolean // external script
58
- isDynamic: boolean // dynamic create script
59
- async: boolean // async script
60
- defer: boolean // defer script
61
- module: boolean // module type script
62
- isGlobal?: boolean // share js to global
63
- code2Function?: Function // code to Function
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
+ }>
64
83
  }
65
84
 
66
- interface sourceType {
67
- html?: HTMLElement
68
- links: Map<string, sourceLinkInfo>
69
- scripts: Map<string, sourceScriptInfo>
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
70
102
  }
71
103
 
72
104
  // app instance
73
105
  interface AppInterface {
74
- isPrefetch: boolean // whether prefetch app, default is false
75
- prefetchResolve: (() => void) | null // prefetch callback
106
+ source: sourceType // source list
107
+ sandBox: SandBoxInterface | null // sandbox
76
108
  name: string // app name
77
109
  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
110
  scopecss: boolean // whether use css scoped, default is true
82
111
  useSandbox: boolean // whether use js sandbox, default is true
83
- useMemoryRouter: boolean // whether use memoryRouter, default is true
84
- baseroute: string // route prefix, default is ''
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)
85
117
  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
118
  umdMode: boolean // is umd mode
90
- defaultPage: string // default page when mount
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
91
124
 
92
125
  // Load resources
93
126
  loadSourceCode (): void
@@ -99,15 +132,7 @@ declare module '@micro-app/types' {
99
132
  onLoadError (e: Error): void
100
133
 
101
134
  // 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
135
+ mount (mountParams: MountParam): void
111
136
 
112
137
  // unmount app
113
138
  unmount (destroy: boolean, unmountcb?: CallableFunction): void
@@ -153,7 +178,8 @@ declare module '@micro-app/types' {
153
178
  // old config 👆
154
179
  'disable-scopecss'?: boolean
155
180
  'disable-sandbox'?: boolean
156
- 'disable-memory-router'?: boolean
181
+ inline?: boolean
182
+ esmodule?: boolean
157
183
  }
158
184
 
159
185
  // prefetch params
@@ -166,6 +192,9 @@ declare module '@micro-app/types' {
166
192
  mounted?(e?: CustomEvent): void
167
193
  unmount?(e?: CustomEvent): void
168
194
  error?(e?: CustomEvent): void
195
+ beforeshow?(e?: CustomEvent): void
196
+ aftershow?(e?: CustomEvent): void
197
+ afterhidden?(e?: CustomEvent): void
169
198
  }
170
199
 
171
200
  type AssetsChecker = (url: string) => boolean;
@@ -182,11 +211,11 @@ declare module '@micro-app/types' {
182
211
  // Ignore JS or CSS
183
212
  ignoreChecker?: AssetsChecker
184
213
  // options for plugin as the third parameter of loader
185
- options?: unknown
214
+ options?: Record<string, unknown>
186
215
  // handle function
187
- loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
216
+ loader?: (code: string, url: string) => string
188
217
  // html processor
189
- processHtml?: (code: string, url: string, options: unknown) => string
218
+ processHtml?: (code: string, url: string) => string
190
219
  }>
191
220
 
192
221
  // plugin for special app
@@ -201,11 +230,11 @@ declare module '@micro-app/types' {
201
230
  // Ignore JS or CSS
202
231
  ignoreChecker?: AssetsChecker
203
232
  // options for plugin as the third parameter of loader
204
- options?: unknown
233
+ options?: Record<string, unknown>
205
234
  // handle function
206
- loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
235
+ loader?: (code: string, url: string) => string
207
236
  // html processor
208
- processHtml?: (code: string, url: string, options: unknown) => string
237
+ processHtml?: (code: string, url: string) => string
209
238
  }>
210
239
  }
211
240
  }
@@ -219,9 +248,10 @@ declare module '@micro-app/types' {
219
248
 
220
249
  type OptionsType = {
221
250
  tagName?: string
222
- 'shadowDOM'?: boolean
223
- 'destroy'?: boolean
224
- 'inline'?: boolean
251
+ shadowDOM?: boolean
252
+ destroy?: boolean
253
+ destory?: boolean
254
+ inline?: boolean
225
255
  // old config 👇
226
256
  disableScopecss?: boolean
227
257
  disableSandbox?: boolean
@@ -232,28 +262,22 @@ declare module '@micro-app/types' {
232
262
  'disable-patch-request'?: boolean
233
263
  'keep-router-state'?: boolean
234
264
  'hidden-router'?: boolean
235
- 'esmodule'?: boolean
236
- 'ssr'?: boolean
265
+ 'keep-alive'?: boolean
266
+ esmodule?: boolean
267
+ ssr?: boolean
268
+ fiber?: boolean
237
269
  lifeCycles?: lifeCyclesType
238
270
  preFetchApps?: prefetchParamList
239
271
  plugins?: plugins
240
272
  fetch?: fetchType
241
273
  globalAssets?: globalAssetsType,
274
+ excludeAssetFilter?: (assetUrl: string) => boolean
242
275
  }
243
276
 
244
277
  // MicroApp config
245
278
  interface MicroAppConfigType {
246
279
  tagName: string
247
- shadowDOM?: boolean
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
280
+ options: OptionsType
257
281
  preFetch(apps: prefetchParamList): void
258
282
  router: Router // eslint-disable-line
259
283
  start(options?: OptionsType): void
@@ -319,7 +343,7 @@ declare module '@micro-app/types' {
319
343
  [appName: string]: (to: GuardLocation, from: GuardLocation) => void
320
344
  }
321
345
 
322
- type GlobalNormalGuard = ((appName: string, to: GuardLocation, from: GuardLocation) => void)
346
+ type GlobalNormalGuard = ((to: GuardLocation, from: GuardLocation, appName: string) => void)
323
347
 
324
348
  type RouterGuard = AccurateGuard | GlobalNormalGuard
325
349
 
@@ -392,7 +416,7 @@ declare module '@micro-app/types' {
392
416
  /**
393
417
  * Get defaultPage that set by setDefaultPage
394
418
  */
395
- getDefaultPage(key: PropertyKey): string | undefined
419
+ getDefaultPage(key: PropertyKey): string | void
396
420
  /**
397
421
  * Attach specified active app router info to browser url
398
422
  */