@micro-zoe/micro-app 0.8.6 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micro-zoe/micro-app",
3
- "version": "0.8.6",
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,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": {
@@ -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 (baseRoute: string): void
12
- stop (): void
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
 
@@ -126,8 +140,6 @@ declare module '@micro-app/types' {
126
140
  error?(e?: CustomEvent): void
127
141
  }
128
142
 
129
- type AssetsChecker = (url: string) => boolean;
130
-
131
143
  type plugins = {
132
144
  // global plugin
133
145
  global?: Array<{
@@ -135,16 +147,10 @@ declare module '@micro-app/types' {
135
147
  scopeProperties?: Array<PropertyKey>
136
148
  // Properties that can be escape to rawWindow
137
149
  escapeProperties?: Array<PropertyKey>
138
- // Exclude JS or CSS
139
- excludeChecker?: AssetsChecker
140
- // Ignore JS or CSS
141
- ignoreChecker?: AssetsChecker
142
150
  // options for plugin as the third parameter of loader
143
151
  options?: unknown
144
152
  // handle function
145
153
  loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
146
- // html processor
147
- processHtml?: (code: string, url: string, options: unknown) => string
148
154
  }>
149
155
 
150
156
  // plugin for special app
@@ -154,16 +160,10 @@ declare module '@micro-app/types' {
154
160
  scopeProperties?: Array<PropertyKey>
155
161
  // Properties that can be escape to rawWindow
156
162
  escapeProperties?: Array<PropertyKey>
157
- // Exclude JS or CSS
158
- excludeChecker?: AssetsChecker
159
- // Ignore JS or CSS
160
- ignoreChecker?: AssetsChecker
161
163
  // options for plugin as the third parameter of loader
162
164
  options?: unknown
163
165
  // handle function
164
166
  loader?: (code: string, url: string, options: unknown, info: sourceScriptInfo) => string
165
- // html processor
166
- processHtml?: (code: string, url: string, options: unknown) => string
167
167
  }>
168
168
  }
169
169
  }
@@ -182,6 +182,7 @@ declare module '@micro-app/types' {
182
182
  inline?: boolean
183
183
  disableScopecss?: boolean
184
184
  disableSandbox?: boolean
185
+ disableMemoryRouter?: boolean
185
186
  ssr?: boolean
186
187
  lifeCycles?: lifeCyclesType
187
188
  preFetchApps?: prefetchParamList
@@ -198,16 +199,143 @@ declare module '@micro-app/types' {
198
199
  inline?: boolean
199
200
  disableScopecss?: boolean
200
201
  disableSandbox?: boolean
202
+ disableMemoryRouter?: boolean
201
203
  ssr?: boolean
202
204
  lifeCycles?: lifeCyclesType
203
205
  plugins?: plugins
204
206
  fetch?: fetchType
205
207
  preFetch(apps: prefetchParamList): void
208
+ router: Router // eslint-disable-line
206
209
  start(options?: OptionsType): void
207
210
  }
208
211
 
209
212
  // special CallableFunction for interact
210
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
+ }
211
339
  }
212
340
 
213
341
  declare namespace JSX {