pixuireactcomponents 1.1.21 → 1.1.23
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/README.md +5 -5
- package/index.d.ts +15 -15
- package/index.js +16 -16
- package/package.json +11 -11
- package/tools/EventDispatcherJs.d.ts +10 -10
- package/tools/EventDispatcherJs.js +71 -71
- package/tools/Logger.d.ts +6 -6
- package/tools/Logger.js +138 -138
- package/tools/tools.md +21 -21
- package/ui/components/button/Button.d.ts +5 -5
- package/ui/components/button/Button.js +37 -37
- package/ui/components/carousel/Carousel.d.ts +5 -5
- package/ui/components/carousel/Carousel.js +219 -219
- package/ui/components/dropdown/Dropdown.d.ts +30 -30
- package/ui/components/dropdown/Dropdown.js +92 -92
- package/ui/components/dropdown/DropdownOptionUI.d.ts +11 -11
- package/ui/components/dropdown/DropdownOptionUI.js +28 -28
- package/ui/components/dropdown/DropdownSpreadMainUI.d.ts +9 -9
- package/ui/components/dropdown/DropdownSpreadMainUI.js +27 -27
- package/ui/components/dropdown/DropdownUnspreadMainUI.d.ts +9 -9
- package/ui/components/dropdown/DropdownUnspreadMainUI.js +27 -27
- package/ui/components/gradient/GradientText.d.ts +63 -63
- package/ui/components/gradient/GradientText.js +329 -329
- package/ui/components/outlinetext/OutlineText.d.ts +73 -73
- package/ui/components/outlinetext/OutlineText.js +157 -157
- package/ui/components/progress/Progress.d.ts +34 -34
- package/ui/components/progress/Progress.js +142 -142
- package/ui/components/slapface/Slapface.d.ts +12 -12
- package/ui/components/slapface/Slapface.js +233 -227
- package/ui/components/slapface/less/Slapface.less +112 -0
- package/ui/components/slider/Slider.d.ts +57 -57
- package/ui/components/slider/Slider.js +289 -289
- package/ui/components/tab/Tab.d.ts +6 -6
- package/ui/components/tab/Tab.js +27 -27
- package/ui/components/tab/Tabs.d.ts +12 -12
- package/ui/components/tab/Tabs.js +54 -54
- package/ui/ui.md +1 -1
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
import { h, Component } from "preact";
|
|
17
|
-
var Button = /** @class */ (function (_super) {
|
|
18
|
-
__extends(Button, _super);
|
|
19
|
-
function Button() {
|
|
20
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
}
|
|
22
|
-
Button.prototype.render = function (props) {
|
|
23
|
-
var _this = this;
|
|
24
|
-
return (h("div", { onClick: function () {
|
|
25
|
-
var _a;
|
|
26
|
-
if (_this.props.clickEvent) {
|
|
27
|
-
if (_this.props.clickArr)
|
|
28
|
-
(_a = _this.props).clickEvent.apply(_a, props.clickArr);
|
|
29
|
-
else
|
|
30
|
-
_this.props.clickEvent();
|
|
31
|
-
}
|
|
32
|
-
}, onMouseDown: function () { _this.btnImg.src = _this.props.pic_yaxia; }, onMouseUp: function () { _this.btnImg.src = _this.props.pic_xuanfu; }, onMouseOver: function () { _this.btnImg.src = _this.props.pic_xuanfu; }, onMouseOut: function () { _this.btnImg.src = _this.props.pic_changtai; } },
|
|
33
|
-
h("img", { ref: function (img) { _this.btnImg = img; }, src: this.props.pic_changtai })));
|
|
34
|
-
};
|
|
35
|
-
return Button;
|
|
36
|
-
}(Component));
|
|
37
|
-
export { Button };
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { h, Component } from "preact";
|
|
17
|
+
var Button = /** @class */ (function (_super) {
|
|
18
|
+
__extends(Button, _super);
|
|
19
|
+
function Button() {
|
|
20
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
+
}
|
|
22
|
+
Button.prototype.render = function (props) {
|
|
23
|
+
var _this = this;
|
|
24
|
+
return (h("div", { onClick: function () {
|
|
25
|
+
var _a;
|
|
26
|
+
if (_this.props.clickEvent) {
|
|
27
|
+
if (_this.props.clickArr)
|
|
28
|
+
(_a = _this.props).clickEvent.apply(_a, props.clickArr);
|
|
29
|
+
else
|
|
30
|
+
_this.props.clickEvent();
|
|
31
|
+
}
|
|
32
|
+
}, onMouseDown: function () { _this.btnImg.src = _this.props.pic_yaxia; }, onMouseUp: function () { _this.btnImg.src = _this.props.pic_xuanfu; }, onMouseOver: function () { _this.btnImg.src = _this.props.pic_xuanfu; }, onMouseOut: function () { _this.btnImg.src = _this.props.pic_changtai; } },
|
|
33
|
+
h("img", { ref: function (img) { _this.btnImg = img; }, src: this.props.pic_changtai })));
|
|
34
|
+
};
|
|
35
|
+
return Button;
|
|
36
|
+
}(Component));
|
|
37
|
+
export { Button };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h } from 'preact';
|
|
2
|
-
export declare function Carousel(props: any): h.JSX.Element;
|
|
3
|
-
export declare namespace Carousel {
|
|
4
|
-
var Item: (props: any) => h.JSX.Element;
|
|
5
|
-
}
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
export declare function Carousel(props: any): h.JSX.Element;
|
|
3
|
+
export declare namespace Carousel {
|
|
4
|
+
var Item: (props: any) => h.JSX.Element;
|
|
5
|
+
}
|
|
@@ -1,219 +1,219 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
|
-
import { h } from 'preact';
|
|
22
|
-
import { useState, useEffect, useRef, useMemo, useImperativeHandle } from '../../../../../lib/preact/hooks/src';
|
|
23
|
-
// import React, { useState, useEffect, useRef, useMemo } from 'preact/hooks';
|
|
24
|
-
var indicatorStyle = { width: '20px', height: '8px', margin: '5px', backgroundColor: '#cecfda', borderRadius: '3px' };
|
|
25
|
-
var indicatorSelectedStyle = __assign(__assign({}, indicatorStyle), { backgroundColor: '#fafbfc' });
|
|
26
|
-
export function Carousel(props) {
|
|
27
|
-
var _a = props.children, children = _a === void 0 ? [] : _a, _b = props.defaultIndex, defaultIndex = _b === void 0 ? 1 : _b, _c = props.compWidth, compWidth = _c === void 0 ? 100 : _c, _d = props.compHeight, compHeight = _d === void 0 ? 100 : _d, _e = props.autoplay, autoplay = _e === void 0 ? true : _e, _f = props.switchDuration, switchDuration = _f === void 0 ? 3000 : _f, _g = props.loop, loop = _g === void 0 ? true : _g, _h = props.isVertical, isVertical = _h === void 0 ? false : _h, _j = props.touchable, touchable = _j === void 0 ? true : _j, _k = props.onSlideChange, onSlideChange = _k === void 0 ? null : _k, _l = props.onclickEvent, onclickEvent = _l === void 0 ? null : _l;
|
|
28
|
-
useImperativeHandle(props.cRef, function () { return ({
|
|
29
|
-
handleNext: handleNext,
|
|
30
|
-
handlePrev: handlePrev
|
|
31
|
-
}); });
|
|
32
|
-
var duration = switchDuration < 1000 ? 1000 : switchDuration;
|
|
33
|
-
var _m = useState(defaultIndex), showIndex = _m[0], setShowIndex = _m[1];
|
|
34
|
-
//轮播元素正在滚动
|
|
35
|
-
var isMoving = useRef(false);
|
|
36
|
-
//鼠标手势信息
|
|
37
|
-
var isMouseDown = useRef(false);
|
|
38
|
-
var mouseDownX = useRef(0);
|
|
39
|
-
var mouseDownY = useRef(0);
|
|
40
|
-
var handleNextRef = useRef(function () { });
|
|
41
|
-
var nextInterval = useRef();
|
|
42
|
-
var _o = useState(true), showTransition = _o[0], setShowTransition = _o[1];
|
|
43
|
-
var _p = useState([0, 0]), gesteroffset = _p[0], setGesteroffset = _p[1];
|
|
44
|
-
var _q = useState(''), logTex = _q[0], setLogTex = _q[1];
|
|
45
|
-
var offset = useMemo(function () { return -(isVertical ? compHeight : compWidth) * showIndex; }, [showIndex]);
|
|
46
|
-
var itemBoxStyle = { minWidth: compWidth + 'px', minHeight: compHeight + 'px', maxWidth: compWidth + 'px', maxHeight: compHeight + 'px', };
|
|
47
|
-
var carouselItems = useMemo(function () {
|
|
48
|
-
var firstChild = children[0];
|
|
49
|
-
var lastChild = children[children.length - 1];
|
|
50
|
-
return __spreadArray(__spreadArray([lastChild], children, true), [firstChild], false);
|
|
51
|
-
}, [children]);
|
|
52
|
-
var isLastCarouseItem = function () { return showIndex === carouselItems.length - 1; };
|
|
53
|
-
var isFirstCarouseLastItem = function () { return showIndex === 0; };
|
|
54
|
-
useEffect(function () {
|
|
55
|
-
setNextInterval();
|
|
56
|
-
}, [autoplay]);
|
|
57
|
-
useEffect(function () {
|
|
58
|
-
//每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
|
|
59
|
-
if (!isLastCarouseItem() && !isFirstCarouseLastItem()) {
|
|
60
|
-
setShowTransition(true);
|
|
61
|
-
}
|
|
62
|
-
}, [showIndex]);
|
|
63
|
-
//更新handleNext的环境
|
|
64
|
-
useEffect(function () {
|
|
65
|
-
handleNextRef.current = handleNext;
|
|
66
|
-
});
|
|
67
|
-
var setNextInterval = function () {
|
|
68
|
-
clearInterval(nextInterval.current);
|
|
69
|
-
if (autoplay) {
|
|
70
|
-
nextInterval.current = setInterval(function () {
|
|
71
|
-
handleNextRef.current();
|
|
72
|
-
}, duration);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
useEffect(function () {
|
|
76
|
-
setNextInterval();
|
|
77
|
-
}, []);
|
|
78
|
-
var handlePrev = function () {
|
|
79
|
-
if (isMoving.current)
|
|
80
|
-
return;
|
|
81
|
-
isMoving.current = true;
|
|
82
|
-
if (showIndex === 0) {
|
|
83
|
-
setShowIndex(carouselItems.length - 1);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
setShowIndex(showIndex - 1);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
var handleNext = function () {
|
|
90
|
-
// console.log('nex', isMoving.current, showIndex, isVertical ? `translate(0px, ${offset}px)` : `translate(${offset}px, 0px)`)
|
|
91
|
-
if (!loop && showIndex == carouselItems.length - 2)
|
|
92
|
-
return;
|
|
93
|
-
if (isMoving.current)
|
|
94
|
-
return;
|
|
95
|
-
isMoving.current = true;
|
|
96
|
-
setShowIndex(showIndex + 1);
|
|
97
|
-
};
|
|
98
|
-
var handleTransitionEnd = function () {
|
|
99
|
-
//判断前后补位元素准备跳转
|
|
100
|
-
//在动画结束以后关掉,否则用鼠标拖动的时候不能补充剩下的offset
|
|
101
|
-
if (isLastCarouseItem() || isFirstCarouseLastItem()) {
|
|
102
|
-
setShowTransition(false);
|
|
103
|
-
}
|
|
104
|
-
// console.log('showIndex' + showIndex)
|
|
105
|
-
isMoving.current = false;
|
|
106
|
-
//触发onSlideChange
|
|
107
|
-
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange)
|
|
108
|
-
onSlideChange(showIndex - 1);
|
|
109
|
-
// 处理首尾特殊case
|
|
110
|
-
if (isLastCarouseItem()) {
|
|
111
|
-
setShowIndex(1);
|
|
112
|
-
}
|
|
113
|
-
if (isFirstCarouseLastItem()) {
|
|
114
|
-
setShowIndex(carouselItems.length - 2);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
var gestureUp = function () {
|
|
118
|
-
// setLogTex(logTex + 'UP ');
|
|
119
|
-
if (!touchable)
|
|
120
|
-
return;
|
|
121
|
-
if (isMoving.current)
|
|
122
|
-
return;
|
|
123
|
-
//打开动画
|
|
124
|
-
setShowTransition(true);
|
|
125
|
-
isMouseDown.current = false;
|
|
126
|
-
//拖动大于1/3的时候跳转
|
|
127
|
-
if (isVertical) {
|
|
128
|
-
if (gesteroffset[1] > compHeight / 3) {
|
|
129
|
-
handlePrev();
|
|
130
|
-
}
|
|
131
|
-
else if (gesteroffset[1] < -compHeight / 3) {
|
|
132
|
-
handleNext();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
if (gesteroffset[0] > compWidth / 3) {
|
|
137
|
-
handlePrev();
|
|
138
|
-
}
|
|
139
|
-
else if (gesteroffset[0] < -compWidth / 3) {
|
|
140
|
-
handleNext();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
setGesteroffset([0, 0]);
|
|
144
|
-
setNextInterval();
|
|
145
|
-
};
|
|
146
|
-
var gestureMove = function (e) {
|
|
147
|
-
if (!touchable)
|
|
148
|
-
return;
|
|
149
|
-
if (!isMouseDown.current)
|
|
150
|
-
return;
|
|
151
|
-
var l = e.target.getBoundingClientRect().left;
|
|
152
|
-
var r = e.target.getBoundingClientRect().right;
|
|
153
|
-
var t = e.target.getBoundingClientRect().top;
|
|
154
|
-
var b = e.target.getBoundingClientRect().bottom;
|
|
155
|
-
var x = e.clientX;
|
|
156
|
-
var y = e.clientY;
|
|
157
|
-
setGesteroffset([e.clientX - mouseDownX.current, e.clientY - mouseDownY.current]);
|
|
158
|
-
//计算滑动超出元素范围
|
|
159
|
-
if (x < l || x > r || y > b || y < t) {
|
|
160
|
-
gestureUp();
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
var gestureDown = function (e) {
|
|
164
|
-
if (!touchable)
|
|
165
|
-
return;
|
|
166
|
-
if (isMoving.current)
|
|
167
|
-
return;
|
|
168
|
-
if (nextInterval.current) {
|
|
169
|
-
clearInterval(nextInterval.current);
|
|
170
|
-
nextInterval.current = null;
|
|
171
|
-
}
|
|
172
|
-
mouseDownX.current = e.clientX;
|
|
173
|
-
mouseDownY.current = e.clientY;
|
|
174
|
-
isMouseDown.current = true;
|
|
175
|
-
//拖动时关闭动画
|
|
176
|
-
setShowTransition(false);
|
|
177
|
-
};
|
|
178
|
-
var gestureClick = function (props) {
|
|
179
|
-
if (isMoving.current)
|
|
180
|
-
return;
|
|
181
|
-
if (onclickEvent) {
|
|
182
|
-
onclickEvent(showIndex - 1);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
return (h("div", { style: { flexDirection: 'column'
|
|
186
|
-
h("div", { style: __assign(__assign({ position: 'relative' }, itemBoxStyle), { overflow: 'hidden', flexShrink: 0 }) },
|
|
187
|
-
h("div", { style: {
|
|
188
|
-
display: 'flex',
|
|
189
|
-
width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
|
|
190
|
-
height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
|
|
191
|
-
transition: "transform ".concat(showTransition ? '0.5s' : '0s', " ease 0s"),
|
|
192
|
-
transform: isVertical ? "translate(0px, ".concat(offset + gesteroffset[1], "px)") : "translate(".concat(offset + gesteroffset[0], "px, 0px)"),
|
|
193
|
-
flexDirection: isVertical ? 'column' : 'row',
|
|
194
|
-
flexShrink: 0,
|
|
195
|
-
}, class: 'wrapper', onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))),
|
|
196
|
-
h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function () { gestureClick(props); }, class: 'GestureComp',
|
|
197
|
-
// onMouseUp={() => { gestureUp(); }}
|
|
198
|
-
// onMouseMove={(e) => { gestureMove(e); }}
|
|
199
|
-
// onMouseDown={gestureDown}
|
|
200
|
-
onDragStart: gestureDown,
|
|
201
|
-
// onMouseOut={() => { gestureUp(); }}
|
|
202
|
-
// onTouchEnd={() => { gestureUp(); }}
|
|
203
|
-
onDrag: function (e) {
|
|
204
|
-
gestureMove(e);
|
|
205
|
-
// setLogTex(logTex + ((e.target as any).className == 'GestureComp' ? '' : '111'));
|
|
206
|
-
}, onDragEnd: function () { gestureUp(); } }),
|
|
207
|
-
h("div", { style: { flexDirection: isVertical ? 'column' : 'row', } }, children.map(function (v, i) {
|
|
208
|
-
return h("div", { style: (showIndex == i + 1) ? indicatorSelectedStyle : indicatorStyle, onClick: function () { setShowIndex(i + 1); } });
|
|
209
|
-
}))));
|
|
210
|
-
}
|
|
211
|
-
Carousel.Item = function (props) {
|
|
212
|
-
return h("div", { style: {
|
|
213
|
-
// width: '100%',
|
|
214
|
-
// height: '100%',
|
|
215
|
-
// flexShrink: 0,
|
|
216
|
-
} },
|
|
217
|
-
" ",
|
|
218
|
-
props.children);
|
|
219
|
-
};
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { h } from 'preact';
|
|
22
|
+
import { useState, useEffect, useRef, useMemo, useImperativeHandle } from '../../../../../lib/preact/hooks/src';
|
|
23
|
+
// import React, { useState, useEffect, useRef, useMemo } from 'preact/hooks';
|
|
24
|
+
var indicatorStyle = { width: '20px', height: '8px', margin: '5px', backgroundColor: '#cecfda', borderRadius: '3px' };
|
|
25
|
+
var indicatorSelectedStyle = __assign(__assign({}, indicatorStyle), { backgroundColor: '#fafbfc' });
|
|
26
|
+
export function Carousel(props) {
|
|
27
|
+
var _a = props.children, children = _a === void 0 ? [] : _a, _b = props.defaultIndex, defaultIndex = _b === void 0 ? 1 : _b, _c = props.compWidth, compWidth = _c === void 0 ? 100 : _c, _d = props.compHeight, compHeight = _d === void 0 ? 100 : _d, _e = props.autoplay, autoplay = _e === void 0 ? true : _e, _f = props.switchDuration, switchDuration = _f === void 0 ? 3000 : _f, _g = props.loop, loop = _g === void 0 ? true : _g, _h = props.isVertical, isVertical = _h === void 0 ? false : _h, _j = props.touchable, touchable = _j === void 0 ? true : _j, _k = props.onSlideChange, onSlideChange = _k === void 0 ? null : _k, _l = props.onclickEvent, onclickEvent = _l === void 0 ? null : _l;
|
|
28
|
+
useImperativeHandle(props.cRef, function () { return ({
|
|
29
|
+
handleNext: handleNext,
|
|
30
|
+
handlePrev: handlePrev
|
|
31
|
+
}); });
|
|
32
|
+
var duration = switchDuration < 1000 ? 1000 : switchDuration;
|
|
33
|
+
var _m = useState(defaultIndex), showIndex = _m[0], setShowIndex = _m[1];
|
|
34
|
+
//轮播元素正在滚动
|
|
35
|
+
var isMoving = useRef(false);
|
|
36
|
+
//鼠标手势信息
|
|
37
|
+
var isMouseDown = useRef(false);
|
|
38
|
+
var mouseDownX = useRef(0);
|
|
39
|
+
var mouseDownY = useRef(0);
|
|
40
|
+
var handleNextRef = useRef(function () { });
|
|
41
|
+
var nextInterval = useRef();
|
|
42
|
+
var _o = useState(true), showTransition = _o[0], setShowTransition = _o[1];
|
|
43
|
+
var _p = useState([0, 0]), gesteroffset = _p[0], setGesteroffset = _p[1];
|
|
44
|
+
var _q = useState(''), logTex = _q[0], setLogTex = _q[1];
|
|
45
|
+
var offset = useMemo(function () { return -(isVertical ? compHeight : compWidth) * showIndex; }, [showIndex]);
|
|
46
|
+
var itemBoxStyle = { minWidth: compWidth + 'px', minHeight: compHeight + 'px', maxWidth: compWidth + 'px', maxHeight: compHeight + 'px', };
|
|
47
|
+
var carouselItems = useMemo(function () {
|
|
48
|
+
var firstChild = children[0];
|
|
49
|
+
var lastChild = children[children.length - 1];
|
|
50
|
+
return __spreadArray(__spreadArray([lastChild], children, true), [firstChild], false);
|
|
51
|
+
}, [children]);
|
|
52
|
+
var isLastCarouseItem = function () { return showIndex === carouselItems.length - 1; };
|
|
53
|
+
var isFirstCarouseLastItem = function () { return showIndex === 0; };
|
|
54
|
+
useEffect(function () {
|
|
55
|
+
setNextInterval();
|
|
56
|
+
}, [autoplay]);
|
|
57
|
+
useEffect(function () {
|
|
58
|
+
//每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
|
|
59
|
+
if (!isLastCarouseItem() && !isFirstCarouseLastItem()) {
|
|
60
|
+
setShowTransition(true);
|
|
61
|
+
}
|
|
62
|
+
}, [showIndex]);
|
|
63
|
+
//更新handleNext的环境
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
handleNextRef.current = handleNext;
|
|
66
|
+
});
|
|
67
|
+
var setNextInterval = function () {
|
|
68
|
+
clearInterval(nextInterval.current);
|
|
69
|
+
if (autoplay) {
|
|
70
|
+
nextInterval.current = setInterval(function () {
|
|
71
|
+
handleNextRef.current();
|
|
72
|
+
}, duration);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
useEffect(function () {
|
|
76
|
+
setNextInterval();
|
|
77
|
+
}, []);
|
|
78
|
+
var handlePrev = function () {
|
|
79
|
+
if (isMoving.current)
|
|
80
|
+
return;
|
|
81
|
+
isMoving.current = true;
|
|
82
|
+
if (showIndex === 0) {
|
|
83
|
+
setShowIndex(carouselItems.length - 1);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
setShowIndex(showIndex - 1);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var handleNext = function () {
|
|
90
|
+
// console.log('nex', isMoving.current, showIndex, isVertical ? `translate(0px, ${offset}px)` : `translate(${offset}px, 0px)`)
|
|
91
|
+
if (!loop && showIndex == carouselItems.length - 2)
|
|
92
|
+
return;
|
|
93
|
+
if (isMoving.current)
|
|
94
|
+
return;
|
|
95
|
+
isMoving.current = true;
|
|
96
|
+
setShowIndex(showIndex + 1);
|
|
97
|
+
};
|
|
98
|
+
var handleTransitionEnd = function () {
|
|
99
|
+
//判断前后补位元素准备跳转
|
|
100
|
+
//在动画结束以后关掉,否则用鼠标拖动的时候不能补充剩下的offset
|
|
101
|
+
if (isLastCarouseItem() || isFirstCarouseLastItem()) {
|
|
102
|
+
setShowTransition(false);
|
|
103
|
+
}
|
|
104
|
+
// console.log('showIndex' + showIndex)
|
|
105
|
+
isMoving.current = false;
|
|
106
|
+
//触发onSlideChange
|
|
107
|
+
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange)
|
|
108
|
+
onSlideChange(showIndex - 1);
|
|
109
|
+
// 处理首尾特殊case
|
|
110
|
+
if (isLastCarouseItem()) {
|
|
111
|
+
setShowIndex(1);
|
|
112
|
+
}
|
|
113
|
+
if (isFirstCarouseLastItem()) {
|
|
114
|
+
setShowIndex(carouselItems.length - 2);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var gestureUp = function () {
|
|
118
|
+
// setLogTex(logTex + 'UP ');
|
|
119
|
+
if (!touchable)
|
|
120
|
+
return;
|
|
121
|
+
if (isMoving.current)
|
|
122
|
+
return;
|
|
123
|
+
//打开动画
|
|
124
|
+
setShowTransition(true);
|
|
125
|
+
isMouseDown.current = false;
|
|
126
|
+
//拖动大于1/3的时候跳转
|
|
127
|
+
if (isVertical) {
|
|
128
|
+
if (gesteroffset[1] > compHeight / 3) {
|
|
129
|
+
handlePrev();
|
|
130
|
+
}
|
|
131
|
+
else if (gesteroffset[1] < -compHeight / 3) {
|
|
132
|
+
handleNext();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
if (gesteroffset[0] > compWidth / 3) {
|
|
137
|
+
handlePrev();
|
|
138
|
+
}
|
|
139
|
+
else if (gesteroffset[0] < -compWidth / 3) {
|
|
140
|
+
handleNext();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
setGesteroffset([0, 0]);
|
|
144
|
+
setNextInterval();
|
|
145
|
+
};
|
|
146
|
+
var gestureMove = function (e) {
|
|
147
|
+
if (!touchable)
|
|
148
|
+
return;
|
|
149
|
+
if (!isMouseDown.current)
|
|
150
|
+
return;
|
|
151
|
+
var l = e.target.getBoundingClientRect().left;
|
|
152
|
+
var r = e.target.getBoundingClientRect().right;
|
|
153
|
+
var t = e.target.getBoundingClientRect().top;
|
|
154
|
+
var b = e.target.getBoundingClientRect().bottom;
|
|
155
|
+
var x = e.clientX;
|
|
156
|
+
var y = e.clientY;
|
|
157
|
+
setGesteroffset([e.clientX - mouseDownX.current, e.clientY - mouseDownY.current]);
|
|
158
|
+
//计算滑动超出元素范围
|
|
159
|
+
if (x < l || x > r || y > b || y < t) {
|
|
160
|
+
gestureUp();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var gestureDown = function (e) {
|
|
164
|
+
if (!touchable)
|
|
165
|
+
return;
|
|
166
|
+
if (isMoving.current)
|
|
167
|
+
return;
|
|
168
|
+
if (nextInterval.current) {
|
|
169
|
+
clearInterval(nextInterval.current);
|
|
170
|
+
nextInterval.current = null;
|
|
171
|
+
}
|
|
172
|
+
mouseDownX.current = e.clientX;
|
|
173
|
+
mouseDownY.current = e.clientY;
|
|
174
|
+
isMouseDown.current = true;
|
|
175
|
+
//拖动时关闭动画
|
|
176
|
+
setShowTransition(false);
|
|
177
|
+
};
|
|
178
|
+
var gestureClick = function (props) {
|
|
179
|
+
if (isMoving.current)
|
|
180
|
+
return;
|
|
181
|
+
if (onclickEvent) {
|
|
182
|
+
onclickEvent(showIndex - 1);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
return (h("div", { style: { flexDirection: 'column' } },
|
|
186
|
+
h("div", { style: __assign(__assign({ position: 'relative' }, itemBoxStyle), { overflow: 'hidden', flexShrink: 0 }) },
|
|
187
|
+
h("div", { style: {
|
|
188
|
+
display: 'flex',
|
|
189
|
+
width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
|
|
190
|
+
height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
|
|
191
|
+
transition: "transform ".concat(showTransition ? '0.5s' : '0s', " ease 0s"),
|
|
192
|
+
transform: isVertical ? "translate(0px, ".concat(offset + gesteroffset[1], "px)") : "translate(".concat(offset + gesteroffset[0], "px, 0px)"),
|
|
193
|
+
flexDirection: isVertical ? 'column' : 'row',
|
|
194
|
+
flexShrink: 0,
|
|
195
|
+
}, class: 'wrapper', onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))),
|
|
196
|
+
h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function () { gestureClick(props); }, class: 'GestureComp',
|
|
197
|
+
// onMouseUp={() => { gestureUp(); }}
|
|
198
|
+
// onMouseMove={(e) => { gestureMove(e); }}
|
|
199
|
+
// onMouseDown={gestureDown}
|
|
200
|
+
onDragStart: gestureDown,
|
|
201
|
+
// onMouseOut={() => { gestureUp(); }}
|
|
202
|
+
// onTouchEnd={() => { gestureUp(); }}
|
|
203
|
+
onDrag: function (e) {
|
|
204
|
+
gestureMove(e);
|
|
205
|
+
// setLogTex(logTex + ((e.target as any).className == 'GestureComp' ? '' : '111'));
|
|
206
|
+
}, onDragEnd: function () { gestureUp(); } }),
|
|
207
|
+
h("div", { style: { flexDirection: isVertical ? 'column' : 'row', } }, children.map(function (v, i) {
|
|
208
|
+
return h("div", { style: (showIndex == i + 1) ? indicatorSelectedStyle : indicatorStyle, onClick: function () { setShowIndex(i + 1); } });
|
|
209
|
+
}))));
|
|
210
|
+
}
|
|
211
|
+
Carousel.Item = function (props) {
|
|
212
|
+
return h("div", { style: {
|
|
213
|
+
// width: '100%',
|
|
214
|
+
// height: '100%',
|
|
215
|
+
// flexShrink: 0,
|
|
216
|
+
} },
|
|
217
|
+
" ",
|
|
218
|
+
props.children);
|
|
219
|
+
};
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { Component, CSSProperties, h } from 'preact';
|
|
2
|
-
import { DropdownOptionUI } from './DropdownOptionUI';
|
|
3
|
-
import { DropdownSpreadMainUI } from './DropdownSpreadMainUI';
|
|
4
|
-
import { DropdownUnspreadMainUI } from './DropdownUnspreadMainUI';
|
|
5
|
-
export interface DropdownConfig<T> {
|
|
6
|
-
spreadStyle: CSSProperties;
|
|
7
|
-
datas: T[];
|
|
8
|
-
}
|
|
9
|
-
export declare class Dropdown<T, DDUnspreadMainUI extends DropdownUnspreadMainUI<T>, DDSpreadMainUI extends DropdownSpreadMainUI<T>, DDOptionUI extends DropdownOptionUI<T>> extends Component<{
|
|
10
|
-
config: DropdownConfig<T>;
|
|
11
|
-
onChoose: Function;
|
|
12
|
-
defaultIndex: number | null;
|
|
13
|
-
unspreadMainUI: DDUnspreadMainUI;
|
|
14
|
-
spreadMainUI: DDSpreadMainUI;
|
|
15
|
-
optionsUI: DDOptionUI[];
|
|
16
|
-
}, {
|
|
17
|
-
selectedIndex: number;
|
|
18
|
-
isSpread: boolean;
|
|
19
|
-
}> {
|
|
20
|
-
constructor(props: any);
|
|
21
|
-
componentWillUnmount(): void;
|
|
22
|
-
addNetEvents: () => void;
|
|
23
|
-
removeNetEvents: () => void;
|
|
24
|
-
addLogicEvents: () => void;
|
|
25
|
-
removeLogicEvents: () => void;
|
|
26
|
-
openList: () => void;
|
|
27
|
-
closeList: () => void;
|
|
28
|
-
onChoose: (index: number) => void;
|
|
29
|
-
render(): h.JSX.Element;
|
|
30
|
-
}
|
|
1
|
+
import { Component, CSSProperties, h } from 'preact';
|
|
2
|
+
import { DropdownOptionUI } from './DropdownOptionUI';
|
|
3
|
+
import { DropdownSpreadMainUI } from './DropdownSpreadMainUI';
|
|
4
|
+
import { DropdownUnspreadMainUI } from './DropdownUnspreadMainUI';
|
|
5
|
+
export interface DropdownConfig<T> {
|
|
6
|
+
spreadStyle: CSSProperties;
|
|
7
|
+
datas: T[];
|
|
8
|
+
}
|
|
9
|
+
export declare class Dropdown<T, DDUnspreadMainUI extends DropdownUnspreadMainUI<T>, DDSpreadMainUI extends DropdownSpreadMainUI<T>, DDOptionUI extends DropdownOptionUI<T>> extends Component<{
|
|
10
|
+
config: DropdownConfig<T>;
|
|
11
|
+
onChoose: Function;
|
|
12
|
+
defaultIndex: number | null;
|
|
13
|
+
unspreadMainUI: DDUnspreadMainUI;
|
|
14
|
+
spreadMainUI: DDSpreadMainUI;
|
|
15
|
+
optionsUI: DDOptionUI[];
|
|
16
|
+
}, {
|
|
17
|
+
selectedIndex: number;
|
|
18
|
+
isSpread: boolean;
|
|
19
|
+
}> {
|
|
20
|
+
constructor(props: any);
|
|
21
|
+
componentWillUnmount(): void;
|
|
22
|
+
addNetEvents: () => void;
|
|
23
|
+
removeNetEvents: () => void;
|
|
24
|
+
addLogicEvents: () => void;
|
|
25
|
+
removeLogicEvents: () => void;
|
|
26
|
+
openList: () => void;
|
|
27
|
+
closeList: () => void;
|
|
28
|
+
onChoose: (index: number) => void;
|
|
29
|
+
render(): h.JSX.Element;
|
|
30
|
+
}
|