py-test-component 1.0.0
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,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Vue.js v2.7.16
|
|
3
|
+
* (c) 2014-2023 Evan You
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @license
|
|
11
|
+
* Lodash <https://lodash.com/>
|
|
12
|
+
* Copyright JS Foundation and other contributors <https://js.foundation/>
|
|
13
|
+
* Released under MIT license <https://lodash.com/license>
|
|
14
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
15
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Checks if an event is supported in the current execution environment.
|
|
20
|
+
*
|
|
21
|
+
* NOTE: This will not work correctly for non-generic events such as `change`,
|
|
22
|
+
* `reset`, `load`, `error`, and `select`.
|
|
23
|
+
*
|
|
24
|
+
* Borrows from Modernizr.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} eventNameSuffix Event name, e.g. "click".
|
|
27
|
+
* @param {?boolean} capture Check if the capture phase is supported.
|
|
28
|
+
* @return {boolean} True if the event is supported.
|
|
29
|
+
* @internal
|
|
30
|
+
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
31
|
+
*/
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "py-test-component",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vue2 + ElementUI 组件库,支持 React 使用",
|
|
5
|
+
"main": "dist/py-component.js",
|
|
6
|
+
"module": "dist/py-component.esm.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/py-component.js",
|
|
9
|
+
"./react": "./src/react/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src/react"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "webpack --mode production",
|
|
17
|
+
"dev": "webpack --mode development --watch"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"vue": "^2.7.14",
|
|
21
|
+
"element-ui": "^2.15.13"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"webpack": "^5.88.0",
|
|
25
|
+
"webpack-cli": "^5.1.0",
|
|
26
|
+
"vue-loader": "^15.10.1",
|
|
27
|
+
"vue-template-compiler": "^2.7.14",
|
|
28
|
+
"css-loader": "^6.8.1",
|
|
29
|
+
"style-loader": "^1.3.0",
|
|
30
|
+
"babel-loader": "^9.1.2",
|
|
31
|
+
"@babel/core": "^7.22.0",
|
|
32
|
+
"@babel/preset-env": "^7.22.0",
|
|
33
|
+
"@vue/web-component-wrapper": "^1.3.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"vue": "^2.7.0",
|
|
37
|
+
"element-ui": "^2.15.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"vue": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"element-ui": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createElement, useEffect, useRef, forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
|
|
3
|
+
// 加载脚本的 Promise(只加载一次)
|
|
4
|
+
let loadPromise = null;
|
|
5
|
+
|
|
6
|
+
function loadPyComponent() {
|
|
7
|
+
if (loadPromise) return loadPromise;
|
|
8
|
+
if (typeof window === 'undefined') return Promise.resolve();
|
|
9
|
+
if (window.PyComponent) return Promise.resolve(window.PyComponent);
|
|
10
|
+
|
|
11
|
+
loadPromise = new Promise((resolve, reject) => {
|
|
12
|
+
const script = document.createElement('script');
|
|
13
|
+
script.src = '/py-component.js';
|
|
14
|
+
script.async = true;
|
|
15
|
+
script.onload = () => resolve(window.PyComponent);
|
|
16
|
+
script.onerror = reject;
|
|
17
|
+
document.body.appendChild(script);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return loadPromise;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// PyTable React 包装组件
|
|
24
|
+
export const PyTable = forwardRef(function PyTable({ data, ...props }, ref) {
|
|
25
|
+
const elRef = useRef(null);
|
|
26
|
+
|
|
27
|
+
useImperativeHandle(ref, () => ({
|
|
28
|
+
getElement: () => elRef.current
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
loadPyComponent();
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (elRef.current && data) {
|
|
37
|
+
elRef.current.setAttribute('table-data', JSON.stringify(data));
|
|
38
|
+
}
|
|
39
|
+
}, [data]);
|
|
40
|
+
|
|
41
|
+
return createElement('py-table', { ref: elRef, ...props });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// PyWeather React 包装组件
|
|
45
|
+
export const PyWeather = forwardRef(function PyWeather(props, ref) {
|
|
46
|
+
const elRef = useRef(null);
|
|
47
|
+
|
|
48
|
+
useImperativeHandle(ref, () => ({
|
|
49
|
+
getElement: () => elRef.current
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
loadPyComponent();
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
return createElement('py-weather', { ref: elRef, ...props });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// 初始化函数
|
|
60
|
+
export function initPyComponent(config) {
|
|
61
|
+
loadPyComponent().then((PyComponent) => {
|
|
62
|
+
PyComponent.init(config);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 获取 store
|
|
67
|
+
export function getStore() {
|
|
68
|
+
return typeof window !== 'undefined' ? window.PyComponent?.store : null;
|
|
69
|
+
}
|