kj-micro-app 1.0.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/LICENSE +21 -0
- package/README.md +156 -0
- package/README.zh-cn.md +156 -0
- package/lib/index.d.ts +483 -0
- package/lib/index.esm.js +9419 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.min.js +2 -0
- package/lib/index.min.js.map +1 -0
- package/lib/index.umd.js +2 -0
- package/lib/index.umd.js.map +1 -0
- package/package.json +134 -0
- package/polyfill/jsx-custom-event.js +54 -0
- package/polyfill/jsx-custom-event.js.map +1 -0
- package/typings/global.d.ts +582 -0
package/package.json
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kj-micro-app",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "A lightweight, efficient and powerful micro front-end framework",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "lib/index.min.js",
|
|
7
|
+
"module": "lib/index.esm.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"directories": {
|
|
10
|
+
"doc": "docs"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"bootstrap": "yarn && npm-run-all --serial install:*",
|
|
14
|
+
"start": "yarn start:main-react16",
|
|
15
|
+
"start:main-react16": "npm-run-all --parallel build:watch start-child:* main-react16",
|
|
16
|
+
"start:main-vue2": "npm-run-all --parallel build:watch start-child:* main-vue2",
|
|
17
|
+
"start:main-vite": "npm-run-all --parallel build:watch start-child:* main-vite",
|
|
18
|
+
"build:watch": "cross-env NODE_ENV='development' rollup -c -w",
|
|
19
|
+
"build": "cross-env NODE_ENV='production' rollup -c && npm run createtype && npm run afterbuild",
|
|
20
|
+
"install:main-react16": "cd dev/main-react16 && yarn",
|
|
21
|
+
"install:main-vue2": "cd dev/main-vue2 && yarn",
|
|
22
|
+
"install:main-vite": "cd dev/main-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-vite2": "cd dev/children/vite2 && yarn",
|
|
28
|
+
"install:child-vite4": "cd dev/children/vite4 && yarn",
|
|
29
|
+
"install:child-angular11": "cd dev/children/angular11 && yarn",
|
|
30
|
+
"main-react16": "cd dev/main-react16 && yarn start",
|
|
31
|
+
"main-vue2": "cd dev/main-vue2 && yarn start",
|
|
32
|
+
"main-vite": "cd dev/main-vite && yarn start",
|
|
33
|
+
"start-child:react16": "cd dev/children/react16 && yarn start",
|
|
34
|
+
"start-child:react17": "cd dev/children/react17 && yarn start",
|
|
35
|
+
"start-child:vue2": "cd dev/children/vue2 && yarn start",
|
|
36
|
+
"start-child:vue3": "cd dev/children/vue3 && yarn start",
|
|
37
|
+
"start-child:vite2": "cd dev/children/vite2 && yarn start",
|
|
38
|
+
"start-child:vite4": "cd dev/children/vite4 && yarn start",
|
|
39
|
+
"start-child:angular11": "cd dev/children/angular11 && yarn start",
|
|
40
|
+
"docs": "docsify serve docs --port 2000",
|
|
41
|
+
"lint": "eslint --cache '**/*.{js,ts}'",
|
|
42
|
+
"lint:fix": "yarn lint --fix",
|
|
43
|
+
"createtype": "node scripts/create_type.js",
|
|
44
|
+
"afterbuild": "node scripts/after_build.js",
|
|
45
|
+
"test:server": "node scripts/test_server.js --start",
|
|
46
|
+
"test": "jest",
|
|
47
|
+
"test:watch": "jest --watch",
|
|
48
|
+
"test:coverage": "jest --coverage",
|
|
49
|
+
"test:unit": "jest src/__tests__/unit",
|
|
50
|
+
"test:unit:coverage": "npm run test:unit -- --coverage",
|
|
51
|
+
"publish": "npm publish --access public"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/kuaijing-bailing/micro-app.git"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"webcomponents",
|
|
62
|
+
"micro-frontend",
|
|
63
|
+
"microapp"
|
|
64
|
+
],
|
|
65
|
+
"files": [
|
|
66
|
+
"es",
|
|
67
|
+
"lib",
|
|
68
|
+
"polyfill",
|
|
69
|
+
"plugins",
|
|
70
|
+
"typings"
|
|
71
|
+
],
|
|
72
|
+
"author": "cangdu",
|
|
73
|
+
"license": "MIT",
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/jd-opensource/micro-app/issues"
|
|
76
|
+
},
|
|
77
|
+
"husky": {
|
|
78
|
+
"hooks": {
|
|
79
|
+
"pre-commit": "lint-staged",
|
|
80
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"lint-staged": {
|
|
84
|
+
"**/*.{js,ts}": [
|
|
85
|
+
"yarn lint"
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@babel/core": "~7.12.10",
|
|
91
|
+
"@babel/plugin-transform-runtime": "~7.12.10",
|
|
92
|
+
"@babel/preset-env": "~7.12.11",
|
|
93
|
+
"@babel/runtime": "~7.12.5",
|
|
94
|
+
"@commitlint/cli": "~11.0.0",
|
|
95
|
+
"@commitlint/config-conventional": "~11.0.0",
|
|
96
|
+
"@rollup/plugin-babel": "~5.2.2",
|
|
97
|
+
"@rollup/plugin-node-resolve": "~11.0.1",
|
|
98
|
+
"@rollup/plugin-replace": "~2.4.1",
|
|
99
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
100
|
+
"@rollup/plugin-typescript": "~8.1.0",
|
|
101
|
+
"@types/jest": "~26.0.24",
|
|
102
|
+
"@types/node": "~14.14.19",
|
|
103
|
+
"@typescript-eslint/eslint-plugin": "~4.11.1",
|
|
104
|
+
"@typescript-eslint/parser": "~4.11.1",
|
|
105
|
+
"@webcomponents/webcomponentsjs": "~2.5.0",
|
|
106
|
+
"babel-jest": "~26.6.0",
|
|
107
|
+
"chalk": "~4.1.0",
|
|
108
|
+
"coveralls": "~3.1.1",
|
|
109
|
+
"cross-env": "~7.0.3",
|
|
110
|
+
"custom-elements-es5-adapter": "~1.0.0",
|
|
111
|
+
"docsify-cli": "~4.4.2",
|
|
112
|
+
"dts-bundle": "~0.7.3",
|
|
113
|
+
"eslint": "~7.17.0",
|
|
114
|
+
"eslint-config-standard": "~16.0.2",
|
|
115
|
+
"eslint-plugin-import": "~2.22.1",
|
|
116
|
+
"eslint-plugin-jest": "~24.3.6",
|
|
117
|
+
"eslint-plugin-node": "~11.1.0",
|
|
118
|
+
"eslint-plugin-promise": "~4.2.1",
|
|
119
|
+
"eslint-plugin-standard": "~5.0.0",
|
|
120
|
+
"fs-extra": "~10.0.0",
|
|
121
|
+
"gzip-size": "~6.0.0",
|
|
122
|
+
"husky": "~4.3.6",
|
|
123
|
+
"jest": "~26.6.0",
|
|
124
|
+
"lint-staged": "~10.5.3",
|
|
125
|
+
"live-server": "~1.2.1",
|
|
126
|
+
"node-fetch": "~2.6.1",
|
|
127
|
+
"npm-run-all": "~4.1.5",
|
|
128
|
+
"pretty-bytes": "~5.5.0",
|
|
129
|
+
"rollup": "~2.35.1",
|
|
130
|
+
"rollup-plugin-terser": "~7.0.2",
|
|
131
|
+
"ts-jest": "~26.5.6",
|
|
132
|
+
"typescript": "~4.1.3"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const React = require('react');
|
|
2
|
+
// lifecycles
|
|
3
|
+
const eventLifeCycles = [
|
|
4
|
+
'oncreated',
|
|
5
|
+
'onbeforemount',
|
|
6
|
+
'onmounted',
|
|
7
|
+
'onunmount',
|
|
8
|
+
'onerror',
|
|
9
|
+
'ondatachange',
|
|
10
|
+
'onbeforeshow',
|
|
11
|
+
'onaftershow',
|
|
12
|
+
'onafterhidden',
|
|
13
|
+
];
|
|
14
|
+
function jsxCustomEvent(type, props, ...children) {
|
|
15
|
+
if (typeof type !== 'string' || !/^micro-app(-\S+)?/.test(type) || !props) {
|
|
16
|
+
return React.createElement.apply(null, [type, props, ...children]);
|
|
17
|
+
}
|
|
18
|
+
const newProps = Object.assign({}, props);
|
|
19
|
+
// ref will call when create, update, unmount
|
|
20
|
+
newProps.ref = (element) => {
|
|
21
|
+
if (typeof props.ref === 'function') {
|
|
22
|
+
props.ref(element);
|
|
23
|
+
}
|
|
24
|
+
else if (typeof props.ref === 'object') {
|
|
25
|
+
props.ref.current = element;
|
|
26
|
+
}
|
|
27
|
+
// when unmount and update the element is null
|
|
28
|
+
if (element) {
|
|
29
|
+
// Update data when the prev and next data are different
|
|
30
|
+
if (toString.call(props.data) === '[object Object]' && element.data !== props.data) {
|
|
31
|
+
element.data = props.data;
|
|
32
|
+
}
|
|
33
|
+
for (const key in props) {
|
|
34
|
+
if (Object.prototype.hasOwnProperty.call(props, key) &&
|
|
35
|
+
eventLifeCycles.includes(key.toLowerCase()) &&
|
|
36
|
+
typeof props[key] === 'function' &&
|
|
37
|
+
(!element[key] || element[key] !== props[key])) {
|
|
38
|
+
const eventName = key.toLowerCase().replace('on', '');
|
|
39
|
+
if (element[key]) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
element.removeEventListener(eventName, element[key], false);
|
|
42
|
+
}
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
element.addEventListener(eventName, props[key], false);
|
|
45
|
+
element[key] = props[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return React.createElement.apply(null, [type, newProps, ...children]);
|
|
51
|
+
}
|
|
52
|
+
module.exports = jsxCustomEvent;
|
|
53
|
+
module.exports.default = jsxCustomEvent;
|
|
54
|
+
//# sourceMappingURL=jsx-custom-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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])\n}\n\nmodule.exports = jsxCustomEvent\nmodule.exports.default = jsxCustomEvent\n"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAI9B;AACA,MAAM,eAAe,GAAG;IACtB,WAAW;IACX,eAAe;IACf,WAAW;IACX,WAAW;IACX,SAAS;IACT,cAAc;IACd,cAAc;IACd,aAAa;IACb,eAAe;CAChB,CAAA;AA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