forked from jd-opensource/micro-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.d.ts
212 lines (176 loc) · 5.74 KB
/
global.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
declare module '@micro-app/types' {
type AttrType = string | null
type Func = (...rest: any[]) => void
type microWindowType = Window & any
interface SandBoxInterface {
proxyWindow: WindowProxy
microWindow: Window // Proxy target
start (baseroute: string): void
stop (): void
// record umd snapshot before the first execution of umdHookMount
recordUmdSnapshot (): void
// rebuild umd snapshot before remount umd app
rebuildUmdSnapshot (): void
}
type sourceLinkInfo = {
code: string // code
placeholder?: Comment | null // placeholder comment
isGlobal: boolean // is global asset
}
type sourceScriptInfo = {
code: string // code
isExternal: boolean // external script
isDynamic: boolean // dynamic create script
async: boolean // async script
defer: boolean // defer script
module: boolean // module type script
isGlobal?: boolean // share js to global
code2Function?: Function // code to Function
}
interface sourceType {
html?: HTMLElement
links: Map<string, sourceLinkInfo>
scripts: Map<string, sourceScriptInfo>
}
// app instance
interface AppInterface {
isPrefetch: boolean // whether prefetch app, default is false
name: string // app name
url: string // app url
ssrUrl: string // html path in ssr mode
container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, DIV(keep-alive)
inline: boolean // whether js runs in inline script mode, default is false
scopecss: boolean // whether use css scoped, default is true
useSandbox: boolean // whether use js sandbox, default is true
macro: boolean // used to solve the async render problem of vue3, default is false
baseroute: string // route prefix, default is ''
source: sourceType // sources of css, js, html
sandBox: SandBoxInterface | null // sanxbox
umdMode: boolean // is umd mode
// Load resources
loadSourceCode (): void
// resource is loaded
onLoad (html: HTMLElement): void
// Error loading HTML
onLoadError (e: Error): void
// mount app
mount (
container?: HTMLElement | ShadowRoot,
inline?: boolean,
baseroute?: string,
): void
// unmount app
unmount (destroy: boolean, unmountcb?: CallableFunction): void
// app rendering error
onerror (e: Error): void
// get app state
getAppState (): string
getKeepAliveState(): string | null
// actions for completely destroy
actionsForCompletelyDestory (): void
// hidden app when disconnectedCallback with keep-alive
hiddenKeepAliveApp (): void
// show app when connectedCallback with keep-alive
showKeepAliveApp (container: HTMLElement | ShadowRoot): void
}
interface MicroAppElementType {
appName: AttrType // app name
appUrl: AttrType // app url
// Hooks for element append to documents
connectedCallback (): void
// Hooks for element delete from documents
disconnectedCallback (): void
// Hooks for element attributes change
attributeChangedCallback (a: 'name' | 'url', o: string, n: string): void
}
type prefetchParam = {
name: string,
url: string,
disableScopecss?: boolean
disableSandbox?: boolean
macro?: boolean
shadowDOM?: boolean
}
// prefetch params
type prefetchParamList = Array<prefetchParam> | (() => Array<prefetchParam>)
// lifeCycles
interface lifeCyclesType {
created?(e?: CustomEvent): void
beforemount?(e?: CustomEvent): void
mounted?(e?: CustomEvent): void
unmount?(e?: CustomEvent): void
error?(e?: CustomEvent): void
}
type plugins = {
// global plugin
global?: Array<{
// Scoped global Properties
scopeProperties?: Array<PropertyKey>
// Properties that can be escape to rawWindow
escapeProperties?: Array<PropertyKey>
// options for plugin as the third parameter of loader
options?: unknown
// handle function
loader?: (code: string, url: string, options: unknown) => string
}>
// plugin for special app
modules?: {
[name: string]: Array<{
// Scoped global Properties
scopeProperties?: Array<PropertyKey>
// Properties that can be escape to rawWindow
escapeProperties?: Array<PropertyKey>
// options for plugin as the third parameter of loader
options?: unknown
// handle function
loader?: (code: string, url: string, options: unknown) => string
}>
}
}
type fetchType = (url: string, options: Record<string, unknown>, appName: string | null) => Promise<string>
type globalAssetsType = {
js?: string[],
css?: string[],
}
type OptionsType = {
tagName?: string
shadowDOM?: boolean
destroy?: boolean
inline?: boolean
disableScopecss?: boolean
disableSandbox?: boolean
macro?: boolean
ssr?: boolean
lifeCycles?: lifeCyclesType
preFetchApps?: prefetchParamList
plugins?: plugins
fetch?: fetchType
globalAssets?: globalAssetsType,
}
// MicroApp config
interface MicroAppConfigType {
tagName: string
shadowDOM?: boolean
destroy?: boolean
inline?: boolean
disableScopecss?: boolean
disableSandbox?: boolean
macro?: boolean
ssr?: boolean
lifeCycles?: lifeCyclesType
plugins?: plugins
fetch?: fetchType
preFetch(apps: prefetchParamList): void
start(options?: OptionsType): void
}
// special CallableFunction for interact
type CallableFunctionForInteract = CallableFunction & { __APP_NAME__?: string, __AUTO_TRIGGER__?: boolean }
}
declare namespace JSX {
interface IntrinsicElements {
'micro-app': any
}
}
declare module '@micro-zoe/micro-app/polyfill/jsx-custom-event'
declare const __DEV__: boolean
declare const __TEST__: boolean