py-test-component 2.0.7 → 2.0.8
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/dist/vue.esm.js +2 -0
- package/dist/vue.esm.js.LICENSE.txt +7 -0
- package/dist/vue.js +2 -0
- package/dist/vue.js.LICENSE.txt +7 -0
- package/package.json +61 -62
- package/src/react/index.js +0 -55
- package/src/vue/index.js +0 -32
package/package.json
CHANGED
|
@@ -1,62 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "py-test-component",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "Vue2 + ElementUI 组件库,支持 React 使用",
|
|
5
|
-
"main": "dist/py-component.js",
|
|
6
|
-
"module": "dist/py-component.esm.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"import": "./dist/py-component.esm.js",
|
|
10
|
-
"require": "./dist/py-component.js"
|
|
11
|
-
},
|
|
12
|
-
"./vue": {
|
|
13
|
-
"import": "./
|
|
14
|
-
"require": "./
|
|
15
|
-
},
|
|
16
|
-
"./react": {
|
|
17
|
-
"import": "./
|
|
18
|
-
"require": "./
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"files": [
|
|
22
|
-
"dist",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"element
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"@babel/
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"vue-
|
|
46
|
-
"
|
|
47
|
-
"webpack": "^5.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "py-test-component",
|
|
3
|
+
"version": "2.0.8",
|
|
4
|
+
"description": "Vue2 + ElementUI 组件库,支持 React 使用",
|
|
5
|
+
"main": "dist/py-component.js",
|
|
6
|
+
"module": "dist/py-component.esm.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/py-component.esm.js",
|
|
10
|
+
"require": "./dist/py-component.js"
|
|
11
|
+
},
|
|
12
|
+
"./vue": {
|
|
13
|
+
"import": "./dist/vue.esm.js",
|
|
14
|
+
"require": "./dist/vue.js"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"import": "./dist/react.esm.js",
|
|
18
|
+
"require": "./dist/react.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"USAGE.md",
|
|
25
|
+
"DEVELOPER.md"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "webpack --mode production",
|
|
29
|
+
"dev": "webpack --mode development --watch"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"element-ui": "^2.15.0",
|
|
33
|
+
"vue": "^2.7.0",
|
|
34
|
+
"vue-custom-element": "^3.3.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@babel/core": "^7.22.0",
|
|
38
|
+
"@babel/preset-env": "^7.22.0",
|
|
39
|
+
"@babel/preset-react": "^7.28.5",
|
|
40
|
+
"@vue/web-component-wrapper": "^1.3.0",
|
|
41
|
+
"babel-loader": "^9.1.2",
|
|
42
|
+
"css-loader": "^6.8.1",
|
|
43
|
+
"style-loader": "^1.3.0",
|
|
44
|
+
"vue-loader": "^15.10.1",
|
|
45
|
+
"vue-template-compiler": "^2.7.14",
|
|
46
|
+
"webpack": "^5.88.0",
|
|
47
|
+
"webpack-cli": "^5.1.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"element-ui": "^2.15.0",
|
|
51
|
+
"vue": "^2.7.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"vue": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"element-ui": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/react/index.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState, forwardRef } from 'react';
|
|
2
|
-
|
|
3
|
-
// 注入 ElementUI CSS(只执行一次)
|
|
4
|
-
let cssInjected = false;
|
|
5
|
-
function injectElementUICSS() {
|
|
6
|
-
if (cssInjected || typeof document === 'undefined') return;
|
|
7
|
-
cssInjected = true;
|
|
8
|
-
const link = document.createElement('link');
|
|
9
|
-
link.rel = 'stylesheet';
|
|
10
|
-
link.href = 'https://unpkg.com/element-ui/lib/theme-chalk/index.css';
|
|
11
|
-
document.head.appendChild(link);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// 加载组件库
|
|
15
|
-
function usePyComponent() {
|
|
16
|
-
const [loaded, setLoaded] = useState(false);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
injectElementUICSS();
|
|
19
|
-
import('py-test-component').then(() => setLoaded(true));
|
|
20
|
-
}, []);
|
|
21
|
-
return loaded;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// 通用包装函数:动态创建 React 组件
|
|
25
|
-
function wrapVueComponent(tagName, dataProp = null) {
|
|
26
|
-
return forwardRef(function WrappedComponent({ propData, loading, ...props }, ref) {
|
|
27
|
-
const elRef = useRef(null);
|
|
28
|
-
const loaded = usePyComponent();
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (elRef.current && propData !== undefined && dataProp) {
|
|
32
|
-
elRef.current[dataProp] = propData;
|
|
33
|
-
}
|
|
34
|
-
}, [propData]);
|
|
35
|
-
|
|
36
|
-
if (!loaded && loading) {
|
|
37
|
-
return <div style={{ padding: '20px', textAlign: 'center' }}>{loading}</div>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 使用 createElement 避免 JSX 标签名大小写警告
|
|
41
|
-
return React.createElement(tagName, { ref: ref || elRef, ...props });
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 一键注册所有组件
|
|
46
|
-
export const PyTable = wrapVueComponent('py-table', 'propData');
|
|
47
|
-
export const PyWeather = wrapVueComponent('py-weather', 'propData');
|
|
48
|
-
|
|
49
|
-
// 初始化 store(仅设置,不暴露 store 给外部)
|
|
50
|
-
export function initStore(config) {
|
|
51
|
-
return import('py-test-component').then((m) => {
|
|
52
|
-
const PyComponent = m.default || m;
|
|
53
|
-
PyComponent?.initStore?.(config);
|
|
54
|
-
});
|
|
55
|
-
}
|
package/src/vue/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// Vue 项目专用入口
|
|
2
|
-
// 注意:此组件库基于 Vue 2.7 + ElementUI 构建
|
|
3
|
-
// Vue 3 工程请使用 React 入口(通过 Web Components 方式)
|
|
4
|
-
|
|
5
|
-
import Vue from 'vue';
|
|
6
|
-
import ElementUI from 'element-ui';
|
|
7
|
-
import 'element-ui/lib/theme-chalk/index.css';
|
|
8
|
-
import vueCustomElement from 'vue-custom-element';
|
|
9
|
-
|
|
10
|
-
import PyTable from '../components/PyTable.vue';
|
|
11
|
-
import PyWeather from '../components/PyWeather.vue';
|
|
12
|
-
import store from '../store';
|
|
13
|
-
|
|
14
|
-
// 确保 Vue 和插件已安装
|
|
15
|
-
Vue.use(ElementUI);
|
|
16
|
-
Vue.use(vueCustomElement);
|
|
17
|
-
|
|
18
|
-
// 注册为 Web Components(禁用 Shadow DOM)
|
|
19
|
-
if (!customElements.get('py-table')) {
|
|
20
|
-
Vue.customElement('py-table', PyTable, { shadow: false });
|
|
21
|
-
}
|
|
22
|
-
if (!customElements.get('py-weather')) {
|
|
23
|
-
Vue.customElement('py-weather', PyWeather, { shadow: false });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 初始化 store(统一的方法)
|
|
27
|
-
function initStore(config) {
|
|
28
|
-
store.set(config);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { PyTable, PyWeather, initStore };
|
|
32
|
-
export default { PyTable, PyWeather, initStore };
|