123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- "use strict";
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.InnerSlider = void 0;
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
- var _isNativeReflectConstruct2 = _interopRequireDefault(require("@babel/runtime/helpers/isNativeReflectConstruct"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
- var _react = _interopRequireDefault(require("react"));
- var _initialState = _interopRequireDefault(require("./initial-state"));
- var _throttleDebounce = require("throttle-debounce");
- var _classnames = _interopRequireDefault(require("classnames"));
- var _innerSliderUtils = require("./utils/innerSliderUtils");
- var _track = require("./track");
- var _dots = require("./dots");
- var _arrows = require("./arrows");
- var _resizeObserverPolyfill = _interopRequireDefault(require("resize-observer-polyfill"));
- var _excluded = ["animating"];
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, (0, _isNativeReflectConstruct2["default"])() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
- var InnerSlider = exports.InnerSlider = /*#__PURE__*/function (_React$Component) {
- function InnerSlider(props) {
- var _this;
- (0, _classCallCheck2["default"])(this, InnerSlider);
- _this = _callSuper(this, InnerSlider, [props]);
- (0, _defineProperty2["default"])(_this, "listRefHandler", function (ref) {
- return _this.list = ref;
- });
- (0, _defineProperty2["default"])(_this, "trackRefHandler", function (ref) {
- return _this.track = ref;
- });
- (0, _defineProperty2["default"])(_this, "adaptHeight", function () {
- if (_this.props.adaptiveHeight && _this.list) {
- var elem = _this.list.querySelector("[data-index=\"".concat(_this.state.currentSlide, "\"]"));
- _this.list.style.height = (0, _innerSliderUtils.getHeight)(elem) + "px";
- }
- });
- (0, _defineProperty2["default"])(_this, "componentDidMount", function () {
- _this.props.onInit && _this.props.onInit();
- if (_this.props.lazyLoad) {
- var slidesToLoad = (0, _innerSliderUtils.getOnDemandLazySlides)((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state));
- if (slidesToLoad.length > 0) {
- _this.setState(function (prevState) {
- return {
- lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad)
- };
- });
- if (_this.props.onLazyLoad) {
- _this.props.onLazyLoad(slidesToLoad);
- }
- }
- }
- var spec = (0, _objectSpread2["default"])({
- listRef: _this.list,
- trackRef: _this.track
- }, _this.props);
- _this.updateState(spec, true, function () {
- _this.adaptHeight();
- _this.props.autoplay && _this.autoPlay("playing");
- });
- if (_this.props.lazyLoad === "progressive") {
- _this.lazyLoadTimer = setInterval(_this.progressiveLazyLoad, 1000);
- }
- _this.ro = new _resizeObserverPolyfill["default"](function () {
- if (_this.state.animating) {
- _this.onWindowResized(false); // don't set trackStyle hence don't break animation
- _this.callbackTimers.push(setTimeout(function () {
- return _this.onWindowResized();
- }, _this.props.speed));
- } else {
- _this.onWindowResized();
- }
- });
- _this.ro.observe(_this.list);
- document.querySelectorAll && Array.prototype.forEach.call(document.querySelectorAll(".slick-slide"), function (slide) {
- slide.onfocus = _this.props.pauseOnFocus ? _this.onSlideFocus : null;
- slide.onblur = _this.props.pauseOnFocus ? _this.onSlideBlur : null;
- });
- if (window.addEventListener) {
- window.addEventListener("resize", _this.onWindowResized);
- } else {
- window.attachEvent("onresize", _this.onWindowResized);
- }
- });
- (0, _defineProperty2["default"])(_this, "componentWillUnmount", function () {
- if (_this.animationEndCallback) {
- clearTimeout(_this.animationEndCallback);
- }
- if (_this.lazyLoadTimer) {
- clearInterval(_this.lazyLoadTimer);
- }
- if (_this.callbackTimers.length) {
- _this.callbackTimers.forEach(function (timer) {
- return clearTimeout(timer);
- });
- _this.callbackTimers = [];
- }
- if (window.addEventListener) {
- window.removeEventListener("resize", _this.onWindowResized);
- } else {
- window.detachEvent("onresize", _this.onWindowResized);
- }
- if (_this.autoplayTimer) {
- clearInterval(_this.autoplayTimer);
- }
- _this.ro.disconnect();
- });
- (0, _defineProperty2["default"])(_this, "componentDidUpdate", function (prevProps) {
- _this.checkImagesLoad();
- _this.props.onReInit && _this.props.onReInit();
- if (_this.props.lazyLoad) {
- var slidesToLoad = (0, _innerSliderUtils.getOnDemandLazySlides)((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state));
- if (slidesToLoad.length > 0) {
- _this.setState(function (prevState) {
- return {
- lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad)
- };
- });
- if (_this.props.onLazyLoad) {
- _this.props.onLazyLoad(slidesToLoad);
- }
- }
- }
- // if (this.props.onLazyLoad) {
- // this.props.onLazyLoad([leftMostSlide])
- // }
- _this.adaptHeight();
- var spec = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
- listRef: _this.list,
- trackRef: _this.track
- }, _this.props), _this.state);
- var setTrackStyle = _this.didPropsChange(prevProps);
- setTrackStyle && _this.updateState(spec, setTrackStyle, function () {
- if (_this.state.currentSlide >= _react["default"].Children.count(_this.props.children)) {
- _this.changeSlide({
- message: "index",
- index: _react["default"].Children.count(_this.props.children) - _this.props.slidesToShow,
- currentSlide: _this.state.currentSlide
- });
- }
- if (prevProps.autoplay !== _this.props.autoplay || prevProps.autoplaySpeed !== _this.props.autoplaySpeed) {
- if (!prevProps.autoplay && _this.props.autoplay) {
- _this.autoPlay("playing");
- } else if (_this.props.autoplay) {
- _this.autoPlay("update");
- } else {
- _this.pause("paused");
- }
- }
- });
- });
- (0, _defineProperty2["default"])(_this, "onWindowResized", function (setTrackStyle) {
- if (_this.debouncedResize) _this.debouncedResize.cancel();
- _this.debouncedResize = (0, _throttleDebounce.debounce)(50, function () {
- return _this.resizeWindow(setTrackStyle);
- });
- _this.debouncedResize();
- });
- (0, _defineProperty2["default"])(_this, "resizeWindow", function () {
- var setTrackStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
- var isTrackMounted = Boolean(_this.track && _this.track.node);
- // prevent warning: setting state on unmounted component (server side rendering)
- if (!isTrackMounted) return;
- var spec = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
- listRef: _this.list,
- trackRef: _this.track
- }, _this.props), _this.state);
- _this.updateState(spec, setTrackStyle, function () {
- if (_this.props.autoplay) _this.autoPlay("update");else _this.pause("paused");
- });
- // animating state should be cleared while resizing, otherwise autoplay stops working
- _this.setState({
- animating: false
- });
- clearTimeout(_this.animationEndCallback);
- delete _this.animationEndCallback;
- });
- (0, _defineProperty2["default"])(_this, "updateState", function (spec, setTrackStyle, callback) {
- var updatedState = (0, _innerSliderUtils.initializedState)(spec);
- spec = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, spec), updatedState), {}, {
- slideIndex: updatedState.currentSlide
- });
- var targetLeft = (0, _innerSliderUtils.getTrackLeft)(spec);
- spec = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, spec), {}, {
- left: targetLeft
- });
- var trackStyle = (0, _innerSliderUtils.getTrackCSS)(spec);
- if (setTrackStyle || _react["default"].Children.count(_this.props.children) !== _react["default"].Children.count(spec.children)) {
- updatedState["trackStyle"] = trackStyle;
- }
- _this.setState(updatedState, callback);
- });
- (0, _defineProperty2["default"])(_this, "ssrInit", function () {
- if (_this.props.variableWidth) {
- var _trackWidth = 0,
- _trackLeft = 0;
- var childrenWidths = [];
- var preClones = (0, _innerSliderUtils.getPreClones)((0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state), {}, {
- slideCount: _this.props.children.length
- }));
- var postClones = (0, _innerSliderUtils.getPostClones)((0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state), {}, {
- slideCount: _this.props.children.length
- }));
- _this.props.children.forEach(function (child) {
- childrenWidths.push(child.props.style.width);
- _trackWidth += child.props.style.width;
- });
- for (var i = 0; i < preClones; i++) {
- _trackLeft += childrenWidths[childrenWidths.length - 1 - i];
- _trackWidth += childrenWidths[childrenWidths.length - 1 - i];
- }
- for (var _i = 0; _i < postClones; _i++) {
- _trackWidth += childrenWidths[_i];
- }
- for (var _i2 = 0; _i2 < _this.state.currentSlide; _i2++) {
- _trackLeft += childrenWidths[_i2];
- }
- var _trackStyle = {
- width: _trackWidth + "px",
- left: -_trackLeft + "px"
- };
- if (_this.props.centerMode) {
- var currentWidth = "".concat(childrenWidths[_this.state.currentSlide], "px");
- _trackStyle.left = "calc(".concat(_trackStyle.left, " + (100% - ").concat(currentWidth, ") / 2 ) ");
- }
- return {
- trackStyle: _trackStyle
- };
- }
- var childrenCount = _react["default"].Children.count(_this.props.children);
- var spec = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state), {}, {
- slideCount: childrenCount
- });
- var slideCount = (0, _innerSliderUtils.getPreClones)(spec) + (0, _innerSliderUtils.getPostClones)(spec) + childrenCount;
- var trackWidth = 100 / _this.props.slidesToShow * slideCount;
- var slideWidth = 100 / slideCount;
- var trackLeft = -slideWidth * ((0, _innerSliderUtils.getPreClones)(spec) + _this.state.currentSlide) * trackWidth / 100;
- if (_this.props.centerMode) {
- trackLeft += (100 - slideWidth * trackWidth / 100) / 2;
- }
- var trackStyle = {
- width: trackWidth + "%",
- left: trackLeft + "%"
- };
- return {
- slideWidth: slideWidth + "%",
- trackStyle: trackStyle
- };
- });
- (0, _defineProperty2["default"])(_this, "checkImagesLoad", function () {
- var images = _this.list && _this.list.querySelectorAll && _this.list.querySelectorAll(".slick-slide img") || [];
- var imagesCount = images.length,
- loadedCount = 0;
- Array.prototype.forEach.call(images, function (image) {
- var handler = function handler() {
- return ++loadedCount && loadedCount >= imagesCount && _this.onWindowResized();
- };
- if (!image.onclick) {
- image.onclick = function () {
- return image.parentNode.focus();
- };
- } else {
- var prevClickHandler = image.onclick;
- image.onclick = function (e) {
- prevClickHandler(e);
- image.parentNode.focus();
- };
- }
- if (!image.onload) {
- if (_this.props.lazyLoad) {
- image.onload = function () {
- _this.adaptHeight();
- _this.callbackTimers.push(setTimeout(_this.onWindowResized, _this.props.speed));
- };
- } else {
- image.onload = handler;
- image.onerror = function () {
- handler();
- _this.props.onLazyLoadError && _this.props.onLazyLoadError();
- };
- }
- }
- });
- });
- (0, _defineProperty2["default"])(_this, "progressiveLazyLoad", function () {
- var slidesToLoad = [];
- var spec = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state);
- for (var index = _this.state.currentSlide; index < _this.state.slideCount + (0, _innerSliderUtils.getPostClones)(spec); index++) {
- if (_this.state.lazyLoadedList.indexOf(index) < 0) {
- slidesToLoad.push(index);
- break;
- }
- }
- for (var _index = _this.state.currentSlide - 1; _index >= -(0, _innerSliderUtils.getPreClones)(spec); _index--) {
- if (_this.state.lazyLoadedList.indexOf(_index) < 0) {
- slidesToLoad.push(_index);
- break;
- }
- }
- if (slidesToLoad.length > 0) {
- _this.setState(function (state) {
- return {
- lazyLoadedList: state.lazyLoadedList.concat(slidesToLoad)
- };
- });
- if (_this.props.onLazyLoad) {
- _this.props.onLazyLoad(slidesToLoad);
- }
- } else {
- if (_this.lazyLoadTimer) {
- clearInterval(_this.lazyLoadTimer);
- delete _this.lazyLoadTimer;
- }
- }
- });
- (0, _defineProperty2["default"])(_this, "slideHandler", function (index) {
- var dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- var _this$props = _this.props,
- asNavFor = _this$props.asNavFor,
- beforeChange = _this$props.beforeChange,
- onLazyLoad = _this$props.onLazyLoad,
- speed = _this$props.speed,
- afterChange = _this$props.afterChange;
- // capture currentslide before state is updated
- var currentSlide = _this.state.currentSlide;
- var _slideHandler = (0, _innerSliderUtils.slideHandler)((0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
- index: index
- }, _this.props), _this.state), {}, {
- trackRef: _this.track,
- useCSS: _this.props.useCSS && !dontAnimate
- })),
- state = _slideHandler.state,
- nextState = _slideHandler.nextState;
- if (!state) return;
- beforeChange && beforeChange(currentSlide, state.currentSlide);
- var slidesToLoad = state.lazyLoadedList.filter(function (value) {
- return _this.state.lazyLoadedList.indexOf(value) < 0;
- });
- onLazyLoad && slidesToLoad.length > 0 && onLazyLoad(slidesToLoad);
- if (!_this.props.waitForAnimate && _this.animationEndCallback) {
- clearTimeout(_this.animationEndCallback);
- afterChange && afterChange(currentSlide);
- delete _this.animationEndCallback;
- }
- _this.setState(state, function () {
- // asNavForIndex check is to avoid recursive calls of slideHandler in waitForAnimate=false mode
- if (asNavFor && _this.asNavForIndex !== index) {
- _this.asNavForIndex = index;
- asNavFor.innerSlider.slideHandler(index);
- }
- if (!nextState) return;
- _this.animationEndCallback = setTimeout(function () {
- var animating = nextState.animating,
- firstBatch = (0, _objectWithoutProperties2["default"])(nextState, _excluded);
- _this.setState(firstBatch, function () {
- _this.callbackTimers.push(setTimeout(function () {
- return _this.setState({
- animating: animating
- });
- }, 10));
- afterChange && afterChange(state.currentSlide);
- delete _this.animationEndCallback;
- });
- }, speed);
- });
- });
- (0, _defineProperty2["default"])(_this, "changeSlide", function (options) {
- var dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- var spec = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state);
- var targetSlide = (0, _innerSliderUtils.changeSlide)(spec, options);
- if (targetSlide !== 0 && !targetSlide) return;
- if (dontAnimate === true) {
- _this.slideHandler(targetSlide, dontAnimate);
- } else {
- _this.slideHandler(targetSlide);
- }
- _this.props.autoplay && _this.autoPlay("update");
- if (_this.props.focusOnSelect) {
- var nodes = _this.list.querySelectorAll(".slick-current");
- nodes[0] && nodes[0].focus();
- }
- });
- (0, _defineProperty2["default"])(_this, "clickHandler", function (e) {
- if (_this.clickable === false) {
- e.stopPropagation();
- e.preventDefault();
- }
- _this.clickable = true;
- });
- (0, _defineProperty2["default"])(_this, "keyHandler", function (e) {
- var dir = (0, _innerSliderUtils.keyHandler)(e, _this.props.accessibility, _this.props.rtl);
- dir !== "" && _this.changeSlide({
- message: dir
- });
- });
- (0, _defineProperty2["default"])(_this, "selectHandler", function (options) {
- _this.changeSlide(options);
- });
- (0, _defineProperty2["default"])(_this, "disableBodyScroll", function () {
- var preventDefault = function preventDefault(e) {
- e = e || window.event;
- if (e.preventDefault) e.preventDefault();
- e.returnValue = false;
- };
- window.ontouchmove = preventDefault;
- });
- (0, _defineProperty2["default"])(_this, "enableBodyScroll", function () {
- window.ontouchmove = null;
- });
- (0, _defineProperty2["default"])(_this, "swipeStart", function (e) {
- if (_this.props.verticalSwiping) {
- _this.disableBodyScroll();
- }
- var state = (0, _innerSliderUtils.swipeStart)(e, _this.props.swipe, _this.props.draggable);
- state !== "" && _this.setState(state);
- });
- (0, _defineProperty2["default"])(_this, "swipeMove", function (e) {
- var state = (0, _innerSliderUtils.swipeMove)(e, (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state), {}, {
- trackRef: _this.track,
- listRef: _this.list,
- slideIndex: _this.state.currentSlide
- }));
- if (!state) return;
- if (state["swiping"]) {
- _this.clickable = false;
- }
- _this.setState(state);
- });
- (0, _defineProperty2["default"])(_this, "swipeEnd", function (e) {
- var state = (0, _innerSliderUtils.swipeEnd)(e, (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state), {}, {
- trackRef: _this.track,
- listRef: _this.list,
- slideIndex: _this.state.currentSlide
- }));
- if (!state) return;
- var triggerSlideHandler = state["triggerSlideHandler"];
- delete state["triggerSlideHandler"];
- _this.setState(state);
- if (triggerSlideHandler === undefined) return;
- _this.slideHandler(triggerSlideHandler);
- if (_this.props.verticalSwiping) {
- _this.enableBodyScroll();
- }
- });
- (0, _defineProperty2["default"])(_this, "touchEnd", function (e) {
- _this.swipeEnd(e);
- _this.clickable = true;
- });
- (0, _defineProperty2["default"])(_this, "slickPrev", function () {
- // this and fellow methods are wrapped in setTimeout
- // to make sure initialize setState has happened before
- // any of such methods are called
- _this.callbackTimers.push(setTimeout(function () {
- return _this.changeSlide({
- message: "previous"
- });
- }, 0));
- });
- (0, _defineProperty2["default"])(_this, "slickNext", function () {
- _this.callbackTimers.push(setTimeout(function () {
- return _this.changeSlide({
- message: "next"
- });
- }, 0));
- });
- (0, _defineProperty2["default"])(_this, "slickGoTo", function (slide) {
- var dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- slide = Number(slide);
- if (isNaN(slide)) return "";
- _this.callbackTimers.push(setTimeout(function () {
- return _this.changeSlide({
- message: "index",
- index: slide,
- currentSlide: _this.state.currentSlide
- }, dontAnimate);
- }, 0));
- });
- (0, _defineProperty2["default"])(_this, "play", function () {
- var nextIndex;
- if (_this.props.rtl) {
- nextIndex = _this.state.currentSlide - _this.props.slidesToScroll;
- } else {
- if ((0, _innerSliderUtils.canGoNext)((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state))) {
- nextIndex = _this.state.currentSlide + _this.props.slidesToScroll;
- } else {
- return false;
- }
- }
- _this.slideHandler(nextIndex);
- });
- (0, _defineProperty2["default"])(_this, "autoPlay", function (playType) {
- if (_this.autoplayTimer) {
- clearInterval(_this.autoplayTimer);
- }
- var autoplaying = _this.state.autoplaying;
- if (playType === "update") {
- if (autoplaying === "hovered" || autoplaying === "focused" || autoplaying === "paused") {
- return;
- }
- } else if (playType === "leave") {
- if (autoplaying === "paused" || autoplaying === "focused") {
- return;
- }
- } else if (playType === "blur") {
- if (autoplaying === "paused" || autoplaying === "hovered") {
- return;
- }
- }
- _this.autoplayTimer = setInterval(_this.play, _this.props.autoplaySpeed + 50);
- _this.setState({
- autoplaying: "playing"
- });
- });
- (0, _defineProperty2["default"])(_this, "pause", function (pauseType) {
- if (_this.autoplayTimer) {
- clearInterval(_this.autoplayTimer);
- _this.autoplayTimer = null;
- }
- var autoplaying = _this.state.autoplaying;
- if (pauseType === "paused") {
- _this.setState({
- autoplaying: "paused"
- });
- } else if (pauseType === "focused") {
- if (autoplaying === "hovered" || autoplaying === "playing") {
- _this.setState({
- autoplaying: "focused"
- });
- }
- } else {
- // pauseType is 'hovered'
- if (autoplaying === "playing") {
- _this.setState({
- autoplaying: "hovered"
- });
- }
- }
- });
- (0, _defineProperty2["default"])(_this, "onDotsOver", function () {
- return _this.props.autoplay && _this.pause("hovered");
- });
- (0, _defineProperty2["default"])(_this, "onDotsLeave", function () {
- return _this.props.autoplay && _this.state.autoplaying === "hovered" && _this.autoPlay("leave");
- });
- (0, _defineProperty2["default"])(_this, "onTrackOver", function () {
- return _this.props.autoplay && _this.pause("hovered");
- });
- (0, _defineProperty2["default"])(_this, "onTrackLeave", function () {
- return _this.props.autoplay && _this.state.autoplaying === "hovered" && _this.autoPlay("leave");
- });
- (0, _defineProperty2["default"])(_this, "onSlideFocus", function () {
- return _this.props.autoplay && _this.pause("focused");
- });
- (0, _defineProperty2["default"])(_this, "onSlideBlur", function () {
- return _this.props.autoplay && _this.state.autoplaying === "focused" && _this.autoPlay("blur");
- });
- (0, _defineProperty2["default"])(_this, "render", function () {
- var className = (0, _classnames["default"])("slick-slider", _this.props.className, {
- "slick-vertical": _this.props.vertical,
- "slick-initialized": true
- });
- var spec = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.props), _this.state);
- var trackProps = (0, _innerSliderUtils.extractObject)(spec, ["fade", "cssEase", "speed", "infinite", "centerMode", "focusOnSelect", "currentSlide", "lazyLoad", "lazyLoadedList", "rtl", "slideWidth", "slideHeight", "listHeight", "vertical", "slidesToShow", "slidesToScroll", "slideCount", "trackStyle", "variableWidth", "unslick", "centerPadding", "targetSlide", "useCSS"]);
- var pauseOnHover = _this.props.pauseOnHover;
- trackProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, trackProps), {}, {
- onMouseEnter: pauseOnHover ? _this.onTrackOver : null,
- onMouseLeave: pauseOnHover ? _this.onTrackLeave : null,
- onMouseOver: pauseOnHover ? _this.onTrackOver : null,
- focusOnSelect: _this.props.focusOnSelect && _this.clickable ? _this.selectHandler : null
- });
- var dots;
- if (_this.props.dots === true && _this.state.slideCount >= _this.props.slidesToShow) {
- var dotProps = (0, _innerSliderUtils.extractObject)(spec, ["dotsClass", "slideCount", "slidesToShow", "currentSlide", "slidesToScroll", "clickHandler", "children", "customPaging", "infinite", "appendDots"]);
- var pauseOnDotsHover = _this.props.pauseOnDotsHover;
- dotProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, dotProps), {}, {
- clickHandler: _this.changeSlide,
- onMouseEnter: pauseOnDotsHover ? _this.onDotsLeave : null,
- onMouseOver: pauseOnDotsHover ? _this.onDotsOver : null,
- onMouseLeave: pauseOnDotsHover ? _this.onDotsLeave : null
- });
- dots = /*#__PURE__*/_react["default"].createElement(_dots.Dots, dotProps);
- }
- var prevArrow, nextArrow;
- var arrowProps = (0, _innerSliderUtils.extractObject)(spec, ["infinite", "centerMode", "currentSlide", "slideCount", "slidesToShow", "prevArrow", "nextArrow"]);
- arrowProps.clickHandler = _this.changeSlide;
- if (_this.props.arrows) {
- prevArrow = /*#__PURE__*/_react["default"].createElement(_arrows.PrevArrow, arrowProps);
- nextArrow = /*#__PURE__*/_react["default"].createElement(_arrows.NextArrow, arrowProps);
- }
- var verticalHeightStyle = null;
- if (_this.props.vertical) {
- verticalHeightStyle = {
- height: _this.state.listHeight
- };
- }
- var centerPaddingStyle = null;
- if (_this.props.vertical === false) {
- if (_this.props.centerMode === true) {
- centerPaddingStyle = {
- padding: "0px " + _this.props.centerPadding
- };
- }
- } else {
- if (_this.props.centerMode === true) {
- centerPaddingStyle = {
- padding: _this.props.centerPadding + " 0px"
- };
- }
- }
- var listStyle = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, verticalHeightStyle), centerPaddingStyle);
- var touchMove = _this.props.touchMove;
- var listProps = {
- className: "slick-list",
- style: listStyle,
- onClick: _this.clickHandler,
- onMouseDown: touchMove ? _this.swipeStart : null,
- onMouseMove: _this.state.dragging && touchMove ? _this.swipeMove : null,
- onMouseUp: touchMove ? _this.swipeEnd : null,
- onMouseLeave: _this.state.dragging && touchMove ? _this.swipeEnd : null,
- onTouchStart: touchMove ? _this.swipeStart : null,
- onTouchMove: _this.state.dragging && touchMove ? _this.swipeMove : null,
- onTouchEnd: touchMove ? _this.touchEnd : null,
- onTouchCancel: _this.state.dragging && touchMove ? _this.swipeEnd : null,
- onKeyDown: _this.props.accessibility ? _this.keyHandler : null
- };
- var innerSliderProps = {
- className: className,
- dir: "ltr",
- style: _this.props.style
- };
- if (_this.props.unslick) {
- listProps = {
- className: "slick-list"
- };
- innerSliderProps = {
- className: className,
- style: _this.props.style
- };
- }
- return /*#__PURE__*/_react["default"].createElement("div", innerSliderProps, !_this.props.unslick ? prevArrow : "", /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
- ref: _this.listRefHandler
- }, listProps), /*#__PURE__*/_react["default"].createElement(_track.Track, (0, _extends2["default"])({
- ref: _this.trackRefHandler
- }, trackProps), _this.props.children)), !_this.props.unslick ? nextArrow : "", !_this.props.unslick ? dots : "");
- });
- _this.list = null;
- _this.track = null;
- _this.state = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _initialState["default"]), {}, {
- currentSlide: _this.props.initialSlide,
- targetSlide: _this.props.initialSlide ? _this.props.initialSlide : 0,
- slideCount: _react["default"].Children.count(_this.props.children)
- });
- _this.callbackTimers = [];
- _this.clickable = true;
- _this.debouncedResize = null;
- var ssrState = _this.ssrInit();
- _this.state = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _this.state), ssrState);
- return _this;
- }
- (0, _inherits2["default"])(InnerSlider, _React$Component);
- return (0, _createClass2["default"])(InnerSlider, [{
- key: "didPropsChange",
- value: function didPropsChange(prevProps) {
- var setTrackStyle = false;
- for (var _i3 = 0, _Object$keys = Object.keys(this.props); _i3 < _Object$keys.length; _i3++) {
- var key = _Object$keys[_i3];
- // eslint-disable-next-line no-prototype-builtins
- if (!prevProps.hasOwnProperty(key)) {
- setTrackStyle = true;
- break;
- }
- if ((0, _typeof2["default"])(prevProps[key]) === "object" || typeof prevProps[key] === "function" || isNaN(prevProps[key])) {
- continue;
- }
- if (prevProps[key] !== this.props[key]) {
- setTrackStyle = true;
- break;
- }
- }
- return setTrackStyle || _react["default"].Children.count(this.props.children) !== _react["default"].Children.count(prevProps.children);
- }
- }]);
- }(_react["default"].Component);
|