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.
@@ -0,0 +1,7 @@
1
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
2
+
3
+ /**
4
+ * vue-custom-element v3.3.0
5
+ * (c) 2021 Karol Fabjańczuk
6
+ * @license MIT
7
+ */
package/package.json CHANGED
@@ -1,62 +1,61 @@
1
- {
2
- "name": "py-test-component",
3
- "version": "2.0.7",
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": "./src/vue/index.js",
14
- "require": "./src/vue/index.js"
15
- },
16
- "./react": {
17
- "import": "./src/react/index.js",
18
- "require": "./src/react/index.js"
19
- }
20
- },
21
- "files": [
22
- "dist",
23
- "src/react",
24
- "src/vue",
25
- "README.md",
26
- "USAGE.md",
27
- "DEVELOPER.md"
28
- ],
29
- "scripts": {
30
- "build": "webpack --mode production",
31
- "dev": "webpack --mode development --watch"
32
- },
33
- "dependencies": {
34
- "element-ui": "^2.15.0",
35
- "vue": "^2.7.0",
36
- "vue-custom-element": "^3.3.0"
37
- },
38
- "devDependencies": {
39
- "@babel/core": "^7.22.0",
40
- "@babel/preset-env": "^7.22.0",
41
- "@vue/web-component-wrapper": "^1.3.0",
42
- "babel-loader": "^9.1.2",
43
- "css-loader": "^6.8.1",
44
- "style-loader": "^1.3.0",
45
- "vue-loader": "^15.10.1",
46
- "vue-template-compiler": "^2.7.14",
47
- "webpack": "^5.88.0",
48
- "webpack-cli": "^5.1.0"
49
- },
50
- "peerDependencies": {
51
- "element-ui": "^2.15.0",
52
- "vue": "^2.7.0"
53
- },
54
- "peerDependenciesMeta": {
55
- "vue": {
56
- "optional": true
57
- },
58
- "element-ui": {
59
- "optional": true
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
+ }
@@ -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 };