@micro-zoe/micro-app 0.8.4 → 1.0.0-alpha.0
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 +4 -4
- package/README.zh-cn.md +9 -15
- package/lib/index.d.ts +64 -20
- package/lib/index.esm.js +1225 -194
- 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 +2 -2
- package/typings/global.d.ts +146 -4
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.0",
|
|
4
4
|
"description": "A lightweight, efficient and powerful micro front-end framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "lib/index.min.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"test": "jest",
|
|
45
45
|
"test:watch": "jest --watch",
|
|
46
46
|
"test:coverage": "jest --coverage",
|
|
47
|
-
"prepublishOnly": "yarn
|
|
47
|
+
"prepublishOnly": "yarn build"
|
|
48
48
|
},
|
|
49
49
|
"repository": {
|
|
50
50
|
"type": "git",
|
package/typings/global.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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
|
|
@@ -8,12 +10,18 @@ declare module '@micro-app/types' {
|
|
|
8
10
|
interface SandBoxInterface {
|
|
9
11
|
proxyWindow: WindowProxy
|
|
10
12
|
microAppWindow: Window // Proxy target
|
|
11
|
-
start (
|
|
12
|
-
|
|
13
|
+
start (
|
|
14
|
+
baseRoute: string,
|
|
15
|
+
useMemoryRouter: boolean,
|
|
16
|
+
defaultPage: string,
|
|
17
|
+
): void
|
|
18
|
+
stop (keepRouteState: boolean): void
|
|
13
19
|
// record umd snapshot before the first execution of umdHookMount
|
|
14
20
|
recordUmdSnapshot (): void
|
|
15
21
|
// rebuild umd snapshot before remount umd app
|
|
16
22
|
rebuildUmdSnapshot (): void
|
|
23
|
+
setRouteInfoForKeepAliveApp (): void
|
|
24
|
+
removeRouteInfoForKeepAliveApp (): void
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
type sourceLinkInfo = {
|
|
@@ -50,10 +58,13 @@ declare module '@micro-app/types' {
|
|
|
50
58
|
inline: boolean // whether js runs in inline script mode, default is false
|
|
51
59
|
scopecss: boolean // whether use css scoped, default is true
|
|
52
60
|
useSandbox: boolean // whether use js sandbox, default is true
|
|
61
|
+
useMemoryRouter: boolean // whether use memoryRouter, default is true
|
|
53
62
|
baseroute: string // route prefix, default is ''
|
|
63
|
+
keepRouteState: boolean // keep route state when unmount, default is false
|
|
54
64
|
source: sourceType // sources of css, js, html
|
|
55
65
|
sandBox: SandBoxInterface | null // sandbox
|
|
56
66
|
umdMode: boolean // is umd mode
|
|
67
|
+
defaultPage: string // default page when mount
|
|
57
68
|
|
|
58
69
|
// Load resources
|
|
59
70
|
loadSourceCode (): void
|
|
@@ -69,6 +80,8 @@ declare module '@micro-app/types' {
|
|
|
69
80
|
container?: HTMLElement | ShadowRoot,
|
|
70
81
|
inline?: boolean,
|
|
71
82
|
baseroute?: string,
|
|
83
|
+
keepRouteState?: boolean,
|
|
84
|
+
defaultPage?: string,
|
|
72
85
|
): void
|
|
73
86
|
|
|
74
87
|
// unmount app
|
|
@@ -111,6 +124,7 @@ declare module '@micro-app/types' {
|
|
|
111
124
|
url: string,
|
|
112
125
|
disableScopecss?: boolean
|
|
113
126
|
disableSandbox?: boolean
|
|
127
|
+
disableMemoryRouter?: boolean
|
|
114
128
|
shadowDOM?: boolean
|
|
115
129
|
}
|
|
116
130
|
|
|
@@ -136,7 +150,7 @@ declare module '@micro-app/types' {
|
|
|
136
150
|
// options for plugin as the third parameter of loader
|
|
137
151
|
options?: unknown
|
|
138
152
|
// handle function
|
|
139
|
-
loader?: (code: string, url: string, options: unknown) => string
|
|
153
|
+
loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
|
|
140
154
|
}>
|
|
141
155
|
|
|
142
156
|
// plugin for special app
|
|
@@ -149,7 +163,7 @@ declare module '@micro-app/types' {
|
|
|
149
163
|
// options for plugin as the third parameter of loader
|
|
150
164
|
options?: unknown
|
|
151
165
|
// handle function
|
|
152
|
-
loader?: (code: string, url: string, options: unknown) => string
|
|
166
|
+
loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
|
|
153
167
|
}>
|
|
154
168
|
}
|
|
155
169
|
}
|
|
@@ -168,6 +182,7 @@ declare module '@micro-app/types' {
|
|
|
168
182
|
inline?: boolean
|
|
169
183
|
disableScopecss?: boolean
|
|
170
184
|
disableSandbox?: boolean
|
|
185
|
+
disableMemoryRouter?: boolean
|
|
171
186
|
ssr?: boolean
|
|
172
187
|
lifeCycles?: lifeCyclesType
|
|
173
188
|
preFetchApps?: prefetchParamList
|
|
@@ -184,16 +199,143 @@ declare module '@micro-app/types' {
|
|
|
184
199
|
inline?: boolean
|
|
185
200
|
disableScopecss?: boolean
|
|
186
201
|
disableSandbox?: boolean
|
|
202
|
+
disableMemoryRouter?: boolean
|
|
187
203
|
ssr?: boolean
|
|
188
204
|
lifeCycles?: lifeCyclesType
|
|
189
205
|
plugins?: plugins
|
|
190
206
|
fetch?: fetchType
|
|
191
207
|
preFetch(apps: prefetchParamList): void
|
|
208
|
+
router: Router // eslint-disable-line
|
|
192
209
|
start(options?: OptionsType): void
|
|
193
210
|
}
|
|
194
211
|
|
|
195
212
|
// special CallableFunction for interact
|
|
196
213
|
type CallableFunctionForInteract = CallableFunction & { __APP_NAME__?: string, __AUTO_TRIGGER__?: boolean }
|
|
214
|
+
|
|
215
|
+
interface ShadowLocation {
|
|
216
|
+
[k: string]: string
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
interface MicroLocation extends Location, URL {
|
|
220
|
+
// shadowLocation is the current location information (href, pathname, search, hash)
|
|
221
|
+
shadowLocation: ShadowLocation
|
|
222
|
+
fullPath: string
|
|
223
|
+
[key: string]: any
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
type MicroHistory = ProxyHandler<History>
|
|
227
|
+
type MicroState = any
|
|
228
|
+
type HistoryProxyValue =
|
|
229
|
+
Pick<
|
|
230
|
+
History,
|
|
231
|
+
'length' |
|
|
232
|
+
'scrollRestoration' |
|
|
233
|
+
'state' |
|
|
234
|
+
'back' |
|
|
235
|
+
'forward' |
|
|
236
|
+
'go' |
|
|
237
|
+
'pushState' |
|
|
238
|
+
'replaceState'
|
|
239
|
+
> | CallableFunction
|
|
240
|
+
interface MicroRouter {
|
|
241
|
+
microLocation: MicroLocation
|
|
242
|
+
microHistory: MicroHistory
|
|
243
|
+
}
|
|
244
|
+
type LocationQueryValue = string | null
|
|
245
|
+
type LocationQueryObject = Record<
|
|
246
|
+
string,
|
|
247
|
+
LocationQueryValue | LocationQueryValue[]
|
|
248
|
+
>
|
|
249
|
+
|
|
250
|
+
type LocationQuery = {
|
|
251
|
+
hashQuery?: LocationQueryObject,
|
|
252
|
+
searchQuery?: LocationQueryObject
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
type GuardLocation = Record<keyof MicroLocation, any>
|
|
256
|
+
|
|
257
|
+
type CurrentRoute = Map<string, GuardLocation>
|
|
258
|
+
|
|
259
|
+
interface RouterTarget {
|
|
260
|
+
name: string
|
|
261
|
+
path: string
|
|
262
|
+
state?: unknown
|
|
263
|
+
replace?: boolean
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
type navigationMethod = (to: RouterTarget) => void
|
|
267
|
+
|
|
268
|
+
interface AccurateGuard {
|
|
269
|
+
[appName: string]: (to: GuardLocation, from: GuardLocation) => void
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
type GlobalNormalGuard = ((appName: string, to: GuardLocation, from: GuardLocation) => void)
|
|
273
|
+
|
|
274
|
+
type RouterGuard = AccurateGuard | GlobalNormalGuard
|
|
275
|
+
|
|
276
|
+
// Router API for developer
|
|
277
|
+
interface Router {
|
|
278
|
+
// current route of all apps
|
|
279
|
+
readonly current: CurrentRoute
|
|
280
|
+
/**
|
|
281
|
+
* encodeURI of microApp path
|
|
282
|
+
* @param path url path
|
|
283
|
+
*/
|
|
284
|
+
encode(path: string): string
|
|
285
|
+
/**
|
|
286
|
+
* decodeURI of microApp path
|
|
287
|
+
* @param path url path
|
|
288
|
+
*/
|
|
289
|
+
decode(path: string): ReturnType<Router['encode']>
|
|
290
|
+
/**
|
|
291
|
+
* Navigate to a new URL by pushing an entry in the history
|
|
292
|
+
* stack.
|
|
293
|
+
* @param to - Route location to navigate to
|
|
294
|
+
*/
|
|
295
|
+
push: navigationMethod
|
|
296
|
+
/**
|
|
297
|
+
* Navigate to a new URL by replacing the current entry in
|
|
298
|
+
* the history stack.
|
|
299
|
+
*
|
|
300
|
+
* @param to - Route location to navigate to
|
|
301
|
+
*/
|
|
302
|
+
replace: navigationMethod
|
|
303
|
+
/**
|
|
304
|
+
* Move forward or backward through the history. calling `history.go()`.
|
|
305
|
+
*
|
|
306
|
+
* @param delta - The position in the history to which you want to move,
|
|
307
|
+
* relative to the current page
|
|
308
|
+
*/
|
|
309
|
+
go: Func
|
|
310
|
+
/**
|
|
311
|
+
* Go back in history if possible by calling `history.back()`.
|
|
312
|
+
*/
|
|
313
|
+
back: Func
|
|
314
|
+
/**
|
|
315
|
+
* Go forward in history if possible by calling `history.forward()`.
|
|
316
|
+
*/
|
|
317
|
+
forward: Func
|
|
318
|
+
/**
|
|
319
|
+
* Add a navigation guard that executes before any navigation
|
|
320
|
+
* @param guard global hook for
|
|
321
|
+
*/
|
|
322
|
+
beforeEach(guard: RouterGuard): () => boolean
|
|
323
|
+
/**
|
|
324
|
+
* Add a navigation guard that executes after any navigation
|
|
325
|
+
* @param guard global hook for
|
|
326
|
+
*/
|
|
327
|
+
afterEach(guard: RouterGuard): () => boolean
|
|
328
|
+
|
|
329
|
+
setDefaultPage(appName: string, path: string): () => boolean
|
|
330
|
+
removeDefaultPage(appName: string): boolean
|
|
331
|
+
getDefaultPage(key: PropertyKey): string | undefined
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// result of add/remove microApp path on browser url
|
|
335
|
+
type HandleMicroPathResult = {
|
|
336
|
+
fullPath: string,
|
|
337
|
+
isAttach2Hash: boolean,
|
|
338
|
+
}
|
|
197
339
|
}
|
|
198
340
|
|
|
199
341
|
declare namespace JSX {
|