kj-micro-app 1.0.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/LICENSE +21 -0
- package/README.md +156 -0
- package/README.zh-cn.md +156 -0
- package/lib/index.d.ts +483 -0
- package/lib/index.esm.js +9419 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.min.js +2 -0
- package/lib/index.min.js.map +1 -0
- package/lib/index.umd.js +2 -0
- package/lib/index.umd.js.map +1 -0
- package/package.json +134 -0
- package/polyfill/jsx-custom-event.js +54 -0
- package/polyfill/jsx-custom-event.js.map +1 -0
- package/typings/global.d.ts +582 -0
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
declare module '@micro-app/types' {
|
|
2
|
+
type AttrType = string | null
|
|
3
|
+
|
|
4
|
+
type NormalKey = string | number
|
|
5
|
+
|
|
6
|
+
type Func = (...rest: any[]) => void
|
|
7
|
+
|
|
8
|
+
type microAppWindowType = Window & any
|
|
9
|
+
|
|
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
|
+
type MicroEventListener = EventListenerOrEventListenerObject & Record<string, any>
|
|
28
|
+
|
|
29
|
+
type timeInfo = {
|
|
30
|
+
handler: TimerHandler,
|
|
31
|
+
timeout?: number,
|
|
32
|
+
args: any[],
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface MicroAppElementTagNameMap extends HTMLElementTagNameMap {
|
|
36
|
+
'micro-app': any,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface CommonEffectHook {
|
|
40
|
+
reset(): void
|
|
41
|
+
record(): void
|
|
42
|
+
rebuild(): void
|
|
43
|
+
release(clearTimer?: boolean): void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface SandBoxStartParams {
|
|
47
|
+
umdMode: boolean
|
|
48
|
+
baseroute: string
|
|
49
|
+
defaultPage: string
|
|
50
|
+
disablePatchRequest: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface SandBoxStopParams {
|
|
54
|
+
umdMode: boolean
|
|
55
|
+
keepRouteState: boolean
|
|
56
|
+
destroy: boolean
|
|
57
|
+
clearData: boolean
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface releaseGlobalEffectParams {
|
|
61
|
+
umdMode?: boolean,
|
|
62
|
+
clearData?: boolean,
|
|
63
|
+
isPrerender?: boolean,
|
|
64
|
+
keepAlive?: boolean,
|
|
65
|
+
destroy?: boolean,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface BaseSandboxType {
|
|
69
|
+
// Properties that can only get and set in microAppWindow, will not escape to rawWindow
|
|
70
|
+
scopeProperties: PropertyKey[]
|
|
71
|
+
// Properties that can be escape to rawWindow
|
|
72
|
+
escapeProperties: PropertyKey[]
|
|
73
|
+
// Properties newly added to microAppWindow
|
|
74
|
+
injectedKeys: Set<PropertyKey>
|
|
75
|
+
// Properties escape to rawWindow, cleared when unmount
|
|
76
|
+
escapeKeys: Set<PropertyKey>
|
|
77
|
+
// Sandbox ready state
|
|
78
|
+
sandboxReady: Promise<void>
|
|
79
|
+
// Variables that can only assigned to rawWindow
|
|
80
|
+
rawWindowScopeKeyList: PropertyKey[]
|
|
81
|
+
// Variables that can escape to rawWindow
|
|
82
|
+
staticEscapeProperties: PropertyKey[]
|
|
83
|
+
// Variables that scoped in child app
|
|
84
|
+
staticScopeProperties: PropertyKey[]
|
|
85
|
+
// clear mount, unmount when stop in default mode
|
|
86
|
+
clearHijackUmdHooks: () => void
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface WithSandBoxInterface extends BaseSandboxType {
|
|
90
|
+
// proxy(microWindow)
|
|
91
|
+
proxyWindow: WindowProxy
|
|
92
|
+
// child window
|
|
93
|
+
microAppWindow: Window // Proxy target
|
|
94
|
+
start (startParams: SandBoxStartParams): void
|
|
95
|
+
stop (stopParams: SandBoxStopParams): void
|
|
96
|
+
recordAndReleaseEffect (options: releaseGlobalEffectParams, preventRecord?: boolean): void
|
|
97
|
+
// reset effect snapshot data
|
|
98
|
+
resetEffectSnapshot(): void
|
|
99
|
+
// record umd snapshot before the first execution of umdHookMount
|
|
100
|
+
recordEffectSnapshot (): void
|
|
101
|
+
// rebuild umd snapshot before remount umd app
|
|
102
|
+
rebuildEffectSnapshot (): void
|
|
103
|
+
releaseGlobalEffect (options: releaseGlobalEffectParams): void
|
|
104
|
+
setRouteInfoForKeepAliveApp (): void
|
|
105
|
+
removeRouteInfoForKeepAliveApp (): void
|
|
106
|
+
setPreRenderState (state: boolean): void
|
|
107
|
+
markUmdMode(state: boolean): void
|
|
108
|
+
patchStaticElement (container: Element | ShadowRoot): void
|
|
109
|
+
actionsBeforeExecScripts (container: Element | ShadowRoot, handleUmdHooks: Func): void
|
|
110
|
+
deleteIframeElement? (): void
|
|
111
|
+
setStaticAppState (state: string): void
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type LinkSourceInfo = {
|
|
115
|
+
code: string, // source code
|
|
116
|
+
appSpace: Record<string, {
|
|
117
|
+
attrs: Map<string, string>, // active element.attributes
|
|
118
|
+
placeholder?: Comment | null, // placeholder comment
|
|
119
|
+
parsedCode?: string, // parsed code
|
|
120
|
+
prefix?: string, // micro-app[name=appName]
|
|
121
|
+
}>
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type ScriptSourceInfo = {
|
|
125
|
+
code: string, // source code
|
|
126
|
+
isExternal: boolean, // external script
|
|
127
|
+
appSpace: Record<string, {
|
|
128
|
+
async: boolean, // async script
|
|
129
|
+
defer: boolean, // defer script
|
|
130
|
+
module: boolean, // module type script
|
|
131
|
+
inline: boolean, // run js with inline script
|
|
132
|
+
pure: boolean, // pure script
|
|
133
|
+
attrs: Map<string, string>, // element attributes
|
|
134
|
+
parsedCode?: string, // bind code
|
|
135
|
+
parsedFunction?: Function | null, // code to function
|
|
136
|
+
sandboxType?: 'with' | 'iframe' | 'disable' // sandbox type (with, iframe, disable)
|
|
137
|
+
}>
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
type sourceType = {
|
|
141
|
+
html: HTMLElement | null, // html address
|
|
142
|
+
links: Set<string>, // style/link address list
|
|
143
|
+
scripts: Set<string>, // script address list
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
interface MountParam {
|
|
147
|
+
container: HTMLElement | ShadowRoot // app container
|
|
148
|
+
inline: boolean // run js in inline mode
|
|
149
|
+
routerMode: string // virtual router mode
|
|
150
|
+
defaultPage: string // default page of virtual router
|
|
151
|
+
baseroute: string // route prefix, default is ''
|
|
152
|
+
disablePatchRequest: boolean // prevent rewrite request method of child app
|
|
153
|
+
fiber: boolean // run js in fiber mode
|
|
154
|
+
// hiddenRouter: boolean
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface OnLoadParam {
|
|
158
|
+
html: HTMLElement,
|
|
159
|
+
// below params is only for prerender app
|
|
160
|
+
defaultPage?: string // default page of virtual router
|
|
161
|
+
routerMode?: string // virtual router mode
|
|
162
|
+
baseroute?: string // route prefix, default is ''
|
|
163
|
+
disablePatchRequest?: boolean // prevent rewrite request method of child app
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface UnmountParam {
|
|
167
|
+
destroy: boolean, // completely destroy, delete cache resources
|
|
168
|
+
clearData: boolean // clear data of dateCenter
|
|
169
|
+
keepRouteState: boolean // keep route state when unmount, default is false
|
|
170
|
+
unmountcb?: CallableFunction // callback of unmount
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// app instance
|
|
174
|
+
interface AppInterface extends Pick<Element, 'querySelector' | 'querySelectorAll'> {
|
|
175
|
+
source: sourceType // source list
|
|
176
|
+
// TODO: 去掉any
|
|
177
|
+
sandBox: WithSandBoxInterface | null | any // sandbox
|
|
178
|
+
name: string // app name
|
|
179
|
+
url: string // app url
|
|
180
|
+
scopecss: boolean // whether use css scoped, default is true
|
|
181
|
+
useSandbox: boolean // whether use js sandbox, default is true
|
|
182
|
+
inline: boolean // whether js runs in inline script mode, default is false
|
|
183
|
+
iframe: boolean // use iframe sandbox
|
|
184
|
+
ssrUrl: string // html path in ssr mode
|
|
185
|
+
container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, div(keep-alive)
|
|
186
|
+
umdMode: boolean // is umd mode
|
|
187
|
+
fiber: boolean // fiber mode
|
|
188
|
+
routerMode: string // virtual router mode
|
|
189
|
+
isPrefetch: boolean // whether prefetch app, default is false
|
|
190
|
+
isPrerender: boolean
|
|
191
|
+
isReloading?: boolean
|
|
192
|
+
prefetchLevel?: number
|
|
193
|
+
// defaultPage: string // default page when mount
|
|
194
|
+
// baseroute: string // route prefix, default is ''
|
|
195
|
+
// hiddenRouter: boolean // hide router info of child from browser url
|
|
196
|
+
|
|
197
|
+
// Load resources
|
|
198
|
+
loadSourceCode (): void
|
|
199
|
+
|
|
200
|
+
// resource is loaded
|
|
201
|
+
onLoad (onLoadParam: OnLoadParam): void
|
|
202
|
+
|
|
203
|
+
// Error loading HTML
|
|
204
|
+
onLoadError (e: Error): void
|
|
205
|
+
|
|
206
|
+
// mount app
|
|
207
|
+
mount (mountParams: MountParam): void
|
|
208
|
+
|
|
209
|
+
// unmount app
|
|
210
|
+
unmount (unmountParam: UnmountParam): void
|
|
211
|
+
|
|
212
|
+
// app rendering error
|
|
213
|
+
onerror (e: Error): void
|
|
214
|
+
|
|
215
|
+
// set app state
|
|
216
|
+
setAppState (state: string): void
|
|
217
|
+
|
|
218
|
+
// get app state
|
|
219
|
+
getAppState (): string
|
|
220
|
+
|
|
221
|
+
// get keep-alive state
|
|
222
|
+
getKeepAliveState(): string | null
|
|
223
|
+
|
|
224
|
+
parseHtmlString(htmlString: string): HTMLElement
|
|
225
|
+
|
|
226
|
+
// is app unmounted
|
|
227
|
+
isUnmounted (): boolean
|
|
228
|
+
|
|
229
|
+
// is app already hidden
|
|
230
|
+
isHidden (): boolean
|
|
231
|
+
|
|
232
|
+
// actions for completely destroy
|
|
233
|
+
actionsForCompletelyDestroy (): void
|
|
234
|
+
|
|
235
|
+
// hidden app when disconnectedCallback with keep-alive
|
|
236
|
+
hiddenKeepAliveApp (callback?: CallableFunction): void
|
|
237
|
+
|
|
238
|
+
// show app when connectedCallback with keep-alive
|
|
239
|
+
showKeepAliveApp (container: HTMLElement | ShadowRoot): void
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface prefetchParam {
|
|
243
|
+
name: string,
|
|
244
|
+
url: string,
|
|
245
|
+
// old config 👇
|
|
246
|
+
disableScopecss?: boolean
|
|
247
|
+
disableSandbox?: boolean
|
|
248
|
+
// old config 👆
|
|
249
|
+
'disable-scopecss'?: boolean
|
|
250
|
+
'disable-sandbox'?: boolean
|
|
251
|
+
inline?: boolean
|
|
252
|
+
iframe?: boolean
|
|
253
|
+
level?: number
|
|
254
|
+
// prerender only 👇
|
|
255
|
+
'default-page'?: string
|
|
256
|
+
'disable-patch-request'?: boolean
|
|
257
|
+
'router-mode'?: string
|
|
258
|
+
baseroute?: string
|
|
259
|
+
// prerender only 👆
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// prefetch params
|
|
263
|
+
type prefetchParamList = Array<prefetchParam> | (() => Array<prefetchParam>)
|
|
264
|
+
|
|
265
|
+
// lifeCycles
|
|
266
|
+
interface lifeCyclesType {
|
|
267
|
+
created?(e: CustomEvent, appName: string): void
|
|
268
|
+
beforemount?(e: CustomEvent, appName: string): void
|
|
269
|
+
mounted?(e: CustomEvent, appName: string): void
|
|
270
|
+
unmount?(e: CustomEvent, appName: string): void
|
|
271
|
+
error?(e: CustomEvent, appName: string): void
|
|
272
|
+
beforeshow?(e: CustomEvent, appName: string): void
|
|
273
|
+
aftershow?(e: CustomEvent, appName: string): void
|
|
274
|
+
afterhidden?(e: CustomEvent, appName: string): void
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
type AssetsChecker = (url: string) => boolean;
|
|
278
|
+
|
|
279
|
+
type plugins = {
|
|
280
|
+
// global plugin
|
|
281
|
+
global?: Array<{
|
|
282
|
+
// Scoped global Properties
|
|
283
|
+
scopeProperties?: Array<PropertyKey>
|
|
284
|
+
// Properties that can be escape to rawWindow
|
|
285
|
+
escapeProperties?: Array<PropertyKey>
|
|
286
|
+
// Exclude JS or CSS
|
|
287
|
+
excludeChecker?: AssetsChecker
|
|
288
|
+
// Ignore JS or CSS
|
|
289
|
+
ignoreChecker?: AssetsChecker
|
|
290
|
+
// options for plugin as the third parameter of loader
|
|
291
|
+
options?: Record<string, unknown>
|
|
292
|
+
// handle function
|
|
293
|
+
loader?: (code: string, url: string) => string
|
|
294
|
+
// html processor
|
|
295
|
+
processHtml?: (code: string, url: string) => string
|
|
296
|
+
}>
|
|
297
|
+
|
|
298
|
+
// plugin for special app
|
|
299
|
+
modules?: {
|
|
300
|
+
[name: string]: Array<{
|
|
301
|
+
// Scoped global Properties
|
|
302
|
+
scopeProperties?: Array<PropertyKey>
|
|
303
|
+
// Properties that can be escape to rawWindow
|
|
304
|
+
escapeProperties?: Array<PropertyKey>
|
|
305
|
+
// Exclude JS or CSS
|
|
306
|
+
excludeChecker?: AssetsChecker
|
|
307
|
+
// Ignore JS or CSS
|
|
308
|
+
ignoreChecker?: AssetsChecker
|
|
309
|
+
// options for plugin as the third parameter of loader
|
|
310
|
+
options?: Record<string, unknown>
|
|
311
|
+
// handle function
|
|
312
|
+
loader?: (code: string, url: string) => string
|
|
313
|
+
// html processor
|
|
314
|
+
processHtml?: (code: string, url: string) => string
|
|
315
|
+
aHrefResolver?: (hrefValue: string, appName: string, appUrl: string) => string
|
|
316
|
+
}>
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
type GetActiveAppsParam = {
|
|
321
|
+
excludeHiddenApp?: boolean,
|
|
322
|
+
excludePreRender?: boolean,
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
type fetchType = (url: string, options: Record<string, unknown>, appName: string | null) => Promise<string>
|
|
326
|
+
|
|
327
|
+
type globalAssetsType = {
|
|
328
|
+
js?: string[],
|
|
329
|
+
css?: string[],
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
interface MicroAppConfig {
|
|
333
|
+
shadowDOM?: boolean
|
|
334
|
+
destroy?: boolean
|
|
335
|
+
destory?: boolean
|
|
336
|
+
inline?: boolean
|
|
337
|
+
// old config 👇
|
|
338
|
+
disableScopecss?: boolean
|
|
339
|
+
disableSandbox?: boolean
|
|
340
|
+
// old config 👆
|
|
341
|
+
'disable-scopecss'?: boolean
|
|
342
|
+
'disable-sandbox'?: boolean
|
|
343
|
+
'disable-memory-router'?: boolean
|
|
344
|
+
'disable-patch-request'?: boolean
|
|
345
|
+
'keep-router-state'?: boolean
|
|
346
|
+
'keep-alive'?: boolean
|
|
347
|
+
'clear-data'?: boolean
|
|
348
|
+
'router-mode'?: string
|
|
349
|
+
'router-event-delay'?: number | ((appName: string) => number),
|
|
350
|
+
iframe?: boolean
|
|
351
|
+
ssr?: boolean
|
|
352
|
+
fiber?: boolean
|
|
353
|
+
prefetchLevel?: number
|
|
354
|
+
prefetchDelay?: number
|
|
355
|
+
iframeSrc?: string
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
interface OptionsType extends MicroAppConfig {
|
|
359
|
+
tagName?: string
|
|
360
|
+
lifeCycles?: lifeCyclesType
|
|
361
|
+
preFetchApps?: prefetchParamList
|
|
362
|
+
plugins?: plugins
|
|
363
|
+
fetch?: fetchType
|
|
364
|
+
globalAssets?: globalAssetsType,
|
|
365
|
+
excludeAssetFilter?: (assetUrl: string) => boolean
|
|
366
|
+
excludeRunScriptFilter?: (scriptUrl: string, error: Error, appName: string, appUrl: string) => boolean
|
|
367
|
+
/* image video audio 是否设置 crossOrigin = 'anonymous' */
|
|
368
|
+
includeCrossOrigin?: (assetUrl: string) => boolean
|
|
369
|
+
getRootElementParentNode?: (node: Node, appName: AppName) => void
|
|
370
|
+
customProxyDocumentProps?: Map<string | number | symbol, (value: unknown) => void>
|
|
371
|
+
aHrefResolver?: (hrefValue: string, appName: string, appUrl: string) => string
|
|
372
|
+
inheritBaseBody?:boolean,
|
|
373
|
+
escapeIframeWindowEvents? : Array<string>,
|
|
374
|
+
disableIframeRootDocument?: boolean,
|
|
375
|
+
excludeRewriteIframeConstructor?: string[]
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// MicroApp config
|
|
379
|
+
interface MicroAppBaseType {
|
|
380
|
+
tagName: string
|
|
381
|
+
hasInit: boolean
|
|
382
|
+
options: OptionsType
|
|
383
|
+
preFetch(apps: prefetchParamList): void
|
|
384
|
+
router: Router // eslint-disable-line
|
|
385
|
+
start(options?: OptionsType): void
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
interface MicroAppElementInterface {
|
|
389
|
+
appName: AttrType // app name
|
|
390
|
+
appUrl: AttrType // app url
|
|
391
|
+
// Hooks for element append to documents
|
|
392
|
+
connectedCallback (): void
|
|
393
|
+
// Hooks for element delete from documents
|
|
394
|
+
disconnectedCallback (): void
|
|
395
|
+
// Hooks for element attributes change
|
|
396
|
+
attributeChangedCallback (a: 'name' | 'url', o: string, n: string): void
|
|
397
|
+
// public mount action for micro_app_element & create_app
|
|
398
|
+
mount (app: AppInterface): void
|
|
399
|
+
// unmount app
|
|
400
|
+
unmount (destroy?: boolean, unmountcb?: CallableFunction): void
|
|
401
|
+
// Re render app from the command line
|
|
402
|
+
reload (destroy?: boolean): Promise<boolean>
|
|
403
|
+
// get delay time of router event
|
|
404
|
+
getRouterEventDelay (): number
|
|
405
|
+
// rewrite micro-app.setAttribute, process attr data
|
|
406
|
+
setAttribute (key: string, value: any): void
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// special CallableFunction for interact
|
|
410
|
+
type CallableFunctionForInteract = CallableFunction & { __APP_NAME__?: string, __AUTO_TRIGGER__?: boolean }
|
|
411
|
+
|
|
412
|
+
type PopStateListener = (this: Window, e: PopStateEvent) => void
|
|
413
|
+
type MicroPopStateEvent = PopStateEvent & { onlyForBrowser?: boolean }
|
|
414
|
+
|
|
415
|
+
interface MicroLocation extends Location, URL {
|
|
416
|
+
fullPath: string
|
|
417
|
+
self: URL | Location
|
|
418
|
+
[key: string]: any
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
type MicroHistory = ProxyHandler<History>
|
|
422
|
+
type MicroState = any
|
|
423
|
+
interface MicroRouterInfoState {
|
|
424
|
+
fullPath: string | null,
|
|
425
|
+
state: MicroState,
|
|
426
|
+
mode: string,
|
|
427
|
+
}
|
|
428
|
+
type HistoryProxyValue =
|
|
429
|
+
Pick<
|
|
430
|
+
History,
|
|
431
|
+
'length' |
|
|
432
|
+
'scrollRestoration' |
|
|
433
|
+
'state' |
|
|
434
|
+
'back' |
|
|
435
|
+
'forward' |
|
|
436
|
+
'go' |
|
|
437
|
+
'pushState' |
|
|
438
|
+
'replaceState'
|
|
439
|
+
> | CallableFunction
|
|
440
|
+
interface MicroRouter {
|
|
441
|
+
microLocation: MicroLocation
|
|
442
|
+
microHistory: MicroHistory
|
|
443
|
+
}
|
|
444
|
+
type LocationQueryValue = string | null
|
|
445
|
+
type LocationQueryObject = Record<
|
|
446
|
+
string,
|
|
447
|
+
LocationQueryValue | LocationQueryValue[]
|
|
448
|
+
>
|
|
449
|
+
|
|
450
|
+
type LocationQuery = {
|
|
451
|
+
hashQuery?: LocationQueryObject,
|
|
452
|
+
searchQuery?: LocationQueryObject
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
type GuardLocation = Record<keyof MicroLocation, any>
|
|
456
|
+
|
|
457
|
+
type CurrentRoute = Map<string, GuardLocation>
|
|
458
|
+
|
|
459
|
+
interface RouterTarget {
|
|
460
|
+
name: string
|
|
461
|
+
path: string
|
|
462
|
+
state?: unknown
|
|
463
|
+
replace?: boolean
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
type navigationMethod = (to: RouterTarget) => Promise<void>
|
|
467
|
+
|
|
468
|
+
interface AccurateGuard {
|
|
469
|
+
[appName: string]: (to: GuardLocation, from: GuardLocation) => void
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
type GlobalNormalGuard = ((to: GuardLocation, from: GuardLocation, appName: string) => void)
|
|
473
|
+
|
|
474
|
+
type RouterGuard = AccurateGuard | GlobalNormalGuard
|
|
475
|
+
|
|
476
|
+
type SetDefaultPageOptions = {
|
|
477
|
+
name: string,
|
|
478
|
+
path: string,
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
type AttachAllToURLParam = {
|
|
482
|
+
includeHiddenApp?: boolean,
|
|
483
|
+
includePreRender?: boolean,
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Router API for developer
|
|
487
|
+
interface Router {
|
|
488
|
+
// current route of all apps
|
|
489
|
+
readonly current: CurrentRoute
|
|
490
|
+
/**
|
|
491
|
+
* encodeURI of microApp path
|
|
492
|
+
* @param path url path
|
|
493
|
+
*/
|
|
494
|
+
encode(path: string): string
|
|
495
|
+
/**
|
|
496
|
+
* decodeURI of microApp path
|
|
497
|
+
* @param path url path
|
|
498
|
+
*/
|
|
499
|
+
decode(path: string): ReturnType<Router['encode']>
|
|
500
|
+
/**
|
|
501
|
+
* Navigate to a new URL by pushing an entry in the history
|
|
502
|
+
* stack.
|
|
503
|
+
* @param to - Route location to navigate to
|
|
504
|
+
*/
|
|
505
|
+
push: navigationMethod
|
|
506
|
+
/**
|
|
507
|
+
* Navigate to a new URL by replacing the current entry in
|
|
508
|
+
* the history stack.
|
|
509
|
+
*
|
|
510
|
+
* @param to - Route location to navigate to
|
|
511
|
+
*/
|
|
512
|
+
replace: navigationMethod
|
|
513
|
+
/**
|
|
514
|
+
* Move forward or backward through the history. calling `history.go()`.
|
|
515
|
+
*
|
|
516
|
+
* @param delta - The position in the history to which you want to move,
|
|
517
|
+
* relative to the current page
|
|
518
|
+
*/
|
|
519
|
+
go: Func
|
|
520
|
+
/**
|
|
521
|
+
* Go back in history if possible by calling `history.back()`.
|
|
522
|
+
*/
|
|
523
|
+
back: Func
|
|
524
|
+
/**
|
|
525
|
+
* Go forward in history if possible by calling `history.forward()`.
|
|
526
|
+
*/
|
|
527
|
+
forward: Func
|
|
528
|
+
/**
|
|
529
|
+
* Add a navigation guard that executes before any navigation
|
|
530
|
+
* @param guard global hook for
|
|
531
|
+
*/
|
|
532
|
+
beforeEach(guard: RouterGuard): () => boolean
|
|
533
|
+
/**
|
|
534
|
+
* Add a navigation guard that executes after any navigation
|
|
535
|
+
* @param guard global hook for
|
|
536
|
+
*/
|
|
537
|
+
afterEach(guard: RouterGuard): () => boolean
|
|
538
|
+
/**
|
|
539
|
+
* Add defaultPage to control the first rendered page
|
|
540
|
+
* @param options SetDefaultPageOptions
|
|
541
|
+
*/
|
|
542
|
+
setDefaultPage(options: SetDefaultPageOptions): () => boolean
|
|
543
|
+
/**
|
|
544
|
+
* Clear data of defaultPage that set by setDefaultPage
|
|
545
|
+
*/
|
|
546
|
+
removeDefaultPage(appName: string): boolean
|
|
547
|
+
/**
|
|
548
|
+
* Get defaultPage that set by setDefaultPage
|
|
549
|
+
*/
|
|
550
|
+
getDefaultPage(key: PropertyKey): string | void
|
|
551
|
+
/**
|
|
552
|
+
* Attach specified active app router info to browser url
|
|
553
|
+
*/
|
|
554
|
+
attachToURL(appName: string): void
|
|
555
|
+
/**
|
|
556
|
+
* Attach all active app router info to browser url
|
|
557
|
+
*/
|
|
558
|
+
attachAllToURL(options: AttachAllToURLParam): void
|
|
559
|
+
/**
|
|
560
|
+
* Record base app router, let child app control base app navigation
|
|
561
|
+
* It is global data
|
|
562
|
+
* @param baseRouter router instance of base app
|
|
563
|
+
*/
|
|
564
|
+
setBaseAppRouter(baseRouter: unknown): void
|
|
565
|
+
/**
|
|
566
|
+
* get baseRouter from cache
|
|
567
|
+
*/
|
|
568
|
+
getBaseAppRouter(): unknown
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// result of add/remove microApp path on browser url
|
|
572
|
+
type HandleMicroPathResult = {
|
|
573
|
+
fullPath: string,
|
|
574
|
+
isAttach2Hash: boolean,
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
declare module '@micro-zoe/micro-app/polyfill/jsx-custom-event'
|
|
579
|
+
|
|
580
|
+
declare const __DEV__: boolean
|
|
581
|
+
|
|
582
|
+
declare const __TEST__: boolean
|