@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/README.md CHANGED
@@ -97,7 +97,7 @@ yarn bootstrap
97
97
  yarn start
98
98
  ```
99
99
 
100
- For more commands, see [DEVELP](https://github.com/micro-zoe/micro-app/blob/master/DEVELOP.md)
100
+ For more commands, see [DEVELOP](https://github.com/micro-zoe/micro-app/blob/master/DEVELOP.md)
101
101
 
102
102
  # FAQ
103
103
  <details>
@@ -152,9 +152,9 @@ For more commands, see [DEVELP](https://github.com/micro-zoe/micro-app/blob/mast
152
152
  </details>
153
153
 
154
154
  # Contributors
155
- <a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="https://micro-zoe.com/contributors.svg?height=55&people=11" /></a>
156
- <!-- opencollective is inaccurate -->
157
- <!-- <a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="https://opencollective.com/micro-app/contributors.svg?width=890&button=false" /></a> -->
155
+ <a href="https://github.com/micro-zoe/micro-app/graphs/contributors">
156
+ <img src="https://contrib.rocks/image?repo=micro-zoe/micro-app" />
157
+ </a>
158
158
 
159
159
  # License
160
160
  [MIT License](https://github.com/micro-zoe/micro-app/blob/master/LICENSE)
package/README.zh-cn.md CHANGED
@@ -33,11 +33,7 @@ micro-app是京东零售推出的一款微前端框架,它基于类WebComponen
33
33
  micro-app与技术栈无关,对前端框架没有限制,任何框架都可以作为基座应用嵌入任何类型的子应用。
34
34
 
35
35
  # 如何使用
36
- 微前端分为基座应用(也可以叫做主应用)和子应用。
37
-
38
- 这里以一种比较常见的情况举例:基座应用使用vue框架,采用history路由,子应用使用react框架,采用hash路由,我们分别列出基座应用和子应用需要进行的修改,具体介绍micro-app的使用方式。
39
-
40
- ## 基座应用
36
+ ## 主应用
41
37
 
42
38
  **1、安装依赖**
43
39
  ```bash
@@ -54,11 +50,8 @@ microApp.start()
54
50
 
55
51
  **3、在页面中嵌入微前端应用**
56
52
  ```html
57
- <!-- my-page.vue -->
58
- <template>
59
- <!-- 👇 name为应用名称,url为应用地址 -->
60
- <micro-app name='my-app' url='http://localhost:3000/'></micro-app>
61
- </template>
53
+ <!-- 👇 name为应用名称,url为应用地址 -->
54
+ <micro-app name='my-app' url='http://localhost:3000/'></micro-app>
62
55
  ```
63
56
 
64
57
  ## 子应用
@@ -72,14 +65,14 @@ devServer: {
72
65
  },
