pixuireactcomponents 1.4.6 → 1.4.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.
package/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { DropDown } from "./src/components/react/app/dropDown/DropDown";
5
5
  export { ImageViewer } from "./src/components/react/app/imageViewer/imageViewer";
6
6
  export { ToggleGroup } from "./src/components/react/app/togglegroup/ToggleGroup";
7
7
  export { VideoPlayer } from "./src/components/react/app/videoPlayer/VideoPlayer";
8
+ export { WheelPicker } from "./src/components/react/app/wheelPicker/WheelPicker";
8
9
  export { GradientText } from "./src/components/react/base/gradient/GradientText";
9
10
  export { PVideo } from "./src/components/react/base/pixVideo/PixVideo";
10
11
  export { OutlineText } from "./src/components/react/base/outlinetext/OutlineText";
package/index.js CHANGED
@@ -7,6 +7,7 @@ export { ImageViewer } from './src/components/react/app/imageViewer/imageViewer'
7
7
  export { Slider } from './src/components/react/app/slider/Slider';
8
8
  export { ToggleGroup } from './src/components/react/app/togglegroup/ToggleGroup';
9
9
  export { VideoPlayer } from './src/components/react/app/videoPlayer/VideoPlayer';
10
+ export { WheelPicker } from './src/components/react/app/wheelPicker/WheelPicker';
10
11
  export { GradientText } from './src/components/react/base/gradient/GradientText';
11
12
  export { PVideo } from './src/components/react/base/pixVideo/PixVideo';
12
13
  export { OutlineText } from './src/components/react/base/outlinetext/OutlineText';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,4 +4,7 @@ export declare const LoadChecker: (props: {
4
4
  rootClass?: string | undefined;
5
5
  timeoutPeriod?: number | undefined;
6
6
  onLoad?: Function | undefined;
7
+ enableCompLog?: boolean | undefined;
8
+ onlyHttp?: boolean | undefined;
9
+ tag?: string | undefined;
7
10
  }) => h.JSX.Element;
@@ -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 _c = useState(false), loaded = _c[0], setLoaded = _c[1];
15
- var _d = useState(false), collectFinish = _d[0], setCollectFinish = _d[1];
16
- var _e = useState([]), loadedElements = _e[0], setLoadedElements = _e[1];
17
- var _f = useState([]), collectSrcs = _f[0], setCollectSrcs = _f[1];
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, _e = props.tag, tag = _e === void 0 ? '' : _e;
14
+ var _f = useState(false), loaded = _f[0], setLoaded = _f[1];
15
+ var _g = useState(false), collectFinish = _g[0], setCollectFinish = _g[1];
16
+ var _h = useState([]), loadedElements = _h[0], setLoadedElements = _h[1];
17
+ var _j = useState([]), collectSrcs = _j[0], setCollectSrcs = _j[1];
18
+ var _k = useState(new Date().getTime()), timeStamp = _k[0], setTimeStamp = _k[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 [".concat(tag, "]: ")], 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://') && src.substring(7).includes(':')))) {
88
+ return '';
89
+ }
71
90
  return src;
72
91
  }
73
92
  return '';
