pixuireactcomponents 1.3.101 → 1.3.102
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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { h } from 'preact';
|
|
2
2
|
/**
|
|
3
3
|
* 轮播组件
|
|
4
|
-
* @param cRef -
|
|
4
|
+
* @param cRef - 组件引用,其中导出了3个方法:handleNext,handlePrev,setShowIndex
|
|
5
|
+
* 使用cRef.current.handleNext(),cRef.current.handlePrev(),cRef.current.setShowIndex(index)来调用
|
|
5
6
|
* @param children - 轮播元素
|
|
6
7
|
* @param defaultIndex - 默认展示元素的索引,从1开始
|
|
7
8
|
* @param compWidth - 轮播元素宽度
|
|
@@ -47,7 +47,8 @@ import { useImperativeHandle, useState, useRef, useMemo, useEffect } from 'preac
|
|
|
47
47
|
// });
|
|
48
48
|
/**
|
|
49
49
|
* 轮播组件
|
|
50
|
-
* @param cRef -
|
|
50
|
+
* @param cRef - 组件引用,其中导出了3个方法:handleNext,handlePrev,setShowIndex
|
|
51
|
+
* 使用cRef.current.handleNext(),cRef.current.handlePrev(),cRef.current.setShowIndex(index)来调用
|
|
51
52
|
* @param children - 轮播元素
|
|
52
53
|
* @param defaultIndex - 默认展示元素的索引,从1开始
|
|
53
54
|
* @param compWidth - 轮播元素宽度
|
|
@@ -187,10 +188,9 @@ export function Carousel(props) {
|
|
|
187
188
|
if (isLastCarouseItem() || isFirstCarouseLastItem()) {
|
|
188
189
|
setShowTransition(false);
|
|
189
190
|
}
|
|
190
|
-
// console.log('showIndex' + showIndex)
|
|
191
191
|
isMoving.current = false;
|
|
192
192
|
//触发onSlideChange
|
|
193
|
-
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange)
|
|
193
|
+
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange && showTransition)
|
|
194
194
|
onSlideChange(showIndex - 1);
|
|
195
195
|
// 处理首尾特殊case
|
|
196
196
|
if (isLastCarouseItem()) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import h from 'lib/dom';
|
|
2
|
+
export declare const LoadChecker: (props: {
|
|
3
|
+
children?: h.JSX.Element | HTMLElement | h.JSX.Element[] | HTMLElement[] | undefined;
|
|
4
|
+
rootClass?: string | undefined;
|
|
5
|
+
timeoutPeriod?: number | undefined;
|
|
6
|
+
onLoad?: Function | undefined;
|
|
7
|
+
}) => h.JSX.Element;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
import h from 'lib/dom';
|
|
11
|
+
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
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 _c = useState(false), loaded = _c[0], setLoaded = _c[1];
|
|
15
|
+
var _d = useState(0), total = _d[0], setTotal = _d[1];
|
|
16
|
+
var _e = useState([]), loadedElements = _e[0], setLoadedElements = _e[1];
|
|
17
|
+
var ref = useRef(null);
|
|
18
|
+
//0.5s后直接显示
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
var timer = setTimeout(function () {
|
|
21
|
+
setLoaded(true);
|
|
22
|
+
}, timeoutPeriod);
|
|
23
|
+
var node = ref.current;
|
|
24
|
+
if (!node) {
|
|
25
|
+
setLoaded(true);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
setTotal(getLoadCount(node, 0));
|
|
29
|
+
return function () {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
var getLoadCount = function (node, preCount) {
|
|
34
|
+
if (!node)
|
|
35
|
+
return preCount;
|
|
36
|
+
var temp = 0;
|
|
37
|
+
if (node.tagName.toLowerCase() === 'img' || (node.style && node.style.backgroundImage)) {
|
|
38
|
+
temp++;
|
|
39
|
+
// console.log(node.id);
|
|
40
|
+
node.addEventListener('load', handleLoad);
|
|
41
|
+
}
|
|
42
|
+
node.childNodes &&
|
|
43
|
+
node.childNodes.forEach(function (child) {
|
|
44
|
+
temp += getLoadCount(child, temp);
|
|
45
|
+
});
|
|
46
|
+
return temp;
|
|
47
|
+
};
|
|
48
|
+
useEffect(function () {
|
|
49
|
+
if (loaded && onLoad) {
|
|
50
|
+
onLoad();
|
|
51
|
+
}
|
|
52
|
+
}, [loaded]);
|
|
53
|
+
var handleLoad = function (event) {
|
|
54
|
+
setLoadedElements(function (prevElements) {
|
|
55
|
+
if (prevElements.includes(event.target)) {
|
|
56
|
+
return prevElements;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
var newElements = __spreadArray(__spreadArray([], prevElements, true), [event.target], false);
|
|
60
|
+
if (newElements.length >= total) {
|
|
61
|
+
setLoaded(true);
|
|
62
|
+
}
|
|
63
|
+
return newElements;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
return (h("div", { ref: ref, style: { visibility: loaded ? 'visible' : 'hidden' }, className: rootClass }, children));
|
|
68
|
+
};
|