@micro-zoe/micro-app 0.8.7 → 1.0.0-alpha.2

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
@@ -152,9 +152,9 @@ For more commands, see [DEVELOP](https://github.com/micro-zoe/micro-app/blob/mas
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=13" /></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=13" /></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, appName } 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
  /**
@@ -19,20 +19,20 @@ declare module '@micro-zoe/micro-app/micro_app' {
19
19
  * @param excludeHiddenApp exclude hidden keep-alive app, default is false
20
20
  * @returns active apps
21
21
  */
22
- export function getActiveApps(excludeHiddenApp?: boolean): string[];
22
+ export function getActiveApps(excludeHiddenApp?: boolean): appName[];
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,56 @@ 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 isObject(target: unknown): target is Object;
106
+ export function isPromise(target: unknown): target is Promise<unknown>;
107
+ export function isBoundFunction(target: unknown): boolean;
108
+ export function isConstructor(target: unknown): boolean;
109
+ export function isShadowRoot(target: unknown): target is ShadowRoot;
110
+ export function isURL(target: unknown): target is URL;
97
111
  /**
98
112
  * format error log
99
113
  * @param msg message
100
114
  * @param appName app name, default is null
101
115
  */
102
- export function logError(msg: unknown, appName?: string | null, ...rest: any[]): void;
116
+ export function logError(msg: unknown, appName?: string | null, ...rest: unknown[]): void;
103
117
  /**
104
118
  * format warn log
105
119
  * @param msg message
106
120
  * @param appName app name, default is null
107
121
  */
108
- export function logWarn(msg: unknown, appName?: string | null, ...rest: any[]): void;
122
+ export function logWarn(msg: unknown, appName?: string | null, ...rest: unknown[]): void;
109
123
  /**
110
124
  * async execution
111
125
  * @param fn callback
112
126
  * @param args params
113
127
  */
114
- export function defer(fn: Func, ...args: any[]): void;
128
+ export function defer(fn: Func, ...args: unknown[]): void;
129
+ /**
130
+ * create URL as MicroLocation
131
+ */
132
+ export const createURL: (path: string | URL, base?: string | undefined) => MicroLocation;
115
133
  /**
116
134
  * Add address protocol
117
135
  * @param url address
@@ -132,6 +150,7 @@ declare module '@micro-zoe/micro-app/libs/utils' {
132
150
  * 3. event_center -> EventCenterForBaseApp -> all methods
133
151
  * 4. preFetch
134
152
  * 5. plugins
153
+ * 6. router api (push, replace)
135
154
  */
136
155
  export function formatAppName(name: string | null): string;
137
156
  /**
@@ -191,6 +210,33 @@ declare module '@micro-zoe/micro-app/libs/utils' {
191
210
  */
192
211
  export function trim(str: string): string;
193
212
  export function isFireFox(): boolean;
213
+ /**
214
+ * Transforms a queryString into object.
215
+ * @param search - search string to parse
216
+ * @returns a query object
217
+ */
218
+ export function parseQuery(search: string): LocationQueryObject;
219
+ /**
220
+ * Transforms an object to query string
221
+ * @param queryObject - query object to stringify
222
+ * @returns query string without the leading `?`
223
+ */
224
+ export function stringifyQuery(queryObject: LocationQueryObject): string;
225
+ /**
226
+ * Register or unregister callback/guard with Set
227
+ */
228
+ export function useSetRecord<T>(): {
229
+ add: (handler: T) => () => boolean;
230
+ list: () => Set<T>;
231
+ };
232
+ /**
233
+ * record data with Map
234
+ */
235
+ export function useMapRecord<T>(): {
236
+ add: (key: PropertyKey, value: T) => () => boolean;
237
+ get: (key: PropertyKey) => T | undefined;
238
+ delete: (key: PropertyKey) => boolean;
239
+ };
194
240
  }
195
241
 
196
242
  declare module '@micro-zoe/micro-app/interact' {