@@ -0,0 +1,15 @@
1
+ import { CSSProperties, h } from 'preact';
2
+ export interface WheelPickerProps {
3
+ wrapperStyle: CSSProperties;
4
+ items: string[];
5
+ visibleAbove?: number;
6
+ visibleBelow?: number;
7
+ itemTextStyle: CSSProperties;
8
+ selectedTextStyle?: CSSProperties;
9
+ AboveMaskAreaStyle?: CSSProperties;
10
+ BelowMaskAreaStyle?: CSSProperties;
11
+ selectedAreaStyle?: CSSProperties;
12
+ firstSelectIndex?: number;
13
+ onChange?: (index: number) => void;
14
+ }
15
+ export declare const WheelPicker: (props: WheelPickerProps) => h.JSX.Element;
@@ -0,0 +1,147 @@
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
+ import { h } from 'preact';
13
+ import { useEffect, useRef, useState } from 'preact/hooks';
14
+ var defaulWrapperStyle = {
15
+ display: 'flex',
16
+ justifyContent: 'center',
17
+ alignItems: 'center'
18
+ };
19
+ var defaultItemTextStyle = {
20
+ fontFamily: 'Font_FounderZZ',
21
+ fontStyle: 'normal',
22
+ fontSize: '24px',
23
+ lineHeight: '32px',
24
+ display: 'flex',
25
+ alignItems: 'center',
26
+ textAlign: 'center',
27
+ color: '#000000'
28
+ };
29
+ var defaultSelectedTextStyle = {
30
+ fontFamily: 'Font_FounderZZ',
31
+ fontStyle: 'normal',
32
+ fontSize: '24px',
33
+ lineHeight: '32px',
34
+ display: 'flex',
35
+ alignItems: 'center',
36
+ textAlign: 'center',
37
+ color: '#F0E6D2',
38
+ };
39
+ var defaultScrollStyle = {
40
+ width: '100%',
41
+ height: '100%',
42
+ overflow: 'scroll',
43
+ display: 'flex',
44
+ flexDirection: 'column',
45
+ justifyContent: 'start',
46
+ alignItems: 'center',
47
+ overflowStyle: 'none',
48
+ };
49
+ var defaultMaskAreaStyle = {
50
+ position: 'absolute',
51
+ pointerEvents: 'none'
52
+ };
53
+ var defaultItemStyle = {
54
+ display: 'flex',
55
+ justifyContent: 'center',
56
+ alignItems: 'center',
57
+ width: '100%'
58
+ };
59
+ export var WheelPicker = function (props) {
60
+ var wrapperStyle = props.wrapperStyle, items = props.items, _a = props.visibleAbove, visibleAbove = _a === void 0 ? 1 : _a, _b = props.visibleBelow, visibleBelow = _b === void 0 ? 1 : _b, itemTextStyle = props.itemTextStyle, selectedTextStyle = props.selectedTextStyle, _c = props.firstSelectIndex, firstSelectIndex = _c === void 0 ? 0 : _c, AboveMaskAreaStyle = props.AboveMaskAreaStyle, BelowMaskAreaStyle = props.BelowMaskAreaStyle, selectedAreaStyle = props.selectedAreaStyle, onChange = props.onChange;
61
+ var scrollRef = useRef(null);
62
+ var _d = useState(0), itemHeight = _d[0], setItemHeight = _d[1];
63
+ var _e = useState([]), itemList = _e[0], setItemList = _e[1];
64
+ var _f = useState(false), isDraging = _f[0], setIsDraging = _f[1];
65
+ var _g = useState(0), selectIndex = _g[0], setSelectIndex = _g[1];
66
+ var scrollTimmer = useRef(null);
67
+ useEffect(function () {
68
+ var calcuItemHeight = parseInt(wrapperStyle.height) / (visibleAbove + visibleBelow + 1);
69
+ setItemHeight(calcuItemHeight);
70
+ setSelectIndex(firstSelectIndex + visibleAbove);
71
+ setItemList(fillBlankItems());
72
+ var timer = setTimeout(function () {
73
+ if (scrollRef.current) {
74
+ scrollRef.current.scrollTop = firstSelectIndex * calcuItemHeight;
75
+ }
76
+ }, 0);
77
+ return function () { return clearTimeout(timer); };
78
+ }, []);
79
+ useEffect(function () {
80
+ if (onChange) {
81
+ onChange(selectIndex - visibleAbove);
82
+ }
83
+ }, [selectIndex]);
84
+ var fillBlankItems = function () {
85
+ var startPadding = new Array(visibleAbove).fill('');
86
+ var endPadding = new Array(visibleBelow).fill('');
87
+ return startPadding.concat(items, endPadding);
88
+ };
89
+ var onScroll = function (e) {
90
+ // console.log('onScroll: ', scrollRef.current.scrollTop)
91
+ if (scrollTimmer.current) {
92
+ clearTimeout(scrollTimmer.current);
93
+ scrollTimmer.current = null;
94
+ }
95
+ scrollTimmer.current = window.setTimeout(function () {
96
+ var finalPos = (selectIndex - visibleAbove) * itemHeight;
97
+ if (!isDraging && scrollRef.current.scrollTop < finalPos - 1 || scrollRef.current.scrollTop > finalPos + 1) {
98
+ animateScroll(scrollRef.current.scrollTop, finalPos, performance.now(), 100);
99
+ }
100
+ if (scrollTimmer.current) {
101
+ clearTimeout(scrollTimmer.current);
102
+ scrollTimmer.current = null;
103
+ }
104
+ }, 50);
105
+ var nowSelectIndex = Math.round((scrollRef.current.scrollTop + visibleAbove * itemHeight) / itemHeight);
106
+ if (selectIndex !== nowSelectIndex) {
107
+ setSelectIndex(nowSelectIndex);
108
+ }
109
+ };
110
+ var animateScroll = function (currentPos, targetPos, startTime, duration) {
111
+ var step = function () {
112
+ var currentTime = performance.now();
113
+ var time = Math.min(1, (currentTime - startTime) / duration);
114
+ var timeFunction = time * (2 - time);
115
+ var newPos = currentPos + (targetPos - currentPos) * timeFunction;
116
+ scrollRef.current.scrollTop = newPos;
117
+ if (time < 1 && !isDraging) {
118
+ requestAnimationFrame(step);
119
+ }
120
+ };
121
+ requestAnimationFrame(step);
122
+ };
123
+ var onMouseEvent = function (isDraging) {
124
+ if (isDraging) {
125
+ setIsDraging(true);
126
+ }
127
+ else {
128
+ setIsDraging(false);
129
+ if (!scrollTimmer.current) {
130
+ var finalPos = (selectIndex - visibleAbove) * itemHeight;
131
+ animateScroll(scrollRef.current.scrollTop, finalPos, performance.now(), 100);
132
+ var nowSelectIndex = Math.round((scrollRef.current.scrollTop + visibleAbove * itemHeight) / itemHeight);
133
+ if (selectIndex !== nowSelectIndex) {
134
+ setSelectIndex(nowSelectIndex);
135
+ }
136
+ }
137
+ }
138
+ };
139
+ return (h("div", { style: __assign(__assign({}, wrapperStyle), defaulWrapperStyle) },
140
+ h("div", { style: __assign({}, defaultScrollStyle),
141
+ // movement-type={'clamped'}
142
+ ref: scrollRef, onScroll: function (e) { onScroll(e); }, onMouseDown: function () { onMouseEvent(true); }, onMouseUp: function () { onMouseEvent(false); } }, itemList.map(function (item, index) { return (h("div", { style: __assign(__assign({}, defaultItemStyle), { minHeight: "".concat(itemHeight, "px") }) },
143
+ h("text", { style: selectedTextStyle ? (index === selectIndex ? selectedTextStyle : itemTextStyle) : itemTextStyle }, item))); })),
144
+ selectedAreaStyle && h("div", { style: __assign(__assign(__assign({}, selectedAreaStyle), defaultMaskAreaStyle), { height: "".concat(itemHeight, "px"), top: "".concat(itemHeight * visibleAbove, "px") }) }),
145
+ AboveMaskAreaStyle && h("div", { style: __assign(__assign(__assign({}, AboveMaskAreaStyle), defaultMaskAreaStyle), { height: "".concat(itemHeight * visibleAbove, "px"), top: '0px' }) }),
146
+ BelowMaskAreaStyle && h("div", { style: __assign(__assign(__assign({}, BelowMaskAreaStyle), defaultMaskAreaStyle), { height: "".concat(itemHeight * visibleBelow, "px"), top: "".concat(itemHeight * (visibleAbove + 1), "px") }) })));
147
+ };