@micro-zoe/micro-app 0.4.1 → 0.5.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 +12 -57
- package/README.zh-cn.md +11 -54
- package/lib/index.d.ts +66 -31
- package/lib/index.esm.js +1797 -1580
- package/lib/index.esm.js.map +1 -1
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.map +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/index.umd.js.map +1 -1
- package/package.json +21 -24
- package/polyfill/jsx-custom-event.js +29 -28
- package/polyfill/jsx-custom-event.js.map +1 -1
- package/typings/global.d.ts +49 -38
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micro-zoe/micro-app",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "A lightweight, efficient and powerful micro front-end framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "lib/index.min.js",
|
|
7
7
|
"module": "lib/index.esm.js",
|
|
@@ -17,24 +17,24 @@
|
|
|
17
17
|
"start:main-vue3-vite": "npm-run-all --parallel build:watch start-child:* main-vue3-vite",
|
|
18
18
|
"build:watch": "cross-env NODE_ENV='development' rollup -c -w",
|
|
19
19
|
"build": "cross-env NODE_ENV='production' rollup -c && npm run createtype && npm run afterbuild",
|
|
20
|
-
"install:main-react16": "cd
|
|
21
|
-
"install:main-vue2": "cd
|
|
22
|
-
"install:main-vue3-vite": "cd
|
|
23
|
-
"install:child-react16": "cd
|
|
24
|
-
"install:child-react17": "cd
|
|
25
|
-
"install:child-vue2": "cd
|
|
26
|
-
"install:child-vue3": "cd
|
|
27
|
-
"install:child-vite": "cd
|
|
28
|
-
"install:child-angular11": "cd
|
|
29
|
-
"main-react16": "cd
|
|
30
|
-
"main-vue2": "cd
|
|
31
|
-
"main-vue3-vite": "cd
|
|
32
|
-
"start-child:react16": "cd
|
|
33
|
-
"start-child:react17": "cd
|
|
34
|
-
"start-child:vue2": "cd
|
|
35
|
-
"start-child:vue3": "cd
|
|
36
|
-
"start-child:vite": "cd
|
|
37
|
-
"start-child:angular11": "cd
|
|
20
|
+
"install:main-react16": "cd dev/main-react16 && yarn",
|
|
21
|
+
"install:main-vue2": "cd dev/main-vue2 && yarn",
|
|
22
|
+
"install:main-vue3-vite": "cd dev/main-vue3-vite && yarn",
|
|
23
|
+
"install:child-react16": "cd dev/children/react16 && yarn",
|
|
24
|
+
"install:child-react17": "cd dev/children/react17 && yarn",
|
|
25
|
+
"install:child-vue2": "cd dev/children/vue2 && yarn",
|
|
26
|
+
"install:child-vue3": "cd dev/children/vue3 && yarn",
|
|
27
|
+
"install:child-vite": "cd dev/children/vite && yarn",
|
|
28
|
+
"install:child-angular11": "cd dev/children/angular11 && yarn",
|
|
29
|
+
"main-react16": "cd dev/main-react16 && yarn start",
|
|
30
|
+
"main-vue2": "cd dev/main-vue2 && yarn start",
|
|
31
|
+
"main-vue3-vite": "cd dev/main-vue3-vite && yarn start",
|
|
32
|
+
"start-child:react16": "cd dev/children/react16 && yarn start",
|
|
33
|
+
"start-child:react17": "cd dev/children/react17 && yarn start",
|
|
34
|
+
"start-child:vue2": "cd dev/children/vue2 && yarn start",
|
|
35
|
+
"start-child:vue3": "cd dev/children/vue3 && yarn start",
|
|
36
|
+
"start-child:vite": "cd dev/children/vite && yarn start",
|
|
37
|
+
"start-child:angular11": "cd dev/children/angular11 && yarn start",
|
|
38
38
|
"docs": "docsify serve docs --port 2000",
|
|
39
39
|
"lint": "eslint --cache '**/*.{js,ts}'",
|
|
40
40
|
"lint:fix": "yarn lint --fix",
|
|
@@ -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 build"
|
|
47
|
+
"prepublishOnly": "yarn lint && yarn test && yarn build"
|
|
48
48
|
},
|
|
49
49
|
"repository": {
|
|
50
50
|
"type": "git",
|
|
@@ -82,9 +82,6 @@
|
|
|
82
82
|
]
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {},
|
|
85
|
-
"peerDependencies": {
|
|
86
|
-
"@babel/runtime": ">=7.0.0"
|
|
87
|
-
},
|
|
88
85
|
"devDependencies": {
|
|
89
86
|
"@babel/core": "~7.12.10",
|
|
90
87
|
"@babel/plugin-transform-runtime": "~7.12.10",
|
|
@@ -4,40 +4,41 @@ import React from 'react';
|
|
|
4
4
|
// lifecycles
|
|
5
5
|
const eventLifeCycles = ['oncreated', 'onbeforemount', 'onmounted', 'onunmount', 'onerror', 'ondatachange'];
|
|
6
6
|
function jsxCustomEvent(type, props, ...children) {
|
|
7
|
+
if (typeof type !== 'string' || !/^micro-app(-\S+)?/.test(type) || !props) {
|
|
8
|
+
return React.createElement.apply(null, [type, props, ...children]);
|
|
9
|
+
}
|
|
7
10
|
const newProps = Object.assign({}, props);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
// ref will call when create, update, unmount
|
|
12
|
+
newProps.ref = (element) => {
|
|
13
|
+
if (typeof props.ref === 'function') {
|
|
14
|
+
props.ref(element);
|
|
15
|
+
}
|
|
16
|
+
else if (typeof props.ref === 'object') {
|
|
17
|
+
props.ref.current = element;
|
|
18
|
+
}
|
|
19
|
+
// when unmount and update the element is null
|
|
20
|
+
if (element) {
|
|
21
|
+
// Update data when the prev and next data are different
|
|
22
|
+
if (toString.call(props.data) === '[object Object]' && element.data !== props.data) {
|
|
23
|
+
element.data = props.data;
|
|
16
24
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
element
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (Object.prototype.hasOwnProperty.call(props, key) &&
|
|
25
|
-
eventLifeCycles.includes(key.toLowerCase()) &&
|
|
26
|
-
typeof props[key] === 'function' &&
|
|
27
|
-
(!element[key] || element[key] !== props[key])) {
|
|
28
|
-
const eventName = key.toLowerCase().replace('on', '');
|
|
29
|
-
if (element[key]) {
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
element.removeEventListener(eventName, element[key], false);
|
|
32
|
-
}
|
|
25
|
+
for (const key in props) {
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(props, key) &&
|
|
27
|
+
eventLifeCycles.includes(key.toLowerCase()) &&
|
|
28
|
+
typeof props[key] === 'function' &&
|
|
29
|
+
(!element[key] || element[key] !== props[key])) {
|
|
30
|
+
const eventName = key.toLowerCase().replace('on', '');
|
|
31
|
+
if (element[key]) {
|
|
33
32
|
// @ts-ignore
|
|
34
|
-
element.
|
|
35
|
-
element[key] = props[key];
|
|
33
|
+
element.removeEventListener(eventName, element[key], false);
|
|
36
34
|
}
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
element.addEventListener(eventName, props[key], false);
|
|
37
|
+
element[key] = props[key];
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
41
42
|
return React.createElement.apply(null, [type, newProps, ...children]);
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-custom-event.js","sources":["../src/polyfill/jsx-custom-event.ts"],"sourcesContent":["// @ts-ignore\nimport React from 'react'\n\ntype MicroElementType = HTMLElement & Record<string, unknown>\n\n// lifecycles\nconst eventLifeCycles = ['oncreated', 'onbeforemount', 'onmounted', 'onunmount', 'onerror', 'ondatachange']\n\nexport default function jsxCustomEvent (\n type: string | CallableFunction,\n props: Record<string, unknown> | null,\n ...children: any[]\n): void {\n
|
|
1
|
+
{"version":3,"file":"jsx-custom-event.js","sources":["../src/polyfill/jsx-custom-event.ts"],"sourcesContent":["// @ts-ignore\nimport React from 'react'\n\ntype MicroElementType = HTMLElement & Record<string, unknown>\n\n// lifecycles\nconst eventLifeCycles = ['oncreated', 'onbeforemount', 'onmounted', 'onunmount', 'onerror', 'ondatachange']\n\nexport default function jsxCustomEvent (\n type: string | CallableFunction,\n props: Record<string, unknown> | null,\n ...children: any[]\n): void {\n if (typeof type !== 'string' || !/^micro-app(-\\S+)?/.test(type as string) || !props) {\n return React.createElement.apply(null, [type, props, ...children])\n }\n\n const newProps = Object.assign({}, props)\n\n // ref will call when create, update, unmount\n newProps.ref = (element: MicroElementType | null) => {\n if (typeof props.ref === 'function') {\n props.ref(element)\n } else if (typeof props.ref === 'object') {\n (props.ref as any).current = element\n }\n\n // when unmount and update the element is null\n if (element) {\n // Update data when the prev and next data are different\n if (toString.call(props.data) === '[object Object]' && element.data !== props.data) {\n element.data = props.data\n }\n\n for (const key in props) {\n if (\n Object.prototype.hasOwnProperty.call(props, key) &&\n eventLifeCycles.includes(key.toLowerCase()) &&\n typeof props[key] === 'function' &&\n (!element[key] || element[key] !== props[key])\n ) {\n const eventName = key.toLowerCase().replace('on', '')\n if (element[key]) {\n // @ts-ignore\n element.removeEventListener(eventName, element[key], false)\n }\n // @ts-ignore\n element.addEventListener(eventName, props[key], false)\n element[key] = props[key]\n }\n }\n }\n }\n\n return React.createElement.apply(null, [type, newProps, ...children])\n}\n"],"names":[],"mappings":";;AAAA;AAKA;AACA,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,CAAC,CAAA;SAEnF,cAAc,CACpC,IAA+B,EAC/B,KAAqC,EACrC,GAAG,QAAe;IAElB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAc,CAAC,IAAI,CAAC,KAAK,EAAE;QACnF,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC,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,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;oBACtD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;iBAC1B;aACF;SACF;KACF,CAAA;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAA;AACvE;;;;"}
|
package/typings/global.d.ts
CHANGED
|
@@ -6,23 +6,14 @@ declare module '@micro-app/types' {
|
|
|
6
6
|
type microWindowType = Window & any
|
|
7
7
|
|
|
8
8
|
interface SandBoxInterface {
|
|
9
|
-
active: boolean // sandbox state
|
|
10
9
|
proxyWindow: WindowProxy
|
|
11
|
-
recordUmdEffect: CallableFunction
|
|
12
|
-
rebuildUmdEffect: CallableFunction
|
|
13
|
-
releaseEffect: CallableFunction
|
|
14
|
-
// Scoped global Properties(Properties that can only get and set in microWindow, will not escape to rawWindow)
|
|
15
|
-
scopeProperties: Array<PropertyKey>
|
|
16
|
-
// Properties that can be escape to rawWindow
|
|
17
|
-
escapeProperties: Array<PropertyKey>
|
|
18
10
|
microWindow: Window // Proxy target
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
rebuildUmdSnapshot(): void
|
|
25
|
-
inject(microWindow: microWindowType, appName: string, url: string): void
|
|
11
|
+
start (baseroute: string): void
|
|
12
|
+
stop (): void
|
|
13
|
+
// record umd snapshot before the first execution of umdHookMount
|
|
14
|
+
recordUmdSnapshot (): void
|
|
15
|
+
// rebuild umd snapshot before remount umd app
|
|
16
|
+
rebuildUmdSnapshot (): void
|
|
26
17
|
}
|
|
27
18
|
|
|
28
19
|
type sourceLinkInfo = {
|
|
@@ -39,6 +30,7 @@ declare module '@micro-app/types' {
|
|
|
39
30
|
defer: boolean // defer script
|
|
40
31
|
module: boolean // module type script
|
|
41
32
|
isGlobal?: boolean // share js to global
|
|
33
|
+
code2Function?: Function // code to Function
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
interface sourceType {
|
|
@@ -52,6 +44,7 @@ declare module '@micro-app/types' {
|
|
|
52
44
|
isPrefetch: boolean // whether prefetch app, default is false
|
|
53
45
|
name: string // app name
|
|
54
46
|
url: string // app url
|
|
47
|
+
ssrUrl: string // html path in ssr mode
|
|
55
48
|
container: HTMLElement | ShadowRoot | null // app container
|
|
56
49
|
inline: boolean // whether js runs in inline script mode, default is false
|
|
57
50
|
scopecss: boolean // whether use css scoped, default is true
|
|
@@ -60,35 +53,49 @@ declare module '@micro-app/types' {
|
|
|
60
53
|
baseroute: string // route prefix, default is ''
|
|
61
54
|
source: sourceType // sources of css, js, html
|
|
62
55
|
sandBox: SandBoxInterface | null // sanxbox
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
umdMode: boolean // is umd mode
|
|
57
|
+
|
|
58
|
+
// Load resources
|
|
59
|
+
loadSourceCode (): void
|
|
60
|
+
|
|
61
|
+
// resource is loaded
|
|
62
|
+
onLoad (html: HTMLElement): void
|
|
63
|
+
|
|
64
|
+
// Error loading HTML
|
|
65
|
+
onLoadError (e: Error): void
|
|
66
|
+
|
|
67
|
+
// mount app
|
|
68
|
+
mount (
|
|
67
69
|
container?: HTMLElement | ShadowRoot,
|
|
68
70
|
inline?: boolean,
|
|
69
71
|
baseroute?: string,
|
|
70
|
-
): void
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
): void
|
|
73
|
+
|
|
74
|
+
// unmount app
|
|
75
|
+
unmount (destroy: boolean): void
|
|
76
|
+
|
|
77
|
+
// app rendering error
|
|
78
|
+
onerror (e: Error): void
|
|
79
|
+
|
|
80
|
+
// get app status
|
|
81
|
+
getAppStatus (): string
|
|
82
|
+
|
|
83
|
+
// actions for completely destroy
|
|
84
|
+
actionsForCompletelyDestory (): void
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
interface MicroAppElementType {
|
|
78
88
|
appName: AttrType // app name
|
|
79
89
|
appUrl: AttrType // app url
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
handleCreate(): void // create app
|
|
90
|
-
handleUnmount (destory: boolean): void // unmount app
|
|
91
|
-
getDisposeResult (name: string): boolean // Get configuration
|
|
90
|
+
|
|
91
|
+
// Hooks for element append to documents
|
|
92
|
+
connectedCallback (): void
|
|
93
|
+
|
|
94
|
+
// Hooks for element delete from documents
|
|
95
|
+
disconnectedCallback (): void
|
|
96
|
+
|
|
97
|
+
// Hooks for element attributes change
|
|
98
|
+
attributeChangedCallback (a: 'name' | 'url', o: string, n: string): void
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
type prefetchParam = {
|
|
@@ -150,7 +157,7 @@ declare module '@micro-app/types' {
|
|
|
150
157
|
type OptionsType = {
|
|
151
158
|
tagName?: string
|
|
152
159
|
shadowDOM?: boolean
|
|
153
|
-
|
|
160
|
+
destroy?: boolean
|
|
154
161
|
inline?: boolean
|
|
155
162
|
disableScopecss?: boolean
|
|
156
163
|
disableSandbox?: boolean
|
|
@@ -166,7 +173,7 @@ declare module '@micro-app/types' {
|
|
|
166
173
|
interface MicroAppConfigType {
|
|
167
174
|
tagName: string
|
|
168
175
|
shadowDOM?: boolean
|
|
169
|
-
|
|
176
|
+
destroy?: boolean
|
|
170
177
|
inline?: boolean
|
|
171
178
|
disableScopecss?: boolean
|
|
172
179
|
disableSandbox?: boolean
|
|
@@ -189,3 +196,7 @@ declare namespace JSX {
|
|
|
189
196
|
}
|
|
190
197
|
|
|
191
198
|
declare module '@micro-zoe/micro-app/polyfill/jsx-custom-event'
|
|
199
|
+
|
|
200
|
+
declare const __DEV__: boolean
|
|
201
|
+
|
|
202
|
+
declare const __TEST__: boolean
|