@micro-zoe/micro-app 0.5.1 → 0.6.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 +9 -6
- package/README.zh-cn.md +11 -8
- package/lib/index.d.ts +81 -2
- package/lib/index.esm.js +693 -447
- 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 +5 -6
- package/polyfill/jsx-custom-event.js +14 -6
- package/polyfill/jsx-custom-event.js.map +1 -1
- package/typings/global.d.ts +14 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micro-zoe/micro-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A lightweight, efficient and powerful micro front-end framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "lib/index.min.js",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"start": "yarn start:main-react16",
|
|
15
15
|
"start:main-react16": "npm-run-all --parallel build:watch start-child:* main-react16",
|
|
16
16
|
"start:main-vue2": "npm-run-all --parallel build:watch start-child:* main-vue2",
|
|
17
|
-
"start:main-
|
|
17
|
+
"start:main-vite": "npm-run-all --parallel build:watch start-child:* main-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
20
|
"install:main-react16": "cd dev/main-react16 && yarn",
|
|
21
21
|
"install:main-vue2": "cd dev/main-vue2 && yarn",
|
|
22
|
-
"install:main-
|
|
22
|
+
"install:main-vite": "cd dev/main-vite && yarn",
|
|
23
23
|
"install:child-react16": "cd dev/children/react16 && yarn",
|
|
24
24
|
"install:child-react17": "cd dev/children/react17 && yarn",
|
|
25
25
|
"install:child-vue2": "cd dev/children/vue2 && yarn",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"install:child-angular11": "cd dev/children/angular11 && yarn",
|
|
29
29
|
"main-react16": "cd dev/main-react16 && yarn start",
|
|
30
30
|
"main-vue2": "cd dev/main-vue2 && yarn start",
|
|
31
|
-
"main-
|
|
31
|
+
"main-vite": "cd dev/main-vite && yarn start",
|
|
32
32
|
"start-child:react16": "cd dev/children/react16 && yarn start",
|
|
33
33
|
"start-child:react17": "cd dev/children/react17 && yarn start",
|
|
34
34
|
"start-child:vue2": "cd dev/children/vue2 && yarn start",
|
|
@@ -43,8 +43,7 @@
|
|
|
43
43
|
"test:server": "node scripts/test_server.js --start",
|
|
44
44
|
"test": "jest",
|
|
45
45
|
"test:watch": "jest --watch",
|
|
46
|
-
"test:coverage": "jest --coverage"
|
|
47
|
-
"prepublishOnly": "yarn lint && yarn test && yarn build"
|
|
46
|
+
"test:coverage": "jest --coverage"
|
|
48
47
|
},
|
|
49
48
|
"repository": {
|
|
50
49
|
"type": "git",
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// @ts-ignore
|
|
1
|
+
const React = require('react');
|
|
4
2
|
// lifecycles
|
|
5
|
-
const eventLifeCycles = [
|
|
3
|
+
const eventLifeCycles = [
|
|
4
|
+
'oncreated',
|
|
5
|
+
'onbeforemount',
|
|
6
|
+
'onmounted',
|
|
7
|
+
'onunmount',
|
|
8
|
+
'onerror',
|
|
9
|
+
'ondatachange',
|
|
10
|
+
'onbeforeshow',
|
|
11
|
+
'onaftershow',
|
|
12
|
+
'onafterhidden',
|
|
13
|
+
];
|
|
6
14
|
function jsxCustomEvent(type, props, ...children) {
|
|
7
15
|
if (typeof type !== 'string' || !/^micro-app(-\S+)?/.test(type) || !props) {
|
|
8
16
|
return React.createElement.apply(null, [type, props, ...children]);
|
|
@@ -41,6 +49,6 @@ function jsxCustomEvent(type, props, ...children) {
|
|
|
41
49
|
};
|
|
42
50
|
return React.createElement.apply(null, [type, newProps, ...children]);
|
|
43
51
|
}
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
module.exports = jsxCustomEvent;
|
|
53
|
+
module.exports.default = jsxCustomEvent;
|
|
46
54
|
//# sourceMappingURL=jsx-custom-event.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-custom-event.js","sources":["../src/polyfill/jsx-custom-event.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"jsx-custom-event.js","sources":["../src/polyfill/jsx-custom-event.ts"],"sourcesContent":["const React = require('react')\n\ntype MicroElementType = HTMLElement & Record<string, unknown>\n\n// lifecycles\nconst eventLifeCycles = [\n 'oncreated',\n 'onbeforemount',\n 'onmounted',\n 'onunmount',\n 'onerror',\n 'ondatachange',\n 'onbeforeshow',\n 'onaftershow',\n 'onafterhidden',\n]\n\nfunction 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) || !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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CAAC,KAAK,EAAE,GAAG,CAAC;oBAChD,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;oBAC3C,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,UAAU;qBAC/B,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC,EAC9C;oBACA,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;oBACrD,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE;;wBAEhB,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;qBAC5D;;oBAED,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,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,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,cAAc,CAAA;AAC/B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,cAAc"}
|
package/typings/global.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ declare module '@micro-app/types' {
|
|
|
45
45
|
name: string // app name
|
|
46
46
|
url: string // app url
|
|
47
47
|
ssrUrl: string // html path in ssr mode
|
|
48
|
-
container: HTMLElement | ShadowRoot | null // app
|
|
48
|
+
container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, DIV(keep-alive)
|
|
49
49
|
inline: boolean // whether js runs in inline script mode, default is false
|
|
50
50
|
scopecss: boolean // whether use css scoped, default is true
|
|
51
51
|
useSandbox: boolean // whether use js sandbox, default is true
|
|
@@ -72,16 +72,24 @@ declare module '@micro-app/types' {
|
|
|
72
72
|
): void
|
|
73
73
|
|
|
74
74
|
// unmount app
|
|
75
|
-
unmount (destroy: boolean): void
|
|
75
|
+
unmount (destroy: boolean, unmountcb?: CallableFunction): void
|
|
76
76
|
|
|
77
77
|
// app rendering error
|
|
78
78
|
onerror (e: Error): void
|
|
79
79
|
|
|
80
|
-
// get app
|
|
81
|
-
|
|
80
|
+
// get app state
|
|
81
|
+
getAppState (): string
|
|
82
|
+
|
|
83
|
+
getKeepAliveState(): string | null
|
|
82
84
|
|
|
83
85
|
// actions for completely destroy
|
|
84
86
|
actionsForCompletelyDestory (): void
|
|
87
|
+
|
|
88
|
+
// hidden app when disconnectedCallback with keep-alive
|
|
89
|
+
hiddenKeepAliveApp (): void
|
|
90
|
+
|
|
91
|
+
// show app when connectedCallback with keep-alive
|
|
92
|
+
showKeepAliveApp (container: HTMLElement | ShadowRoot): void
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
interface MicroAppElementType {
|
|
@@ -162,6 +170,7 @@ declare module '@micro-app/types' {
|
|
|
162
170
|
disableScopecss?: boolean
|
|
163
171
|
disableSandbox?: boolean
|
|
164
172
|
macro?: boolean
|
|
173
|
+
ssr?: boolean
|
|
165
174
|
lifeCycles?: lifeCyclesType
|
|
166
175
|
preFetchApps?: prefetchParamList
|
|
167
176
|
plugins?: plugins
|
|
@@ -178,6 +187,7 @@ declare module '@micro-app/types' {
|
|
|
178
187
|
disableScopecss?: boolean
|
|
179
188
|
disableSandbox?: boolean
|
|
180
189
|
macro?: boolean
|
|
190
|
+
ssr?: boolean
|
|
181
191
|
lifeCycles?: lifeCyclesType
|
|
182
192
|
plugins?: plugins
|
|
183
193
|
fetch?: fetchType
|