@micro-zoe/micro-app 1.0.0-alpha.5 → 1.0.0-alpha.8

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.8",
4
4
  "description": "A lightweight, efficient and powerful micro front-end framework",
5
5
  "private": false,
6
6
  "main": "lib/index.min.js",
@@ -7,29 +7,57 @@ declare module '@micro-app/types' {
7
7
 
8
8
  type microAppWindowType = Window & any
9
9
 
10
- type appName = string
10
+ type AppName = string
11
+
12
+ type SourceAddress = string
13
+
14
+ type AttrsType = Map<string, string>
15
+
16
+ type RequestIdleCallbackOptions = {
17
+ timeout: number
18
+ }
19
+
20
+ type RequestIdleCallbackInfo = {
21
+ readonly didTimeout: boolean
22
+ timeRemaining: () => number
23
+ }
24
+
25
+ type fiberTasks = Array<() => Promise<void>> | null
26
+
27
+ interface EffectController {
28
+ recordEffect(): void
29
+ rebuildEffect(): void
30
+ releaseEffect(): void
31
+ }
32
+
33
+ interface SandBoxStartParams {
34
+ umdMode: boolean
35
+ baseroute: string
36
+ useMemoryRouter: boolean
37
+ defaultPage: string
38
+ disablePatchRequest: boolean
39
+ }
40
+
41
+ interface SandBoxStopParams {
42
+ umdMode: boolean
43
+ keepRouteState: boolean
44
+ clearEventSource: boolean
45
+ clearData: boolean
46
+ }
11
47
 
12
48
  interface SandBoxInterface {
13
49
  proxyWindow: WindowProxy
14
50
  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
51
+ start (startParams: SandBoxStartParams): void
52
+ stop (stopParams: SandBoxStopParams): void
53
+ releaseGlobalEffect (clearData?: boolean): void
27
54
  // record umd snapshot before the first execution of umdHookMount
28
- recordUmdSnapshot (): void
55
+ recordEffectSnapshot (): void
29
56
  // rebuild umd snapshot before remount umd app
30
- rebuildUmdSnapshot (): void
57
+ rebuildEffectSnapshot (): void
31
58
  setRouteInfoForKeepAliveApp (): void
32
59
  removeRouteInfoForKeepAliveApp (): void
60
+ setPreRenderState (state: boolean): void
33
61
  }
34
62
 
35
63
  interface SandBoxAdapter {
@@ -46,71 +74,93 @@ declare module '@micro-app/types' {
46
74
  // injectReactHRMProperty (): void
47
75
  }
48
76
 
49
- type sourceLinkInfo = {
50
- code: string // code
51
- placeholder?: Comment | null // placeholder comment
52
- isGlobal: boolean // is global asset
77
+ type LinkSourceInfo = {
78
+ code: string, // source code
79
+ appSpace: Record<string, {
80
+ attrs: Map<string, string>, // active element.attributes
81
+ placeholder?: Comment | null, // placeholder comment
82
+ parsedCode?: string, // parsed code
83
+ prefix?: string, // micro-app[name=appName]
84
+ }>
85
+ }
86
+
87
+ type ScriptSourceInfo = {
88
+ code: string, // source code
89
+ isExternal: boolean, // external script
90
+ appSpace: Record<string, {
91
+ async: boolean, // async script
92
+ defer: boolean, // defer script
93
+ module: boolean, // module type script
94
+ inline: boolean, // run js with inline script
95
+ pure: boolean, // pure script
96
+ attrs: Map<string, string>, // element attributes
97
+ parsedCode?: string, // bind code
98
+ parsedFunction?: Function | null, // code to function
99
+ wrapInSandBox?: boolean // use sandbox
100
+ }>
53
101
  }
54
102
 
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
103
+ type sourceType = {
104
+ html: HTMLElement | null, // html address
105
+ links: Set<string>, // style/link address list
106
+ scripts: Set<string>, // script address list
64
107
  }
65
108
 
66
- interface sourceType {
67
- html?: HTMLElement
68
- links: Map<string, sourceLinkInfo>
69
- scripts: Map<string, sourceScriptInfo>
109
+ interface MountParam {
110
+ container: HTMLElement | ShadowRoot // app container
111
+ inline: boolean // run js in inline mode
112
+ useMemoryRouter: boolean // use virtual router
113
+ defaultPage: string // default page of virtual router
114
+ baseroute: string // route prefix, default is ''
115
+ disablePatchRequest: boolean // prevent rewrite request method of child app
116
+ fiber: boolean // run js in fiber mode
117
+ esmodule: boolean // support type='module' script
118
+ // hiddenRouter: boolean
119
+ }
120
+
121
+ interface UnmountParam {
122
+ destroy: boolean, // completely destroy, delete cache resources
123
+ clearData: boolean // clear data of dateCenter
124
+ keepRouteState: boolean // keep route state when unmount, default is false
125
+ unmountcb?: CallableFunction // callback of unmount
70
126
  }
71
127
 
72
128
  // app instance
73
129
  interface AppInterface {
74
- isPrefetch: boolean // whether prefetch app, default is false
75
- prefetchResolve: (() => void) | null // prefetch callback
130
+ source: sourceType // source list
131
+ sandBox: SandBoxInterface | null // sandbox
76
132
  name: string // app name
77
133
  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
134
  scopecss: boolean // whether use css scoped, default is true
82
135
  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 ''
85
- 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
136
+ inline: boolean // whether js runs in inline script mode, default is false
137
+ esmodule: boolean // support esmodule in script
138
+ ssrUrl: string // html path in ssr mode
139
+ container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, div(keep-alive)
89
140
  umdMode: boolean // is umd mode
90
- defaultPage: string // default page when mount
141
+ fiber: boolean // fiber mode
142
+ useMemoryRouter: boolean // use virtual router
143
+ isPrefetch: boolean // whether prefetch app, default is false
144
+ isPrerender: boolean
145
+ prefetchLevel?: number
146
+ // defaultPage: string // default page when mount
147
+ // baseroute: string // route prefix, default is ''
148
+ // hiddenRouter: boolean // hide router info of child from browser url
91
149
 
92
150
  // Load resources
93
151
  loadSourceCode (): void
94
152
 
95
153
  // resource is loaded
96
- onLoad (html: HTMLElement): void
154
+ onLoad (html: HTMLElement, defaultPage?: string, disablePatchRequest?: boolean): void
97
155
 
98
156
  // Error loading HTML
99
157
  onLoadError (e: Error): void
100
158
 
101
159
  // 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
160
+ mount (mountParams: MountParam): void
111
161
 
112
162
  // unmount app
113
- unmount (destroy: boolean, unmountcb?: CallableFunction): void
163
+ unmount (unmountParam: UnmountParam): void
114
164
 
115
165
  // app rendering error
116
166
  onerror (e: Error): void
@@ -124,7 +174,7 @@ declare module '@micro-app/types' {
124
174
  actionsForCompletelyDestroy (): void
125
175
 
126
176
  // hidden app when disconnectedCallback with keep-alive
127
- hiddenKeepAliveApp (): void
177
+ hiddenKeepAliveApp (callback?: CallableFunction): void
128
178
 
129
179
  // show app when connectedCallback with keep-alive
130
180
  showKeepAliveApp (container: HTMLElement | ShadowRoot): void
@@ -144,7 +194,7 @@ declare module '@micro-app/types' {
144
194
  attributeChangedCallback (a: 'name' | 'url', o: string, n: string): void
145
195
  }
146
196
 
147
- type prefetchParam = {
197
+ interface prefetchParam {
148
198
  name: string,
149
199
  url: string,
150
200
  // old config 👇
@@ -153,7 +203,11 @@ declare module '@micro-app/types' {
153
203
  // old config 👆
154
204
  'disable-scopecss'?: boolean
155
205
  'disable-sandbox'?: boolean
156
- 'disable-memory-router'?: boolean
206
+ inline?: boolean
207
+ esmodule?: boolean
208
+ level?: number
209
+ 'default-page'?: string
210
+ 'disable-patch-request'?: boolean
157
211
  }
158
212
 
159
213
  // prefetch params
@@ -161,11 +215,14 @@ declare module '@micro-app/types' {
161
215
 
162
216
  // lifeCycles
163
217
  interface lifeCyclesType {
164
- created?(e?: CustomEvent): void
165
- beforemount?(e?: CustomEvent): void
166
- mounted?(e?: CustomEvent): void
167
- unmount?(e?: CustomEvent): void
168
- error?(e?: CustomEvent): void
218
+ created(e: CustomEvent): void
219
+ beforemount(e: CustomEvent): void
220
+ mounted(e: CustomEvent): void
221
+ unmount(e: CustomEvent): void
222
+ error(e: CustomEvent): void
223
+ beforeshow(e: CustomEvent): void
224
+ aftershow(e: CustomEvent): void
225
+ afterhidden(e: CustomEvent): void
169
226
  }
170
227
 
171
228
  type AssetsChecker = (url: string) => boolean;
@@ -182,11 +239,11 @@ declare module '@micro-app/types' {
182
239
  // Ignore JS or CSS
183
240
  ignoreChecker?: AssetsChecker
184
241
  // options for plugin as the third parameter of loader
185
- options?: unknown
242
+ options?: Record<string, unknown>
186
243
  // handle function
187
- loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
244
+ loader?: (code: string, url: string) => string
188
245
  // html processor
189
- processHtml?: (code: string, url: string, options: unknown) => string
246
+ processHtml?: (code: string, url: string) => string
190
247
  }>
191
248
 
192
249
  // plugin for special app
@@ -201,15 +258,20 @@ declare module '@micro-app/types' {
201
258
  // Ignore JS or CSS
202
259
  ignoreChecker?: AssetsChecker
203
260
  // options for plugin as the third parameter of loader
204
- options?: unknown
261
+ options?: Record<string, unknown>
205
262
  // handle function
206
- loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
263
+ loader?: (code: string, url: string) => string
207
264
  // html processor
208
- processHtml?: (code: string, url: string, options: unknown) => string
265
+ processHtml?: (code: string, url: string) => string
209
266
  }>
210
267
  }
211
268
  }
212
269
 
270
+ type GetActiveAppsParam = {
271
+ excludeHiddenApp?: boolean,
272
+ excludePreRender?: boolean,
273
+ }
274
+
213
275
  type fetchType = (url: string, options: Record<string, unknown>, appName: string | null) => Promise<string>
214
276
 
215
277
  type globalAssetsType = {
@@ -217,11 +279,11 @@ declare module '@micro-app/types' {
217
279
  css?: string[],
218
280
  }
219
281
 
220
- type OptionsType = {
221
- tagName?: string
222
- 'shadowDOM'?: boolean
223
- 'destroy'?: boolean
224
- 'inline'?: boolean
282
+ interface MicroAppConfig {
283
+ shadowDOM?: boolean
284
+ destroy?: boolean
285
+ destory?: boolean
286
+ inline?: boolean
225
287
  // old config 👇
226
288
  disableScopecss?: boolean
227
289
  disableSandbox?: boolean
@@ -232,28 +294,29 @@ declare module '@micro-app/types' {
232
294
  'disable-patch-request'?: boolean
233
295
  'keep-router-state'?: boolean
234
296
  'hidden-router'?: boolean
235
- 'esmodule'?: boolean
236
- 'ssr'?: boolean
297
+ 'keep-alive'?: boolean
298
+ 'clear-data'?: boolean
299
+ esmodule?: boolean
300
+ ssr?: boolean
301
+ fiber?: boolean
302
+ prefetchLevel?: number
303
+ prefetchDelay?: number
304
+ }
305
+
306
+ interface OptionsType extends MicroAppConfig {
307
+ tagName?: string
237
308
  lifeCycles?: lifeCyclesType
238
309
  preFetchApps?: prefetchParamList
239
310
  plugins?: plugins
240
311
  fetch?: fetchType
241
312
  globalAssets?: globalAssetsType,
313
+ excludeAssetFilter?: (assetUrl: string) => boolean
242
314
  }
243
315
 
244
316
  // MicroApp config
245
- interface MicroAppConfigType {
317
+ interface MicroAppBaseType {
246
318
  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
319
+ options: OptionsType
257
320
  preFetch(apps: prefetchParamList): void
258
321
  router: Router // eslint-disable-line
259
322
  start(options?: OptionsType): void
@@ -319,7 +382,7 @@ declare module '@micro-app/types' {
319
382
  [appName: string]: (to: GuardLocation, from: GuardLocation) => void
320
383
  }
321
384
 
322
- type GlobalNormalGuard = ((appName: string, to: GuardLocation, from: GuardLocation) => void)
385
+ type GlobalNormalGuard = ((to: GuardLocation, from: GuardLocation, appName: string) => void)
323
386
 
324
387
  type RouterGuard = AccurateGuard | GlobalNormalGuard
325
388
 
@@ -328,6 +391,11 @@ declare module '@micro-app/types' {
328
391
  path: string,
329
392
  }
330
393
 
394
+ type AttachAllToURLParam = {
395
+ includeHiddenApp?: boolean,
396
+ includePreRender?: boolean,
397
+ }
398
+
331
399
  // Router API for developer
332
400
  interface Router {
333
401
  // current route of all apps
@@ -392,7 +460,7 @@ declare module '@micro-app/types' {
392
460
  /**
393
461
  * Get defaultPage that set by setDefaultPage
394
462
  */
395
- getDefaultPage(key: PropertyKey): string | undefined
463
+ getDefaultPage(key: PropertyKey): string | void
396
464
  /**
397
465
  * Attach specified active app router info to browser url
398
466
  */
@@ -400,7 +468,7 @@ declare module '@micro-app/types' {
400
468
  /**
401
469
  * Attach all active app router info to browser url
402
470
  */
403
- attachAllToURL(): void
471
+ attachAllToURL(options: AttachAllToURLParam): void
404
472
  /**
405
473
  * Record base app router, let child app control base app navigation
406
474
  * It is global data