@micro-zoe/micro-app 0.8.7 → 1.0.0-alpha.2
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 +3 -3
- package/README.zh-cn.md +9 -15
- package/lib/index.d.ts +67 -21
- package/lib/index.esm.js +1648 -409
- 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 -3
- package/typings/global.d.ts +188 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micro-zoe/micro-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "A lightweight, efficient and powerful micro front-end framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "lib/index.min.js",
|
|
@@ -44,8 +44,6 @@
|
|
|
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",
|
|
49
47
|
"prepublishOnly": "yarn build"
|
|
50
48
|
},
|
|
51
49
|
"repository": {
|
package/typings/global.d.ts
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
declare module '@micro-app/types' {
|
|
2
2
|
type AttrType = string | null
|
|
3
3
|
|
|
4
|
+
type NormalKey = string | number
|
|
5
|
+
|
|
4
6
|
type Func = (...rest: any[]) => void
|
|
5
7
|
|
|
6
8
|
type microAppWindowType = Window & any
|
|
7
9
|
|
|
10
|
+
type appName = string
|
|
11
|
+
|
|
8
12
|
interface SandBoxInterface {
|
|
9
13
|
proxyWindow: WindowProxy
|
|
10
14
|
microAppWindow: Window // Proxy target
|
|
11
|
-
start (
|
|
12
|
-
|
|
15
|
+
start (
|
|
16
|
+
baseRoute: string,
|
|
17
|
+
useMemoryRouter: boolean,
|
|
18
|
+
defaultPage: string,
|
|
19
|
+
): void
|
|
20
|
+
stop (keepRouteState: boolean, clearEventSource: boolean): void
|
|
13
21
|
// record umd snapshot before the first execution of umdHookMount
|
|
14
22
|
recordUmdSnapshot (): void
|
|
15
23
|
// rebuild umd snapshot before remount umd app
|
|
16
24
|
rebuildUmdSnapshot (): void
|
|
25
|
+
setRouteInfoForKeepAliveApp (): void
|
|
26
|
+
removeRouteInfoForKeepAliveApp (): void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SandBoxAdapter {
|
|
30
|
+
// Variables that can only assigned to rawWindow
|
|
31
|
+
escapeSetterKeyList: PropertyKey[]
|
|
32
|
+
|
|
33
|
+
// Variables that can escape to rawWindow
|
|
34
|
+
staticEscapeProperties: PropertyKey[]
|
|
35
|
+
|
|
36
|
+
// Variables that scoped in child app
|
|
37
|
+
staticScopeProperties: PropertyKey[]
|
|
38
|
+
|
|
39
|
+
// adapter for react
|
|
40
|
+
// injectReactHRMProperty (): void
|
|
17
41
|
}
|
|
18
42
|
|
|
19
43
|
type sourceLinkInfo = {
|
|
@@ -50,10 +74,13 @@ declare module '@micro-app/types' {
|
|
|
50
74
|
inline: boolean // whether js runs in inline script mode, default is false
|
|
51
75
|
scopecss: boolean // whether use css scoped, default is true
|
|
52
76
|
useSandbox: boolean // whether use js sandbox, default is true
|
|
77
|
+
useMemoryRouter: boolean // whether use memoryRouter, default is true
|
|
53
78
|
baseroute: string // route prefix, default is ''
|
|
79
|
+
keepRouteState: boolean // keep route state when unmount, default is false
|
|
54
80
|
source: sourceType // sources of css, js, html
|
|
55
81
|
sandBox: SandBoxInterface | null // sandbox
|
|
56
82
|
umdMode: boolean // is umd mode
|
|
83
|
+
defaultPage: string // default page when mount
|
|
57
84
|
|
|
58
85
|
// Load resources
|
|
59
86
|
loadSourceCode (): void
|
|
@@ -69,6 +96,8 @@ declare module '@micro-app/types' {
|
|
|
69
96
|
container?: HTMLElement | ShadowRoot,
|
|
70
97
|
inline?: boolean,
|
|
71
98
|
baseroute?: string,
|
|
99
|
+
keepRouteState?: boolean,
|
|
100
|
+
defaultPage?: string,
|
|
72
101
|
): void
|
|
73
102
|
|
|
74
103
|
// unmount app
|
|
@@ -111,6 +140,7 @@ declare module '@micro-app/types' {
|
|
|
111
140
|
url: string,
|
|
112
141
|
disableScopecss?: boolean
|
|
113
142
|
disableSandbox?: boolean
|
|
143
|
+
disableMemoryRouter?: boolean
|
|
114
144
|
shadowDOM?: boolean
|
|
115
145
|
}
|
|
116
146
|
|
|
@@ -126,8 +156,6 @@ declare module '@micro-app/types' {
|
|
|
126
156
|
error?(e?: CustomEvent): void
|
|
127
157
|
}
|
|
128
158
|
|
|
129
|
-
type AssetsChecker = (url: string) => boolean;
|
|
130
|
-
|
|
131
159
|
type plugins = {
|
|
132
160
|
// global plugin
|
|
133
161
|
global?: Array<{
|
|
@@ -135,16 +163,10 @@ declare module '@micro-app/types' {
|
|
|
135
163
|
scopeProperties?: Array<PropertyKey>
|
|
136
164
|
// Properties that can be escape to rawWindow
|
|
137
165
|
escapeProperties?: Array<PropertyKey>
|
|
138
|
-
// Exclude JS or CSS
|
|
139
|
-
excludeChecker?: AssetsChecker
|
|
140
|
-
// Ignore JS or CSS
|
|
141
|
-
ignoreChecker?: AssetsChecker
|
|
142
166
|
// options for plugin as the third parameter of loader
|
|
143
167
|
options?: unknown
|
|
144
168
|
// handle function
|
|
145
169
|
loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
|
|
146
|
-
// html processor
|
|
147
|
-
processHtml?: (code: string, url: string, options: unknown) => string
|
|
148
170
|
}>
|
|
149
171
|
|
|
150
172
|
// plugin for special app
|
|
@@ -154,16 +176,10 @@ declare module '@micro-app/types' {
|
|
|
154
176
|
scopeProperties?: Array<PropertyKey>
|
|
155
177
|
// Properties that can be escape to rawWindow
|
|
156
178
|
escapeProperties?: Array<PropertyKey>
|
|
157
|
-
// Exclude JS or CSS
|
|
158
|
-
excludeChecker?: AssetsChecker
|
|
159
|
-
// Ignore JS or CSS
|
|
160
|
-
ignoreChecker?: AssetsChecker
|
|
161
179
|
// options for plugin as the third parameter of loader
|
|
162
180
|
options?: unknown
|
|
163
181
|
// handle function
|
|
164
182
|
loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
|
|
165
|
-
// html processor
|
|
166
|
-
processHtml?: (code: string, url: string, options: unknown) => string
|
|
167
183
|
}>
|
|
168
184
|
}
|
|
169
185
|
}
|
|
@@ -182,6 +198,7 @@ declare module '@micro-app/types' {
|
|
|
182
198
|
inline?: boolean
|
|
183
199
|
disableScopecss?: boolean
|
|
184
200
|
disableSandbox?: boolean
|
|
201
|
+
disableMemoryRouter?: boolean
|
|
185
202
|
ssr?: boolean
|
|
186
203
|
lifeCycles?: lifeCyclesType
|
|
187
204
|
preFetchApps?: prefetchParamList
|
|
@@ -198,16 +215,171 @@ declare module '@micro-app/types' {
|
|
|
198
215
|
inline?: boolean
|
|
199
216
|
disableScopecss?: boolean
|
|
200
217
|
disableSandbox?: boolean
|
|
218
|
+
disableMemoryRouter?: boolean
|
|
201
219
|
ssr?: boolean
|
|
202
220
|
lifeCycles?: lifeCyclesType
|
|
203
221
|
plugins?: plugins
|
|
204
222
|
fetch?: fetchType
|
|
205
223
|
preFetch(apps: prefetchParamList): void
|
|
224
|
+
router: Router // eslint-disable-line
|
|
206
225
|
start(options?: OptionsType): void
|
|
207
226
|
}
|
|
208
227
|
|
|
209
228
|
// special CallableFunction for interact
|
|
210
229
|
type CallableFunctionForInteract = CallableFunction & { __APP_NAME__?: string, __AUTO_TRIGGER__?: boolean }
|
|
230
|
+
|
|
231
|
+
interface ShadowLocation {
|
|
232
|
+
[k: string]: string
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
interface MicroLocation extends Location, URL {
|
|
236
|
+
// shadowLocation is the current location information (href, pathname, search, hash)
|
|
237
|
+
shadowLocation: ShadowLocation
|
|
238
|
+
fullPath: string
|
|
239
|
+
[key: string]: any
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
type MicroHistory = ProxyHandler<History>
|
|
243
|
+
type MicroState = any
|
|
244
|
+
type HistoryProxyValue =
|
|
245
|
+
Pick<
|
|
246
|
+
History,
|
|
247
|
+
'length' |
|
|
248
|
+
'scrollRestoration' |
|
|
249
|
+
'state' |
|
|
250
|
+
'back' |
|
|
251
|
+
'forward' |
|
|
252
|
+
'go' |
|
|
253
|
+
'pushState' |
|
|
254
|
+
'replaceState'
|
|
255
|
+
> | CallableFunction
|
|
256
|
+
interface MicroRouter {
|
|
257
|
+
microLocation: MicroLocation
|
|
258
|
+
microHistory: MicroHistory
|
|
259
|
+
}
|
|
260
|
+
type LocationQueryValue = string | null
|
|
261
|
+
type LocationQueryObject = Record<
|
|
262
|
+
string,
|
|
263
|
+
LocationQueryValue | LocationQueryValue[]
|
|
264
|
+
>
|
|
265
|
+
|
|
266
|
+
type LocationQuery = {
|
|
267
|
+
hashQuery?: LocationQueryObject,
|
|
268
|
+
searchQuery?: LocationQueryObject
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
type GuardLocation = Record<keyof MicroLocation, any>
|
|
272
|
+
|
|
273
|
+
type CurrentRoute = Map<string, GuardLocation>
|
|
274
|
+
|
|
275
|
+
interface RouterTarget {
|
|
276
|
+
name: string
|
|
277
|
+
path: string
|
|
278
|
+
state?: unknown
|
|
279
|
+
replace?: boolean
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
type navigationMethod = (to: RouterTarget) => void
|
|
283
|
+
|
|
284
|
+
interface AccurateGuard {
|
|
285
|
+
[appName: string]: (to: GuardLocation, from: GuardLocation) => void
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
type GlobalNormalGuard = ((appName: string, to: GuardLocation, from: GuardLocation) => void)
|
|
289
|
+
|
|
290
|
+
type RouterGuard = AccurateGuard | GlobalNormalGuard
|
|
291
|
+
|
|
292
|
+
// Router API for developer
|
|
293
|
+
interface Router {
|
|
294
|
+
// current route of all apps
|
|
295
|
+
readonly current: CurrentRoute
|
|
296
|
+
/**
|
|
297
|
+
* encodeURI of microApp path
|
|
298
|
+
* @param path url path
|
|
299
|
+
*/
|
|
300
|
+
encode(path: string): string
|
|
301
|
+
/**
|
|
302
|
+
* decodeURI of microApp path
|
|
303
|
+
* @param path url path
|
|
304
|
+
*/
|
|
305
|
+
decode(path: string): ReturnType<Router['encode']>
|
|
306
|
+
/**
|
|
307
|
+
* Navigate to a new URL by pushing an entry in the history
|
|
308
|
+
* stack.
|
|
309
|
+
* @param to - Route location to navigate to
|
|
310
|
+
*/
|
|
311
|
+
push: navigationMethod
|
|
312
|
+
/**
|
|
313
|
+
* Navigate to a new URL by replacing the current entry in
|
|
314
|
+
* the history stack.
|
|
315
|
+
*
|
|
316
|
+
* @param to - Route location to navigate to
|
|
317
|
+
*/
|
|
318
|
+
replace: navigationMethod
|
|
319
|
+
/**
|
|
320
|
+
* Move forward or backward through the history. calling `history.go()`.
|
|
321
|
+
*
|
|
322
|
+
* @param delta - The position in the history to which you want to move,
|
|
323
|
+
* relative to the current page
|
|
324
|
+
*/
|
|
325
|
+
go: Func
|
|
326
|
+
/**
|
|
327
|
+
* Go back in history if possible by calling `history.back()`.
|
|
328
|
+
*/
|
|
329
|
+
back: Func
|
|
330
|
+
/**
|
|
331
|
+
* Go forward in history if possible by calling `history.forward()`.
|
|
332
|
+
*/
|
|
333
|
+
forward: Func
|
|
334
|
+
/**
|
|
335
|
+
* Add a navigation guard that executes before any navigation
|
|
336
|
+
* @param guard global hook for
|
|
337
|
+
*/
|
|
338
|
+
beforeEach(guard: RouterGuard): () => boolean
|
|
339
|
+
/**
|
|
340
|
+
* Add a navigation guard that executes after any navigation
|
|
341
|
+
* @param guard global hook for
|
|
342
|
+
*/
|
|
343
|
+
afterEach(guard: RouterGuard): () => boolean
|
|
344
|
+
/**
|
|
345
|
+
* Add defaultPage to control the first rendered page
|
|
346
|
+
* @param appName app name
|
|
347
|
+
* @param path default page path
|
|
348
|
+
*/
|
|
349
|
+
setDefaultPage(appName: string, path: string): () => boolean
|
|
350
|
+
/**
|
|
351
|
+
* Clear data of defaultPage that set by setDefaultPage
|
|
352
|
+
*/
|
|
353
|
+
removeDefaultPage(appName: string): boolean
|
|
354
|
+
/**
|
|
355
|
+
* Get defaultPage that set by setDefaultPage
|
|
356
|
+
*/
|
|
357
|
+
getDefaultPage(key: PropertyKey): string | undefined
|
|
358
|
+
/**
|
|
359
|
+
* Attach specified active app router info to browser url
|
|
360
|
+
*/
|
|
361
|
+
attachToURL(appName: string): void
|
|
362
|
+
/**
|
|
363
|
+
* Attach all active app router info to browser url
|
|
364
|
+
*/
|
|
365
|
+
attachAllToURL(): void
|
|
366
|
+
/**
|
|
367
|
+
* Record base app router, let child app control base app navigation
|
|
368
|
+
* It is global data
|
|
369
|
+
* @param baseRouter router instance of base app
|
|
370
|
+
*/
|
|
371
|
+
setBaseAppRouter(baseRouter: unknown): void
|
|
372
|
+
/**
|
|
373
|
+
* get baseRouter from cache
|
|
374
|
+
*/
|
|
375
|
+
getBaseAppRouter(): unknown
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// result of add/remove microApp path on browser url
|
|
379
|
+
type HandleMicroPathResult = {
|
|
380
|
+
fullPath: string,
|
|
381
|
+
isAttach2Hash: boolean,
|
|
382
|
+
}
|
|
211
383
|
}
|
|
212
384
|
|
|
213
385
|
declare namespace JSX {
|