@micro-zoe/micro-app 1.0.0-alpha.0 → 1.0.0-alpha.10

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 CHANGED
@@ -35,10 +35,6 @@ It is the lowest cost framework for accessing micro front-end, and provides a se
35
35
  micro-app has no restrictions on the front-end framework, and any framework can be used as a base application to embed any type of micro application of the framework.
36
36
 
37
37
  # How to use
38
- The micro front end is divided into a base application (also called main application) and a micro application.
39
-
40
- Here is a common example: the base application uses the Vue framework, uses history routing, the micro application uses the react framework, and uses hash routing. We list the modifications that need to be made by the base application and the micro application, and introduce the use of micro-app in detail.
41
-
42
38
  ## base application
43
39
  **1、Install**
44
40
  ```bash
@@ -151,6 +147,9 @@ For more commands, see [DEVELOP](https://github.com/micro-zoe/micro-app/blob/mas
151
147
  Yes, please see [nextjs](https://micro-zoe.github.io/micro-app/docs.html#/zh-cn/framework/nextjs), [nuxtjs](https://micro-zoe.github.io/micro-app/docs.html#/zh-cn/framework/nuxtjs) for details.
152
148
  </details>
153
149
 
150
+ # Communication
151
+ [Official Wechat group](./Contact.md)
152
+
154
153
  # Contributors
155
154
  <a href="https://github.com/micro-zoe/micro-app/graphs/contributors">
156
155
  <img src="https://contrib.rocks/image?repo=micro-zoe/micro-app" />
package/README.zh-cn.md CHANGED
@@ -28,7 +28,7 @@
28
28
  [English](https://github.com/micro-zoe/micro-app)|简体中文|[官网文档](https://micro-zoe.github.io/micro-app/)|[讨论组](https://github.com/micro-zoe/micro-app/discussions)|[聊天室](https://gitter.im/microzoe/micro-app)
29
29
 
30
30
  # 📖简介
31
- micro-app是京东零售推出的一款微前端框架,它基于类WebComponent进行渲染,从组件化的思维实现微前端,旨在降低上手难度、提升工作效率。它是目前接入微前端成本最低的框架,并且提供了JS沙箱、样式隔离、元素隔离、预加载、资源地址补全、插件系统、数据通信等一系列完善的功能。
31
+ micro-app是京东零售推出的一款微前端框架,它基于类WebComponent进行渲染,从组件化的思维实现微前端,旨在降低上手难度、提升工作效率。它是目前接入微前端成本最低的框架,并且提供了JS沙箱、样式隔离、元素隔离、预加载、虚拟路由系统、插件系统、数据通信等一系列完善的功能。
32
32
 
33
33
  micro-app与技术栈无关,对前端框架没有限制,任何框架都可以作为基座应用嵌入任何类型的子应用。
34
34
 
@@ -145,6 +145,9 @@ yarn start # 访问 http://localhost:3000
145
145
  支持,详情请查看[nextjs](https://micro-zoe.github.io/micro-app/docs.html#/zh-cn/framework/nextjs)、[nuxtjs](https://micro-zoe.github.io/micro-app/docs.html#/zh-cn/framework/nuxtjs)
146
146
  </details>
147
147
 
148
+ # 开发交流
149
+ [官方交流微信群](./Contact.md)
150
+
148
151
  # 贡献者们
149
152
  <a href="https://github.com/micro-zoe/micro-app/graphs/contributors">
150
153
  <img src="https://contrib.rocks/image?repo=micro-zoe/micro-app" />
package/lib/index.d.ts CHANGED
@@ -4,26 +4,28 @@
4
4
  // ../../@micro-app/types
5
5
 
6
6
  declare module '@micro-zoe/micro-app' {
7
- export { default, MicroApp, getActiveApps, getAllApps, unmountApp, unmountAllApps, } from '@micro-zoe/micro-app/micro_app';
7
+ export { default, MicroApp, getActiveApps, getAllApps, unmountApp, unmountAllApps, reload, renderApp, } from '@micro-zoe/micro-app/micro_app';
8
8
  export { default as preFetch, } from '@micro-zoe/micro-app/prefetch';
9
9
  export { removeDomScope, pureCreateElement, version, } from '@micro-zoe/micro-app/libs/utils';
10
10
  export { EventCenterForMicroApp, } from '@micro-zoe/micro-app/interact';
11
11
  }
12
12
 
13
13
  declare module '@micro-zoe/micro-app/micro_app' {
14
- import type { OptionsType, MicroAppConfigType, lifeCyclesType, plugins, fetchType, Router } from '@micro-app/types';
14
+ import type { OptionsType, MicroAppBaseType, Router, AppName, Func, lifeCyclesType, MicroAppConfig, GetActiveAppsParam } from '@micro-app/types';
15
15
  import preFetch from '@micro-zoe/micro-app/prefetch';
16
16
  import { EventCenterForBaseApp } from '@micro-zoe/micro-app/interact';
17
17
  /**
18
18
  * if app not prefetch & not unmount, then app is active
19
19
  * @param excludeHiddenApp exclude hidden keep-alive app, default is false
20
+ * @param excludePreRender exclude pre render app
20
21
  * @returns active apps
21
22
  */
22
- export function getActiveApps(excludeHiddenApp?: boolean): string[];
23
+ export function getActiveApps({ excludeHiddenApp, excludePreRender, }?: GetActiveAppsParam): AppName[];
23
24
  export function getAllApps(): string[];
24
25
  type unmountAppOptions = {
25
26
  destroy?: boolean;
26
27
  clearAliveState?: boolean;
28
+ clearData?: boolean;
27
29
  };
28
30
  /**
29
31
  * unmount app by appName
@@ -31,26 +33,48 @@ declare module '@micro-zoe/micro-app/micro_app' {
31
33
  * @param options unmountAppOptions
32
34
  * @returns Promise<void>
33
35
  */
34
- export function unmountApp(appName: string, options?: unmountAppOptions): Promise<void>;
35
- export function unmountAllApps(options?: unmountAppOptions): Promise<void>;
36
- export class MicroApp extends EventCenterForBaseApp implements MicroAppConfigType {
37
- tagName: string;
38
- shadowDOM?: boolean;
39
- destroy?: boolean;
40
- inline?: boolean;
41
- disableScopecss?: boolean;
42
- disableSandbox?: boolean;
43
- disableMemoryRouter?: boolean;
44
- ssr?: boolean;
36
+ export function unmountApp(appName: string, options?: unmountAppOptions): Promise<boolean>;
37
+ export function unmountAllApps(options?: unmountAppOptions): Promise<boolean>;
38
+ /**
39
+ * Re render app from the command line
40
+ * microApp.reload(destroy)
41
+ * @param appName app.name
42
+ * @param destroy unmount app with destroy mode
43
+ * @returns Promise<boolean>
44
+ */
45
+ export function reload(appName: string, destroy?: boolean): Promise<boolean>;
46
+ interface RenderAppOptions extends MicroAppConfig {
47
+ name: string;
48
+ url: string;
49
+ container: string | Element;
50
+ baseroute?: string;
51
+ 'default-page'?: string;
52
+ data?: Record<PropertyKey, unknown>;
53
+ onDataChange?: Func;
45
54
  lifeCycles?: lifeCyclesType;
46
- plugins?: plugins;
47
- fetch?: fetchType;
48
- preFetch: typeof preFetch;
55
+ [key: string]: unknown;
56
+ }
57
+ /**
58
+ * Manually render app
59
+ * @param options RenderAppOptions
60
+ * @returns Promise<boolean>
61
+ */
62
+ export function renderApp(options: RenderAppOptions): Promise<boolean>;
63
+ export class MicroApp extends EventCenterForBaseApp implements MicroAppBaseType {
64
+ tagName: string;
65
+ options: OptionsType;
49
66
  router: Router;
67
+ preFetch: typeof preFetch;
68
+ unmountApp: typeof unmountApp;
69
+ unmountAllApps: typeof unmountAllApps;
70
+ getActiveApps: typeof getActiveApps;
71
+ getAllApps: typeof getAllApps;
72
+ reload: typeof reload;
73
+ renderApp: typeof renderApp;
50
74
  start(options?: OptionsType): void;
51
75
  }
52
- const _default: MicroApp;
53
- export default _default;
76
+ const microApp: MicroApp;
77
+ export default microApp;
54
78
  }
55
79
 
56
80
  declare module '@micro-zoe/micro-app/prefetch' {
@@ -60,18 +84,23 @@ declare module '@micro-zoe/micro-app/prefetch' {
60
84
  * {
61
85
  * name: string,
62
86
  * url: string,
63
- * disableScopecss?: boolean,
64
- * disableSandbox?: boolean,
65
- * disableMemoryRouter?: boolean,
87
+ * esmodule: boolean,
88
+ * inline: boolean,
89
+ * 'disable-scopecss': boolean,
90
+ * 'disable-sandbox': boolean,
91
+ * level: number,
92
+ * 'default-page': string,
93
+ * 'disable-patch-request': boolean,
66
94
  * },
67
95
  * ...
68
96
  * ])
69
97
  * Note:
70
- * 1: preFetch is asynchronous and is performed only when the browser is idle
71
- * 2: disableScopecss, disableSandbox, disableMemoryRouter must be same with micro-app element, if conflict, the one who executes first shall prevail
72
- * @param apps micro apps
98
+ * 1: preFetch is async and is performed only when the browser is idle
99
+ * 2: options of prefetch preferably match the config of the micro-app element, although this is not required
100
+ * @param apps micro app options
101
+ * @param delay delay time
73
102
  */
74
- export default function preFetch(apps: prefetchParamList): void;
103
+ export default function preFetch(apps: prefetchParamList, delay?: number): void;
75
104
  /**
76
105
  * load global assets into cache
77
106
  * @param assets global assets of js, css
@@ -80,7 +109,7 @@ declare module '@micro-zoe/micro-app/prefetch' {
80
109
  }
81
110
 
82
111
  declare module '@micro-zoe/micro-app/libs/utils' {
83
- import type { Func, LocationQueryObject, MicroLocation } from '@micro-app/types';
112
+ import type { Func, LocationQueryObject, MicroLocation, AttrsType, fiberTasks } from '@micro-app/types';
84
113
  export const version = "__MICRO_APP_VERSION__";
85
114
  export const isBrowser: boolean;
86
115
  export const globalThis: any;
@@ -100,12 +129,18 @@ declare module '@micro-zoe/micro-app/libs/utils' {
100
129
  export function isNull(target: unknown): target is null;
101
130
  export function isString(target: unknown): target is string;
102
131
  export function isBoolean(target: unknown): target is boolean;
132
+ export function isNumber(target: unknown): target is Number;
103
133
  export function isFunction(target: unknown): target is Function;
104
- export function isPlainObject(target: unknown): target is Record<PropertyKey, unknown>;
134
+ export function isPlainObject<T = Record<PropertyKey, unknown>>(target: unknown): target is T;
135
+ export function isObject(target: unknown): target is Object;
105
136
  export function isPromise(target: unknown): target is Promise<unknown>;
106
- export function isBoundFunction(target: unknown): target is Function;
137
+ export function isBoundFunction(target: unknown): boolean;
138
+ export function isConstructor(target: unknown): boolean;
107
139
  export function isShadowRoot(target: unknown): target is ShadowRoot;
108
140
  export function isURL(target: unknown): target is URL;
141
+ export function isElement(target: unknown): target is Element;
142
+ export function isNode(target: unknown): target is Node;
143
+ export function isProxyDocument(target: unknown): target is Document;
109
144
  /**
110
145
  * format error log
111
146
  * @param msg message
@@ -127,7 +162,7 @@ declare module '@micro-zoe/micro-app/libs/utils' {
127
162
  /**
128
163
  * create URL as MicroLocation
129
164
  */
130
- export const createURL: (p: string | URL, b?: string | undefined) => MicroLocation;
165
+ export const createURL: (path: string | URL, base?: string | undefined) => MicroLocation;
131
166
  /**
132
167
  * Add address protocol
133
168
  * @param url address
@@ -180,6 +215,11 @@ declare module '@micro-zoe/micro-app/libs/utils' {
180
215
  export function createNonceSrc(): string;
181
216
  export function unique(array: any[]): any[];
182
217
  export const requestIdleCallback: any;
218
+ /**
219
+ * Wrap requestIdleCallback with promise
220
+ * Exec callback when browser idle
221
+ */
222
+ export function promiseRequestIdle(callback: CallableFunction): Promise<void>;
183
223
  export function setCurrentAppName(appName: string | null): void;
184
224
  export function throttleDeferForSetAppName(appName: string): void;
185
225
  export function getCurrentAppName(): string | null;
@@ -235,6 +275,31 @@ declare module '@micro-zoe/micro-app/libs/utils' {
235
275
  get: (key: PropertyKey) => T | undefined;
236
276
  delete: (key: PropertyKey) => boolean;
237
277
  };
278
+ export function getAttributes(element: Element): AttrsType;
279
+ /**
280
+ * if fiberTasks exist, wrap callback with promiseRequestIdle
281
+ * if not, execute callback
282
+ * @param fiberTasks fiber task list
283
+ * @param callback action callback
284
+ */
285
+ export function injectFiberTask(fiberTasks: fiberTasks, callback: CallableFunction): void;
286
+ /**
287
+ * serial exec fiber task of link, style, script
288
+ * @param tasks task array or null
289
+ */
290
+ export function serialExecFiberTasks(tasks: fiberTasks): Promise<void> | null;
291
+ /**
292
+ * inline script start with inline-xxx
293
+ * @param address source address
294
+ */
295
+ export function isInlineScript(address: string): boolean;
296
+ /**
297
+ * call function with try catch
298
+ * @param fn target function
299
+ * @param appName app.name
300
+ * @param args arguments
301
+ */
302
+ export function callFnWithTryCatch(fn: Func | null, appName: string, msgSuffix: string, ...args: unknown[]): void;
238
303
  }
239
304
 
240
305
  declare module '@micro-zoe/micro-app/interact' {
@@ -255,11 +320,16 @@ declare module '@micro-zoe/micro-app/interact' {
255
320
  * dispatch global data
256
321
  * @param data data
257
322
  */
258
- setGlobalData(data: Record<PropertyKey, unknown>): void;
323
+ setGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
324
+ forceSetGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
259
325
  /**
260
326
  * get global data
261
327
  */
262
328
  getGlobalData(): Record<PropertyKey, unknown> | null;
329
+ /**
330
+ * clear global data
331
+ */
332
+ clearGlobalData(): void;
263
333
  /**
264
334
  * clear all listener of global data
265
335
  * if appName exists, only the specified functions is cleared
@@ -292,7 +362,14 @@ declare module '@micro-zoe/micro-app/interact' {
292
362
  * @param appName app.name
293
363
  * @param data data
294
364
  */
295
- setData(appName: string, data: Record<PropertyKey, unknown>): void;
365
+ setData(appName: string, data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
366
+ forceSetData(appName: string, data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
367
+ /**
368
+ * clear data from base app
369
+ * @param appName app.name
370
+ * @param fromBaseApp whether clear data from child app, default is true
371
+ */
372
+ clearData(appName: string, fromBaseApp?: boolean): void;
296
373
  /**
297
374
  * clear all listener for specified micro app
298
375
  * @param appName app.name
@@ -320,12 +397,18 @@ declare module '@micro-zoe/micro-app/interact' {
320
397
  /**
321
398
  * get data from base app
322
399
  */
323
- getData(): Record<PropertyKey, unknown> | null;
400
+ getData(fromBaseApp?: boolean): Record<PropertyKey, unknown> | null;
324
401
  /**
325
402
  * dispatch data to base app
326
403
  * @param data data
327
404
  */
328
- dispatch(data: Record<PropertyKey, unknown>): void;
405
+ dispatch(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
406
+ forceDispatch(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
407
+ /**
408
+ * clear data from child app
409
+ * @param fromBaseApp whether clear data from base app, default is false
410
+ */
411
+ clearData(fromBaseApp?: boolean): void;
329
412
  /**
330
413
  * clear all listeners
331
414
  */