pixuireactcomponents 1.4.6 → 1.4.7
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/package.json
CHANGED
|
@@ -10,20 +10,32 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
10
10
|
import h from 'lib/dom';
|
|
11
11
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
12
12
|
export var LoadChecker = function (props) {
|
|
13
|
-
var children = props.children, _a = props.rootClass, rootClass = _a === void 0 ? '' : _a, _b = props.timeoutPeriod, timeoutPeriod = _b === void 0 ? 500 : _b, onLoad = props.onLoad;
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
13
|
+
var children = props.children, _a = props.rootClass, rootClass = _a === void 0 ? '' : _a, _b = props.timeoutPeriod, timeoutPeriod = _b === void 0 ? 500 : _b, onLoad = props.onLoad, _c = props.enableCompLog, enableCompLog = _c === void 0 ? false : _c, _d = props.onlyHttp, onlyHttp = _d === void 0 ? false : _d;
|
|
14
|
+
var _e = useState(false), loaded = _e[0], setLoaded = _e[1];
|
|
15
|
+
var _f = useState(false), collectFinish = _f[0], setCollectFinish = _f[1];
|
|
16
|
+
var _g = useState([]), loadedElements = _g[0], setLoadedElements = _g[1];
|
|
17
|
+
var _h = useState([]), collectSrcs = _h[0], setCollectSrcs = _h[1];
|
|
18
|
+
var _j = useState(new Date().getTime()), timeStamp = _j[0], setTimeStamp = _j[1];
|
|
18
19
|
var ref = useRef(null);
|
|
20
|
+
var myLog = function () {
|
|
21
|
+
var args = [];
|
|
22
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
23
|
+
args[_i] = arguments[_i];
|
|
24
|
+
}
|
|
25
|
+
if (enableCompLog) {
|
|
26
|
+
console.log.apply(console, __spreadArray(['LoadChecker: '], args, false));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
19
29
|
//0.5s后直接显示
|
|
20
30
|
useEffect(function () {
|
|
21
31
|
var timer = setTimeout(function () {
|
|
22
32
|
setLoaded(true);
|
|
33
|
+
myLog(timeoutPeriod, 's timeout, direct show');
|
|
23
34
|
}, timeoutPeriod);
|
|
24
35
|
var node = ref.current;
|
|
25
36
|
if (!node) {
|
|
26
37
|
setLoaded(true);
|
|
38
|
+
myLog('no root node, direct show');
|
|
27
39
|
return;
|
|
28
40
|
}
|
|
29
41
|
getLoadCount(node);
|
|
@@ -35,7 +47,11 @@ export var LoadChecker = function (props) {
|
|
|
35
47
|
useEffect(function () {
|
|
36
48
|
if (!collectFinish)
|
|
37
49
|
return;
|
|
50
|
+
myLog('elementsLoadedCount:', loadedElements.length, 'collectSrcs:', collectSrcs.length);
|
|
51
|
+
myLog('loadedElements:', loadedElements, collectSrcs);
|
|
38
52
|
if (collectSrcs.length == 0 || loadedElements.length >= collectSrcs.length) {
|
|
53
|
+
myLog('all loaded, srcs:', JSON.stringify(collectSrcs, null, 2));
|
|
54
|
+
myLog('all loaded, timeStamp:', new Date().getTime() - timeStamp);
|
|
39
55
|
setLoaded(true);
|
|
40
56
|
onLoad && onLoad();
|
|
41
57
|
}
|
|
@@ -68,6 +84,9 @@ export var LoadChecker = function (props) {
|
|
|
68
84
|
if (src.startsWith('url(')) {
|
|
69
85
|
src = src.substring(4, src.length - 1);
|
|
70
86
|
}
|
|
87
|
+
if (onlyHttp && (!src.startsWith('http') || src.startsWith('http://localhost'))) {
|
|
88
|
+
return '';
|
|
89
|
+
}
|
|
71
90
|
return src;
|
|
72
91
|
}
|
|
73
92
|
return '';
|