73
66
  ```
74
67
 
75
- 以上微前端基本渲染完成,效果如下:
68
+ 以上即完成微前端的嵌入,效果如下:
76
69
 
77
70
  <img src="https://img12.360buyimg.com/imagetools/jfs/t1/196940/34/1541/38365/610a14fcE46c21374/c321b9f8fa50a8fc.png" alt="result" width='900'/>
78
71
 
79
72
  更多详细配置可以查看[官网文档](https://micro-zoe.github.io/micro-app/docs.html#/zh-cn/start)
80
73
 
81
74
  # 🤝 参与共建
82
- 如果您对这个项目感兴趣,欢迎提 pull request,也欢迎 "Star" 支持一下 ^_^
75
+ 如果您对这个项目感兴趣,欢迎参与贡献,也欢迎 "Star" 支持一下 ^_^
83
76
 
84
77
  ### 本地运行
85
78
  1、克隆项目
@@ -153,9 +146,10 @@ yarn start # 访问 http://localhost:3000
153
146
  </details>
154
147
 
155
148
  # 贡献者们
156
- <a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="https://micro-zoe.com/contributors.svg?height=55&people=11" /></a>
157
- <!-- opencollective is inaccurate -->
158
- <!-- <a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="https://opencollective.com/micro-app/contributors.svg?width=890&button=false" /></a> -->
149
+ <a href="https://github.com/micro-zoe/micro-app/graphs/contributors">
150
+ <img src="https://contrib.rocks/image?repo=micro-zoe/micro-app" />
151
+ </a>
152
+
159
153
 
160
154
  # License
161
155
  [MIT License](https://github.com/micro-zoe/micro-app/blob/master/LICENSE)
package/lib/index.d.ts CHANGED
@@ -11,7 +11,7 @@ declare module '@micro-zoe/micro-app' {
11
11
  }
12
12
 
13
13
  declare module '@micro-zoe/micro-app/micro_app' {
14
- import type { OptionsType, MicroAppConfigType, lifeCyclesType, plugins, fetchType } from '@micro-app/types';
14
+ import type { OptionsType, MicroAppConfigType, lifeCyclesType, plugins, fetchType, Router } 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
  /**
@@ -21,18 +21,18 @@ declare module '@micro-zoe/micro-app/micro_app' {
21
21
  */
22
22
  export function getActiveApps(excludeHiddenApp?: boolean): string[];
23
23
  export function getAllApps(): string[];
24
- export interface unmountAppParams {
24
+ type unmountAppOptions = {
25
25
  destroy?: boolean;
26
26
  clearAliveState?: boolean;
27
- }
27
+ };
28
28
  /**
29
29
  * unmount app by appName
30
30
  * @param appName
31
- * @param options unmountAppParams
31
+ * @param options unmountAppOptions
32
32
  * @returns Promise<void>
33
33
  */
34
- export function unmountApp(appName: string, options?: unmountAppParams): Promise<void>;
35
- export function unmountAllApps(options?: unmountAppParams): Promise<void>;
34
+ export function unmountApp(appName: string, options?: unmountAppOptions): Promise<void>;
35
+ export function unmountAllApps(options?: unmountAppOptions): Promise<void>;
36
36
  export class MicroApp extends EventCenterForBaseApp implements MicroAppConfigType {
37
37
  tagName: string;
38
38
  shadowDOM?: boolean;
@@ -40,11 +40,13 @@ declare module '@micro-zoe/micro-app/micro_app' {
40
40
  inline?: boolean;
41
41
  disableScopecss?: boolean;
42
42
  disableSandbox?: boolean;
43
+ disableMemoryRouter?: boolean;
43
44
  ssr?: boolean;
44
45
  lifeCycles?: lifeCyclesType;
45
46
  plugins?: plugins;
46
47
  fetch?: fetchType;
47
48
  preFetch: typeof preFetch;
49
+ router: Router;
48
50
  start(options?: OptionsType): void;
49
51
  }
50
52
  const _default: MicroApp;
@@ -60,12 +62,13 @@ declare module '@micro-zoe/micro-app/prefetch' {
60
62
  * url: string,
61
63
  * disableScopecss?: boolean,
62
64
  * disableSandbox?: boolean,
65
+ * disableMemoryRouter?: boolean,
63
66
  * },
64
67
  * ...
65
68
  * ])
66
69
  * Note:
67
70
  * 1: preFetch is asynchronous and is performed only when the browser is idle
68
- * 2: disableScopecss, disableSandbox must be same with micro-app element, if conflict, the one who executes first shall prevail
71
+ * 2: disableScopecss, disableSandbox, disableMemoryRouter must be same with micro-app element, if conflict, the one who executes first shall prevail
69
72
  * @param apps micro apps
70
73
  */
71
74
  export default function preFetch(apps: prefetchParamList): void;
@@ -77,41 +80,54 @@ declare module '@micro-zoe/micro-app/prefetch' {
77
80
  }
78
81
 
79
82
  declare module '@micro-zoe/micro-app/libs/utils' {
80
- import type { Func } from '@micro-app/types';
83
+ import type { Func, LocationQueryObject, MicroLocation } from '@micro-app/types';
81
84
  export const version = "__MICRO_APP_VERSION__";
82
85
  export const isBrowser: boolean;
83
86
  export const globalThis: any;
84
- export function isUndefined(target: unknown): target is undefined;
85
- export function isNull(target: unknown): target is null;
86
- export function isString(target: unknown): target is string;
87
- export function isBoolean(target: unknown): target is boolean;
88
- export function isFunction(target: unknown): boolean;
87
+ export const noop: () => void;
88
+ export const noopFalse: () => boolean;
89
89
  export const isArray: (arg: any) => arg is any[];
90
- export function isPlainObject(target: unknown): boolean;
91
- export function isPromise(target: unknown): boolean;
92
- export function isBoundFunction(target: any): boolean;
93
- export function isShadowRoot(target: unknown): boolean;
90
+ export const assign: {
91
+ <T, U>(target: T, source: U): T & U;
92
+ <T_1, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
93
+ <T_2, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
94
+ (target: object, ...sources: any[]): any;
95
+ };
94
96
  export const rawDefineProperty: (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any;
95
97
  export const rawDefineProperties: (o: any, properties: PropertyDescriptorMap & ThisType<any>) => any;
96
98
  export const rawHasOwnProperty: (v: string | number | symbol) => boolean;
99
+ export function isUndefined(target: unknown): target is undefined;
100
+ export function isNull(target: unknown): target is null;
101
+ export function isString(target: unknown): target is string;
102
+ export function isBoolean(target: unknown): target is boolean;
103
+ export function isFunction(target: unknown): target is Function;
104
+ export function isPlainObject(target: unknown): target is Record<PropertyKey, unknown>;
105
+ export function isPromise(target: unknown): target is Promise<unknown>;
106
+ export function isBoundFunction(target: unknown): target is Function;
107
+ export function isShadowRoot(target: unknown): target is ShadowRoot;
108
+ export function isURL(target: unknown): target is URL;
97
109
  /**
98
110
  * format error log
99
111
  * @param msg message
100
112
  * @param appName app name, default is null
101
113
  */
102
- export function logError(msg: unknown, appName?: string | null, ...rest: any[]): void;
114
+ export function logError(msg: unknown, appName?: string | null, ...rest: unknown[]): void;
103
115
  /**
104
116
  * format warn log
105
117
  * @param msg message
106
118
  * @param appName app name, default is null
107
119
  */
108
- export function logWarn(msg: unknown, appName?: string | null, ...rest: any[]): void;
120
+ export function logWarn(msg: unknown, appName?: string | null, ...rest: unknown[]): void;
109
121
  /**
110
122
  * async execution
111
123
  * @param fn callback
112
124
  * @param args params
113
125
  */
114
- export function defer(fn: Func, ...args: any[]): void;
126
+ export function defer(fn: Func, ...args: unknown[]): void;
127
+ /**
128
+ * create URL as MicroLocation
129
+ */
130
+ export const createURL: (path: string | URL, base?: string | undefined) => MicroLocation;
115
131
  /**
116
132
  * Add address protocol
117
133
  * @param url address
@@ -132,6 +148,7 @@ declare module '@micro-zoe/micro-app/libs/utils' {
132
148
  * 3. event_center -> EventCenterForBaseApp -> all methods
133
149
  * 4. preFetch
134
150
  * 5. plugins
151
+ * 6. router api (push, replace)
135
152
  */
136
153
  export function formatAppName(name: string | null): string;
137
154
  /**
@@ -191,6 +208,33 @@ declare module '@micro-zoe/micro-app/libs/utils' {
191
208
  */
192
209
  export function trim(str: string): string;
193
210
  export function isFireFox(): boolean;
211
+ /**
212
+ * Transforms a queryString into object.
213
+ * @param search - search string to parse
214
+ * @returns a query object
215
+ */
216
+ export function parseQuery(search: string): LocationQueryObject;
217
+ /**
218
+ * Transforms an object to query string
219
+ * @param queryObject - query object to stringify
220
+ * @returns query string without the leading `?`
221
+ */
222
+ export function stringifyQuery(queryObject: LocationQueryObject): string;
223
+ /**
224
+ * Register or unregister callback/guard with Set
225
+ */
226
+ export function useSetRecord<T>(): {
227
+ add: (handler: T) => () => boolean;
228
+ list: () => Set<T>;
229
+ };
230
+ /**
231
+ * record data with Map
232
+ */
233
+ export function useMapRecord<T>(): {
234
+ add: (key: PropertyKey, value: T) => () => boolean;
235
+ get: (key: PropertyKey) => T | undefined;
236
+ delete: (key: PropertyKey) => boolean;
237
+ };
194
238
  }
195
239
 
196
240
  declare module '@micro-zoe/micro-app/interact' {