@kolserdav/swiper 2.1.0-beta → 2.2.0-alfa
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/dist/index.js +126 -46
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +128 -48
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -1
package/dist/index.modern.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React, { useState, useRef, useMemo, useEffect, createRef } from 'react';
|
|
2
|
-
import { IconButton } from '@mui/material';
|
|
1
|
+
import React, { useState, useRef, useMemo, useEffect, Fragment, createRef } from 'react';
|
|
2
|
+
import { Paper, IconButton } from '@mui/material';
|
|
3
|
+
import { makeStyles } from '@mui/styles';
|
|
3
4
|
import clsx from 'clsx';
|
|
4
5
|
import StopIcon from '@mui/icons-material/StopScreenShare';
|
|
5
6
|
import NavigateNextIcon from '@mui/icons-material/NavigateNext';
|
|
@@ -197,8 +198,64 @@ function _switch(discriminant, cases) {
|
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
|
|
200
|
-
var
|
|
201
|
-
|
|
201
|
+
var useStyles = makeStyles(function () {
|
|
202
|
+
return {
|
|
203
|
+
go: {
|
|
204
|
+
transition: 'left 0.4s ease-out 0s'
|
|
205
|
+
},
|
|
206
|
+
back: {
|
|
207
|
+
transition: 'left 0.4s ease-in 0s'
|
|
208
|
+
},
|
|
209
|
+
container: {
|
|
210
|
+
position: 'relative',
|
|
211
|
+
overflow: 'hidden',
|
|
212
|
+
minWidth: '320px',
|
|
213
|
+
width: '100%',
|
|
214
|
+
height: '100%',
|
|
215
|
+
minHeight: '80vh',
|
|
216
|
+
maxWidth: '100vw',
|
|
217
|
+
display: 'flex',
|
|
218
|
+
alignItems: 'center',
|
|
219
|
+
justifyContent: 'center'
|
|
220
|
+
},
|
|
221
|
+
button: {
|
|
222
|
+
cursor: 'pointer',
|
|
223
|
+
position: 'absolute',
|
|
224
|
+
width: 'auto',
|
|
225
|
+
height: 'auto',
|
|
226
|
+
display: 'flex',
|
|
227
|
+
alignItems: 'center',
|
|
228
|
+
zIndex: '12'
|
|
229
|
+
},
|
|
230
|
+
button__prev: {
|
|
231
|
+
left: 0,
|
|
232
|
+
transform: 'rotate(180deg)'
|
|
233
|
+
},
|
|
234
|
+
button__next: {
|
|
235
|
+
right: 0
|
|
236
|
+
},
|
|
237
|
+
content: {
|
|
238
|
+
position: 'relative',
|
|
239
|
+
width: 'calc(100% - 48px)',
|
|
240
|
+
height: 'calc(100% - 48px)'
|
|
241
|
+
},
|
|
242
|
+
card: {
|
|
243
|
+
position: 'absolute',
|
|
244
|
+
maxWidth: 'inherit',
|
|
245
|
+
top: 0,
|
|
246
|
+
left: 0,
|
|
247
|
+
display: 'flex',
|
|
248
|
+
alignItems: 'center',
|
|
249
|
+
justifyContent: 'center'
|
|
250
|
+
},
|
|
251
|
+
card__prev: {
|
|
252
|
+
left: '-100%'
|
|
253
|
+
},
|
|
254
|
+
card__next: {
|
|
255
|
+
left: '100%'
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
});
|
|
202
259
|
var SWIPE_TRANSITION_TIMEOUT = 400;
|
|
203
260
|
|
|
204
261
|
var getSwipes = function getSwipes(prev, current, next, swipes) {
|
|
@@ -239,6 +296,18 @@ var Swiper = function Swiper(props) {
|
|
|
239
296
|
className = props.className,
|
|
240
297
|
invitationAnimation = props.invitationAnimation;
|
|
241
298
|
|
|
299
|
+
var _useStyles = useStyles(),
|
|
300
|
+
go = _useStyles.go,
|
|
301
|
+
card = _useStyles.card,
|
|
302
|
+
card__next = _useStyles.card__next,
|
|
303
|
+
card__prev = _useStyles.card__prev,
|
|
304
|
+
button = _useStyles.button,
|
|
305
|
+
button__next = _useStyles.button__next,
|
|
306
|
+
button__prev = _useStyles.button__prev,
|
|
307
|
+
back = _useStyles.back,
|
|
308
|
+
container = _useStyles.container,
|
|
309
|
+
content = _useStyles.content;
|
|
310
|
+
|
|
242
311
|
var _useState = useState(),
|
|
243
312
|
current = _useState[0],
|
|
244
313
|
setCurrent = _useState[1];
|
|
@@ -275,11 +344,11 @@ var Swiper = function Swiper(props) {
|
|
|
275
344
|
isMobile = _useState9[0],
|
|
276
345
|
setIsMobile = _useState9[1];
|
|
277
346
|
|
|
278
|
-
var
|
|
347
|
+
var _useState10 = useState(true),
|
|
348
|
+
load = _useState10[0],
|
|
349
|
+
setLoad = _useState10[1];
|
|
279
350
|
|
|
280
|
-
var
|
|
281
|
-
|
|
282
|
-
var _buttonNextRef = useRef(null);
|
|
351
|
+
var containerRef = useRef(null);
|
|
283
352
|
|
|
284
353
|
if (typeof _defaultCurrent === 'undefined') {
|
|
285
354
|
_defaultCurrent = defaultCurrent;
|
|
@@ -295,33 +364,33 @@ var Swiper = function Swiper(props) {
|
|
|
295
364
|
return refs[id];
|
|
296
365
|
};
|
|
297
366
|
|
|
298
|
-
var
|
|
367
|
+
var setGoClassHandler = function setGoClassHandler() {
|
|
299
368
|
var _getRef$current, _getRef$current2, _getRef$current3;
|
|
300
369
|
|
|
301
|
-
(_getRef$current = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current === void 0 ? void 0 : _getRef$current.classList.add(
|
|
302
|
-
(_getRef$current2 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current2 === void 0 ? void 0 : _getRef$current2.classList.add(
|
|
303
|
-
(_getRef$current3 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current3 === void 0 ? void 0 : _getRef$current3.classList.add(
|
|
370
|
+
(_getRef$current = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current === void 0 ? void 0 : _getRef$current.classList.add(go);
|
|
371
|
+
(_getRef$current2 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current2 === void 0 ? void 0 : _getRef$current2.classList.add(go);
|
|
372
|
+
(_getRef$current3 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current3 === void 0 ? void 0 : _getRef$current3.classList.add(go);
|
|
304
373
|
setTimeout(function () {
|
|
305
374
|
var _getRef$current4, _getRef$current5, _getRef$current6;
|
|
306
375
|
|
|
307
|
-
(_getRef$current4 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current4 === void 0 ? void 0 : _getRef$current4.classList.remove(
|
|
308
|
-
(_getRef$current5 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current5 === void 0 ? void 0 : _getRef$current5.classList.remove(
|
|
309
|
-
(_getRef$current6 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current6 === void 0 ? void 0 : _getRef$current6.classList.remove(
|
|
376
|
+
(_getRef$current4 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current4 === void 0 ? void 0 : _getRef$current4.classList.remove(go);
|
|
377
|
+
(_getRef$current5 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current5 === void 0 ? void 0 : _getRef$current5.classList.remove(go);
|
|
378
|
+
(_getRef$current6 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current6 === void 0 ? void 0 : _getRef$current6.classList.remove(go);
|
|
310
379
|
}, SWIPE_TRANSITION_TIMEOUT);
|
|
311
380
|
};
|
|
312
381
|
|
|
313
|
-
var
|
|
382
|
+
var setBackClassHandler = function setBackClassHandler() {
|
|
314
383
|
var _getRef$current7, _getRef$current8, _getRef$current9;
|
|
315
384
|
|
|
316
|
-
(_getRef$current7 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current7 === void 0 ? void 0 : _getRef$current7.classList.add(
|
|
317
|
-
(_getRef$current8 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current8 === void 0 ? void 0 : _getRef$current8.classList.add(
|
|
318
|
-
(_getRef$current9 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current9 === void 0 ? void 0 : _getRef$current9.classList.add(
|
|
385
|
+
(_getRef$current7 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current7 === void 0 ? void 0 : _getRef$current7.classList.add(back);
|
|
386
|
+
(_getRef$current8 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current8 === void 0 ? void 0 : _getRef$current8.classList.add(back);
|
|
387
|
+
(_getRef$current9 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current9 === void 0 ? void 0 : _getRef$current9.classList.add(back);
|
|
319
388
|
setTimeout(function () {
|
|
320
389
|
var _getRef$current10, _getRef$current11, _getRef$current12;
|
|
321
390
|
|
|
322
|
-
(_getRef$current10 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current10 === void 0 ? void 0 : _getRef$current10.classList.remove(
|
|
323
|
-
(_getRef$current11 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current11 === void 0 ? void 0 : _getRef$current11.classList.remove(
|
|
324
|
-
(_getRef$current12 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current12 === void 0 ? void 0 : _getRef$current12.classList.remove(
|
|
391
|
+
(_getRef$current10 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current10 === void 0 ? void 0 : _getRef$current10.classList.remove(back);
|
|
392
|
+
(_getRef$current11 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current11 === void 0 ? void 0 : _getRef$current11.classList.remove(back);
|
|
393
|
+
(_getRef$current12 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current12 === void 0 ? void 0 : _getRef$current12.classList.remove(back);
|
|
325
394
|
}, SWIPE_TRANSITION_TIMEOUT);
|
|
326
395
|
};
|
|
327
396
|
|
|
@@ -360,10 +429,12 @@ var Swiper = function Swiper(props) {
|
|
|
360
429
|
onSwipe(currentId);
|
|
361
430
|
}
|
|
362
431
|
|
|
432
|
+
setLoad(false);
|
|
363
433
|
return 0;
|
|
364
434
|
};
|
|
365
435
|
|
|
366
436
|
var _exit2 = false;
|
|
437
|
+
setLoad(true);
|
|
367
438
|
var startTime;
|
|
368
439
|
var currentId = 0;
|
|
369
440
|
|
|
@@ -382,13 +453,14 @@ var Swiper = function Swiper(props) {
|
|
|
382
453
|
};
|
|
383
454
|
|
|
384
455
|
if (!(next !== null && next !== void 0 && next.id)) {
|
|
385
|
-
|
|
456
|
+
setBackClassHandler();
|
|
386
457
|
setLeft(0);
|
|
458
|
+
setLoad(false);
|
|
387
459
|
_exit2 = true;
|
|
388
460
|
return 1;
|
|
389
461
|
}
|
|
390
462
|
|
|
391
|
-
|
|
463
|
+
setGoClassHandler();
|
|
392
464
|
setLeft(windowWidth * -1);
|
|
393
465
|
startTime = new Date().getTime();
|
|
394
466
|
|
|
@@ -422,13 +494,14 @@ var Swiper = function Swiper(props) {
|
|
|
422
494
|
};
|
|
423
495
|
|
|
424
496
|
if (!(prev !== null && prev !== void 0 && prev.id)) {
|
|
425
|
-
|
|
497
|
+
setBackClassHandler();
|
|
426
498
|
setLeft(0);
|
|
499
|
+
setLoad(false);
|
|
427
500
|
_exit2 = true;
|
|
428
501
|
return 1;
|
|
429
502
|
}
|
|
430
503
|
|
|
431
|
-
|
|
504
|
+
setGoClassHandler();
|
|
432
505
|
setLeft(windowWidth);
|
|
433
506
|
startTime = new Date().getTime();
|
|
434
507
|
|
|
@@ -453,8 +526,9 @@ var Swiper = function Swiper(props) {
|
|
|
453
526
|
}
|
|
454
527
|
}();
|
|
455
528
|
} else {
|
|
456
|
-
|
|
529
|
+
setBackClassHandler();
|
|
457
530
|
setLeft(0);
|
|
531
|
+
setLoad(false);
|
|
458
532
|
_exit2 = true;
|
|
459
533
|
return 1;
|
|
460
534
|
}
|
|
@@ -510,18 +584,23 @@ var Swiper = function Swiper(props) {
|
|
|
510
584
|
var isNext = origin === 'next';
|
|
511
585
|
return function () {
|
|
512
586
|
try {
|
|
587
|
+
if (load) {
|
|
588
|
+
return Promise.resolve(1);
|
|
589
|
+
}
|
|
590
|
+
|
|
513
591
|
var coeff = isNext ? -1 : 1;
|
|
514
592
|
var leftVal = width * coeff;
|
|
515
593
|
|
|
516
594
|
if (isNext) {
|
|
517
|
-
|
|
595
|
+
setGoClassHandler();
|
|
518
596
|
} else {
|
|
519
|
-
|
|
597
|
+
setBackClassHandler();
|
|
520
598
|
}
|
|
521
599
|
|
|
522
|
-
setLeft(leftVal);
|
|
523
600
|
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT / 2)).then(function () {
|
|
524
|
-
return Promise.resolve(swipe(leftVal)).then(function () {
|
|
601
|
+
return Promise.resolve(swipe(leftVal)).then(function () {
|
|
602
|
+
return 0;
|
|
603
|
+
});
|
|
525
604
|
});
|
|
526
605
|
} catch (e) {
|
|
527
606
|
return Promise.reject(e);
|
|
@@ -560,20 +639,21 @@ var Swiper = function Swiper(props) {
|
|
|
560
639
|
var infitationAnimationHandler = function infitationAnimationHandler(shift) {
|
|
561
640
|
try {
|
|
562
641
|
if (shift < 0) {
|
|
563
|
-
|
|
642
|
+
setGoClassHandler();
|
|
564
643
|
} else {
|
|
565
|
-
|
|
644
|
+
setBackClassHandler();
|
|
566
645
|
}
|
|
567
646
|
|
|
568
647
|
setLeft(shift);
|
|
569
648
|
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT)).then(function () {
|
|
570
649
|
if (shift < 0) {
|
|
571
|
-
|
|
650
|
+
setBackClassHandler();
|
|
572
651
|
} else {
|
|
573
|
-
|
|
652
|
+
setGoClassHandler();
|
|
574
653
|
}
|
|
575
654
|
|
|
576
655
|
setLeft(0);
|
|
656
|
+
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT)).then(function () {});
|
|
577
657
|
});
|
|
578
658
|
} catch (e) {
|
|
579
659
|
return Promise.reject(e);
|
|
@@ -611,12 +691,12 @@ var Swiper = function Swiper(props) {
|
|
|
611
691
|
setCurrent(defaultCurrent);
|
|
612
692
|
setPrev(_p);
|
|
613
693
|
setNext(_n);
|
|
614
|
-
setLeft(_left);
|
|
615
694
|
return Promise.resolve(getPrev(_p.id || 0)).then(function (_getPrev) {
|
|
616
695
|
prePrev = _getPrev;
|
|
617
696
|
return Promise.resolve(getNext(_n.id || 0)).then(function (_getNext) {
|
|
618
697
|
postNext = _getNext;
|
|
619
698
|
_defaultCurrent = defaultCurrent;
|
|
699
|
+
setLoad(false);
|
|
620
700
|
});
|
|
621
701
|
});
|
|
622
702
|
});
|
|
@@ -634,7 +714,7 @@ var Swiper = function Swiper(props) {
|
|
|
634
714
|
var _temp18 = function _temp18() {
|
|
635
715
|
var _temp15 = function () {
|
|
636
716
|
if (next !== null && next !== void 0 && next.id) {
|
|
637
|
-
return Promise.resolve(infitationAnimationHandler(-
|
|
717
|
+
return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5 * -1)).then(function () {});
|
|
638
718
|
}
|
|
639
719
|
}();
|
|
640
720
|
|
|
@@ -643,7 +723,7 @@ var Swiper = function Swiper(props) {
|
|
|
643
723
|
|
|
644
724
|
var _temp19 = function () {
|
|
645
725
|
if (prev !== null && prev !== void 0 && prev.id) {
|
|
646
|
-
return Promise.resolve(infitationAnimationHandler(
|
|
726
|
+
return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5)).then(function () {});
|
|
647
727
|
}
|
|
648
728
|
}();
|
|
649
729
|
|
|
@@ -665,14 +745,14 @@ var Swiper = function Swiper(props) {
|
|
|
665
745
|
};
|
|
666
746
|
}, [next, defaultCurrent]);
|
|
667
747
|
return React.createElement("div", {
|
|
668
|
-
className:
|
|
748
|
+
className: container,
|
|
669
749
|
ref: containerRef
|
|
670
750
|
}, swipes.map(function (item) {
|
|
671
751
|
var _item$id;
|
|
672
752
|
|
|
673
753
|
return React.createElement("div", {
|
|
674
754
|
key: item.id
|
|
675
|
-
}, React.createElement(
|
|
755
|
+
}, React.createElement(Fragment, null, item.id && width && React.createElement("div", {
|
|
676
756
|
onTouchMove: onTouchWrapper('onTouchMove'),
|
|
677
757
|
onTouchStart: onTouchWrapper('onTouchStart'),
|
|
678
758
|
onTouchEnd: onTouchWrapper('onTouchEnd'),
|
|
@@ -690,10 +770,10 @@ var Swiper = function Swiper(props) {
|
|
|
690
770
|
height: height,
|
|
691
771
|
left: left + windowWidth
|
|
692
772
|
},
|
|
693
|
-
className: clsx(
|
|
773
|
+
className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : ''),
|
|
694
774
|
ref: getRef(item.id)
|
|
695
|
-
}, React.createElement(
|
|
696
|
-
className: clsx(
|
|
775
|
+
}, React.createElement(Paper, {
|
|
776
|
+
className: clsx(content, className)
|
|
697
777
|
}, item.children)), !item.id && React.createElement("div", {
|
|
698
778
|
style: item.type === 'current' ? {
|
|
699
779
|
width: width,
|
|
@@ -708,19 +788,19 @@ var Swiper = function Swiper(props) {
|
|
|
708
788
|
height: height,
|
|
709
789
|
left: left + windowWidth
|
|
710
790
|
},
|
|
711
|
-
className: clsx(
|
|
791
|
+
className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : '')
|
|
712
792
|
}, React.createElement(IconButton, {
|
|
713
793
|
disabled: true
|
|
714
794
|
}, React.createElement(StopIcon, null)))));
|
|
715
795
|
}), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) && React.createElement("div", {
|
|
716
|
-
className: clsx(
|
|
717
|
-
ref: _buttonPrevRef
|
|
796
|
+
className: clsx(button, button__prev)
|
|
718
797
|
}, React.createElement(IconButton, {
|
|
798
|
+
disabled: load,
|
|
719
799
|
onClick: clickPrevHandler
|
|
720
800
|
}, React.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) && React.createElement("div", {
|
|
721
|
-
className: clsx(
|
|
722
|
-
ref: _buttonNextRef
|
|
801
|
+
className: clsx(button, button__next)
|
|
723
802
|
}, React.createElement(IconButton, {
|
|
803
|
+
disabled: load,
|
|
724
804
|
onClick: clickNextHandler
|
|
725
805
|
}, React.createElement(NavigateNextIcon, null))));
|
|
726
806
|
};
|