1 |
- "use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames2=_interopRequireDefault(require("../helpers/libs/classNames")),_styleToCssString=_interopRequireDefault(require("../helpers/libs/styleToCssString")),_bound=require("../helpers/shared/bound"),_useDOM=require("../helpers/hooks/useDOM"),_props=require("./props");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_unsupportedIterableToArray(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(t,e){var r;if(t)return"string"==typeof t?_arrayLikeToArray(t,e):"Map"===(r="Object"===(r=Object.prototype.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(t,e):void 0}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function _iterableToArrayLimit(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,a,l=[],s=!0,c=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=o.call(r)).done)&&(l.push(n.value),l.length!==e);s=!0);}catch(t){c=!0,i=t}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw i}}return l}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _defineProperty(t,e,r){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"==_typeof(t)?t:String(t)}function _toPrimitive(t,e){if("object"!=_typeof(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}var getDefaultActiveKey=function(t){t=t.filter(function(t){return!t.data.disabled})[0];return t?t.data.key:null},activeKeyIsValid=function(t,e){return t.map(function(t){return t.data.key}).includes(e)},getActiveKey=function(t,e){var r=getDefaultActiveKey(t);return e&&activeKeyIsValid(t,e)?e:r};(0,_baseComponent.default)({relations:{"../tab/index":{type:"child",observer:function(){this.callDebounceFn(this.updated)}}},properties:_props.props,data:{activeKey:"",keys:[],scrollLeft:0,scrollTop:0,showPrevMask:!1,showNextMask:!1,scrollViewStyle:""},observers:{current:function(t){this.data.controlled&&this.updated(t)},justify:function(t){this.setStyles(t)}},computed:{classes:["prefixCls, direction, scroll",function(t,e,r){return{wrap:(0,_classNames2.default)(t,_defineProperty(_defineProperty({},"".concat(t,"--").concat(e),e),"".concat(t,"--scroll"),r)),scrollView:"".concat(t,"__scroll-view"),prev:(0,_classNames2.default)(["".concat(t,"__mask"),"".concat(t,"__mask--prev")]),next:(0,_classNames2.default)(["".concat(t,"__mask"),"".concat(t,"__mask--next")])}}]},methods:{onScrollFix:function(){var t,n=this,e=this.data.direction;"horizontal"===e&&(this.updateMask||(t=this.useThrottleFn(function(){n.tabsContainerRef().then(function(t){var e=t.containerScrollLeft,r=0<e,e=Math.round(e+t.containerWidth)<Math.round(t.containerScrollWidth);n.setData({showPrevMask:r,showNextMask:e})})},100,{trailing:!0,leading:!0}).run,this.updateMask=t),this.updateMask.call(this)),"vertical"===e&&(this.updateMask||(t=this.useThrottleFn(function(){n.tabsContainerRef().then(function(t){var e=t.containerScrollTop,r=0<e,e=Math.round(e+t.containerHeight)<Math.round(t.containerScrollHeight);n.setData({showPrevMask:r,showNextMask:e})})},100,{trailing:!0,leading:!0}).run,this.updateMask=t),this.updateMask.call(this))},tabsContainerRef:function(){var t=this.data.prefixCls;return(0,_useDOM.useRef)(".".concat(t,"__scroll-view"),this).then(function(t){return{containerWidth:t.width,containerHeight:t.height,containerScrollWidth:t.scrollWidth,containerScrollHeight:t.scrollHeight,containerScrollLeft:t.scrollLeft,containerScrollTop:t.scrollTop,containerOffsetX:t.left,containerOffsetY:t.top}})},setNextScroll:function(t){var r=this,e=this.data,n=e.direction;if(e.scroll)return Promise.all([this.tabsContainerRef(),t.activeTabRef()]).then(function(t){var e,t=_slicedToArray(t,2),r=t[0],t=t[1];return"horizontal"===n?(e=r.containerScrollWidth-r.containerWidth)<=0?[]:[Math.round((0,_bound.bound)(r.containerScrollLeft+(t.activeTabLeft-r.containerOffsetX)-(r.containerWidth-t.activeTabWidth)/2,0,e)),void 0]:"vertical"===n?(e=r.containerScrollHeight-r.containerHeight)<=0?[]:[void 0,Math.round((0,_bound.bound)(r.containerScrollTop+(t.activeTabTop-r.containerOffsetY)-(r.containerHeight-t.activeTabHeight)/2,0,e))]:void 0}).then(function(t){var t=_slicedToArray(t,2),e=t[0],t=t[1];void 0!==e&&(r.setData({scrollLeft:e}),r.onScrollFix()),void 0!==t&&(r.setData({scrollTop:t}),r.onScrollFix())})},updated:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.data.activeKey,e=this.getRelationsByName("../tab/index"),t=getActiveKey(e,t);this.data.activeKey!==t&&this.setData({activeKey:t}),this.changeCurrent(t,e)},changeCurrent:function(e,t){var r=this,n=this.data,i=n.scroll,o=n.theme,a=n.direction,l=n.activeLineMode;0<t.length&&t.forEach(function(t){t.changeCurrent({current:t.data.key===e,context:{scroll:i,theme:o,direction:a,activeLineMode:l}}),t.data.key===e&&r.setNextScroll(t)}),this.data.keys.length!==t.length&&this.setData({keys:t.map(function(t){return t.data})})},emitEvent:function(t){this.triggerEvent("change",{key:t,keys:this.data.keys})},setActiveKey:function(t){this.data.controlled||this.updated(t),this.emitEvent(t)},setStyles:function(t){"horizontal"===this.data.direction&&(t=(0,_styleToCssString.default)({"justify-content":t}),this.data.scrollViewStyle!==t)&&this.setData({scrollViewStyle:t})}},ready:function(){var t=this.data,e=t.defaultCurrent,r=t.current,n=t.controlled,t=t.justify;this.updated(n?r:e),this.setStyles(t)}});
|