@micro-zoe/micro-app 0.8.5 → 1.0.0-alpha.1

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.5",
3
+ "version": "1.0.0-alpha.1",
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 lint && yarn test && yarn build"
47
+ "prepublishOnly": "yarn build"
48
48
  },
49
49
  "repository": {
50
50
  "type": "git",
@@ -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,32 @@ 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, clearEventSource: 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
25
+ }
26
+
27
+ interface SandBoxAdapter {
28
+ // Variables that can only assigned to rawWindow
29
+ escapeSetterKeyList: PropertyKey[]
30
+
31
+ // Variables that can escape to rawWindow
32
+ staticEscapeProperties: PropertyKey[]
33
+
34
+ // Variables that scoped in child app
35
+ staticScopeProperties: PropertyKey[]
36
+
37
+ // adapter for react
38
+ // injectReactHRMProperty (): void
17
39
  }
18
40
 
19
41
  type sourceLinkInfo = {
@@ -50,10 +72,13 @@ declare module '@micro-app/types' {
50
72
  inline: boolean // whether js runs in inline script mode, default is false
51
73
  scopecss: boolean // whether use css scoped, default is true
52
74
  useSandbox: boolean // whether use js sandbox, default is true
75
+ useMemoryRouter: boolean // whether use memoryRouter, default is true
53
76
  baseroute: string // route prefix, default is ''
77
+ keepRouteState: boolean // keep route state when unmount, default is false
54
78
  source: sourceType // sources of css, js, html
55
79
  sandBox: SandBoxInterface | null // sandbox
56
80
  umdMode: boolean // is umd mode
81
+ defaultPage: string // default page when mount
57
82
 
58
83
  // Load resources
59
84
  loadSourceCode (): void
@@ -69,6 +94,8 @@ declare module '@micro-app/types' {
69
94
  container?: HTMLElement | ShadowRoot,
70
95
  inline?: boolean,
71
96
  baseroute?: string,
97
+ keepRouteState?: boolean,
98
+ defaultPage?: string,
72
99
  ): void
73
100
 
74
101
  // unmount app
@@ -111,6 +138,7 @@ declare module '@micro-app/types' {
111
138
  url: string,
112
139
  disableScopecss?: boolean
113
140
  disableSandbox?: boolean
141
+ disableMemoryRouter?: boolean
114
142
  shadowDOM?: boolean
115
143
  }
116
144
 
@@ -168,6 +196,7 @@ declare module '@micro-app/types' {
168
196
  inline?: boolean
169
197
  disableScopecss?: boolean
170
198
  disableSandbox?: boolean
199
+ disableMemoryRouter?: boolean
171
200
  ssr?: boolean
172
201
  lifeCycles?: lifeCyclesType
173
202
  preFetchApps?: prefetchParamList
@@ -184,16 +213,143 @@ declare module '@micro-app/types' {
184
213
  inline?: boolean
185
214
  disableScopecss?: boolean
186
215
  disableSandbox?: boolean
216
+ disableMemoryRouter?: boolean
187
217
  ssr?: boolean
188
218
  lifeCycles?: lifeCyclesType
189
219
  plugins?: plugins
190
220
  fetch?: fetchType
191
221
  preFetch(apps: prefetchParamList): void
222
+ router: Router // eslint-disable-line
192
223
  start(options?: OptionsType): void
193
224
  }
194
225
 
195
226
  // special CallableFunction for interact
196
227
  type CallableFunctionForInteract = CallableFunction & { __APP_NAME__?: string, __AUTO_TRIGGER__?: boolean }
228
+
229
+ interface ShadowLocation {
230
+ [k: string]: string
231
+ }
232
+
233
+ interface MicroLocation extends Location, URL {
234
+ // shadowLocation is the current location information (href, pathname, search, hash)
235
+ shadowLocation: ShadowLocation
236
+ fullPath: string
237
+ [key: string]: any
238
+ }
239
+
240
+ type MicroHistory = ProxyHandler<History>
241
+ type MicroState = any
242
+ type HistoryProxyValue =
243
+ Pick<
244
+ History,
245
+ 'length' |
246
+ 'scrollRestoration' |
247
+ 'state' |
248
+ 'back' |
249
+ 'forward' |
250
+ 'go' |
251
+ 'pushState' |
252
+ 'replaceState'
253
+ > | CallableFunction
254
+ interface MicroRouter {
255
+ microLocation: MicroLocation
256
+ microHistory: MicroHistory
257
+ }
258
+ type LocationQueryValue = string | null
259
+ type LocationQueryObject = Record<
260
+ string,
261
+ LocationQueryValue | LocationQueryValue[]
262
+ >
263
+
264
+ type LocationQuery = {
265
+ hashQuery?: LocationQueryObject,
266
+ searchQuery?: LocationQueryObject
267
+ }
268
+
269
+ type GuardLocation = Record<keyof MicroLocation, any>
270
+
271
+ type CurrentRoute = Map<string, GuardLocation>
272
+
273
+ interface RouterTarget {
274
+ name: string
275
+ path: string
276
+ state?: unknown
277
+ replace?: boolean
278
+ }
279
+
280
+ type navigationMethod = (to: RouterTarget) => void
281
+
282
+ interface AccurateGuard {
283
+ [appName: string]: (to: GuardLocation, from: GuardLocation) => void
284
+ }
285
+
286
+ type GlobalNormalGuard = ((appName: string, to: GuardLocation, from: GuardLocation) => void)
287
+
288
+ type RouterGuard = AccurateGuard | GlobalNormalGuard
289
+
290
+ // Router API for developer
291
+ interface Router {
292
+ // current route of all apps
293
+ readonly current: CurrentRoute
294
+ /**
295
+ * encodeURI of microApp path
296
+ * @param path url path
297
+ */
298
+ encode(path: string): string
299
+ /**
300
+ * decodeURI of microApp path
301
+ * @param path url path
302
+ */
303
+ decode(path: string): ReturnType<Router['encode']>
304
+ /**
305
+ * Navigate to a new URL by pushing an entry in the history
306
+ * stack.
307
+ * @param to - Route location to navigate to
308
+ */
309
+ push: navigationMethod
310
+ /**
311
+ * Navigate to a new URL by replacing the current entry in
312
+ * the history stack.
313
+ *
314
+ * @param to - Route location to navigate to
315
+ */
316
+ replace: navigationMethod
317
+ /**
318
+ * Move forward or backward through the history. calling `history.go()`.
319
+ *
320
+ * @param delta - The position in the history to which you want to move,
321
+ * relative to the current page
322
+ */
323
+ go: Func
324
+ /**
325
+ * Go back in history if possible by calling `history.back()`.
326
+ */
327
+ back: Func
328
+ /**
329
+ * Go forward in history if possible by calling `history.forward()`.
330
+ */
331
+ forward: Func
332
+ /**
333
+ * Add a navigation guard that executes before any navigation
334
+ * @param guard global hook for
335
+ */
336
+ beforeEach(guard: RouterGuard): () => boolean
337
+ /**
338
+ * Add a navigation guard that executes after any navigation
339
+ * @param guard global hook for
340
+ */
341
+ afterEach(guard: RouterGuard): () => boolean
342
+
343
+ setDefaultPage(appName: string, path: string): () => boolean
344
+ removeDefaultPage(appName: string): boolean
345
+ getDefaultPage(key: PropertyKey): string | undefined
346
+ }
347
+
348
+ // result of add/remove microApp path on browser url
349
+ type HandleMicroPathResult = {
350
+ fullPath: string,
351
+ isAttach2Hash: boolean,
352
+ }
197
353
  }
198
354
 
199
355
  declare namespace JSX {