diff --git a/components/dropdown/dropdown-button.tsx b/components/dropdown/dropdown-button.tsx index 050382a11..c839e26c2 100644 --- a/components/dropdown/dropdown-button.tsx +++ b/components/dropdown/dropdown-button.tsx @@ -1,4 +1,4 @@ -import { ExtractPropTypes } from 'vue'; +import type { ExtractPropTypes } from 'vue'; import { defineComponent } from 'vue'; import Button from '../button'; import classNames from '../_util/classNames'; diff --git a/components/dropdown/dropdown.tsx b/components/dropdown/dropdown.tsx index f7a49b1d7..358509b66 100644 --- a/components/dropdown/dropdown.tsx +++ b/components/dropdown/dropdown.tsx @@ -1,4 +1,5 @@ -import { ExtractPropTypes, computed } from 'vue'; +import type { ExtractPropTypes } from 'vue'; +import { computed } from 'vue'; import { defineComponent } from 'vue'; import RcDropdown from '../vc-dropdown'; import DropdownButton from './dropdown-button'; diff --git a/components/popconfirm/index.tsx b/components/popconfirm/index.tsx index db6ec06b2..b96af1352 100644 --- a/components/popconfirm/index.tsx +++ b/components/popconfirm/index.tsx @@ -1,5 +1,6 @@ import omit from 'omit.js'; -import { computed, ExtractPropTypes, onMounted, PropType, ref, toRef } from 'vue'; +import type { ExtractPropTypes, PropType } from 'vue'; +import { computed, onMounted, ref, toRef } from 'vue'; import { defineComponent } from 'vue'; import Tooltip from '../tooltip'; import abstractTooltipProps from '../tooltip/abstractTooltipProps'; diff --git a/components/popover/index.tsx b/components/popover/index.tsx index 210ec5e1d..54c406be5 100644 --- a/components/popover/index.tsx +++ b/components/popover/index.tsx @@ -1,4 +1,5 @@ -import { computed, defineComponent, ExtractPropTypes, ref } from 'vue'; +import type { ExtractPropTypes } from 'vue'; +import { computed, defineComponent, ref } from 'vue'; import Tooltip from '../tooltip'; import abstractTooltipProps from '../tooltip/abstractTooltipProps'; import PropTypes from '../_util/vue-types'; diff --git a/components/vc-slick/src/inner-slider.jsx b/components/vc-slick/src/inner-slider.jsx index 828e79bad..c454636bc 100644 --- a/components/vc-slick/src/inner-slider.jsx +++ b/components/vc-slick/src/inner-slider.jsx @@ -30,11 +30,11 @@ function noop() {} export default { name: 'InnerSlider', + mixins: [BaseMixin], inheritAttrs: false, props: { ...defaultProps, }, - mixins: [BaseMixin], data() { this.preProps = { ...this.$props }; this.list = null; @@ -48,6 +48,145 @@ export default { slideCount: this.children.length, }; }, + watch: { + __propsSymbol__() { + const nextProps = this.$props; + const spec = { + listRef: this.list, + trackRef: this.track, + ...nextProps, + ...this.$data, + }; + let setTrackStyle = false; + for (const key of Object.keys(this.preProps)) { + if (!nextProps.hasOwnProperty(key)) { + setTrackStyle = true; + break; + } + if ( + typeof nextProps[key] === 'object' || + typeof nextProps[key] === 'function' || + typeof nextProps[key] === 'symbol' + ) { + continue; + } + if (nextProps[key] !== this.preProps[key]) { + setTrackStyle = true; + break; + } + } + this.updateState(spec, setTrackStyle, () => { + if (this.currentSlide >= nextProps.children.length) { + this.changeSlide({ + message: 'index', + index: nextProps.children.length - nextProps.slidesToShow, + currentSlide: this.currentSlide, + }); + } + if (nextProps.autoplay) { + this.handleAutoPlay('update'); + } else { + this.pause('paused'); + } + }); + this.preProps = { ...nextProps }; + }, + }, + beforeMount() { + this.ssrInit(); + this.__emit('init'); + if (this.lazyLoad) { + const slidesToLoad = getOnDemandLazySlides({ + ...this.$props, + ...this.$data, + }); + if (slidesToLoad.length > 0) { + this.setState(prevState => ({ + lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad), + })); + this.__emit('lazyLoad', slidesToLoad); + } + } + }, + mounted() { + this.$nextTick(() => { + const spec = { + listRef: this.list, + trackRef: this.track, + children: this.children, + ...this.$props, + }; + this.updateState(spec, true, () => { + this.adaptHeight(); + this.autoplay && this.handleAutoPlay('update'); + }); + if (this.lazyLoad === 'progressive') { + this.lazyLoadTimer = setInterval(this.progressiveLazyLoad, 1000); + } + this.ro = new ResizeObserver(() => { + if (this.animating) { + this.onWindowResized(false); // don't set trackStyle hence don't break animation + this.callbackTimers.push(setTimeout(() => this.onWindowResized(), this.speed)); + } else { + this.onWindowResized(); + } + }); + this.ro.observe(this.list); + Array.prototype.forEach.call(document.querySelectorAll('.slick-slide'), slide => { + slide.onfocus = this.$props.pauseOnFocus ? this.onSlideFocus : null; + slide.onblur = this.$props.pauseOnFocus ? this.onSlideBlur : null; + }); + // To support server-side rendering + if (!window) { + return; + } + if (window.addEventListener) { + window.addEventListener('resize', this.onWindowResized); + } else { + window.attachEvent('onresize', this.onWindowResized); + } + }); + }, + beforeUnmount() { + if (this.animationEndCallback) { + clearTimeout(this.animationEndCallback); + } + if (this.lazyLoadTimer) { + clearInterval(this.lazyLoadTimer); + } + if (this.callbackTimers.length) { + this.callbackTimers.forEach(timer => clearTimeout(timer)); + this.callbackTimers = []; + } + if (window.addEventListener) { + window.removeEventListener('resize', this.onWindowResized); + } else { + window.detachEvent('onresize', this.onWindowResized); + } + if (this.autoplayTimer) { + clearInterval(this.autoplayTimer); + } + }, + updated() { + this.checkImagesLoad(); + this.__emit('reInit'); + if (this.lazyLoad) { + const slidesToLoad = getOnDemandLazySlides({ + ...this.$props, + ...this.$data, + }); + if (slidesToLoad.length > 0) { + this.setState(prevState => ({ + lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad), + })); + this.__emit('lazyLoad'); + } + } + // if (this.props.onLazyLoad) { + // this.props.onLazyLoad([leftMostSlide]) + // } + this.adaptHeight(); + }, methods: { listRefHandler(ref) { this.list = ref; @@ -432,145 +571,6 @@ export default { return