1 |
- "use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames4=_interopRequireDefault(require("../helpers/libs/classNames")),_gestures=require("../helpers/shared/gestures"),_useDOM=require("../helpers/hooks/useDOM");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 ownKeys(e,t){var n,i=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,n)),i}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}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 n;if(t)return"string"==typeof t?_arrayLikeToArray(t,e):"Map"===(n="Object"===(n=Object.prototype.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:n)||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(t,e):void 0}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function _iterableToArrayLimit(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var i,o,r,s,a=[],h=!0,u=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;h=!1}else for(;!(h=(i=r.call(n)).done)&&(a.push(i.value),a.length!==e);h=!0);}catch(t){u=!0,o=t}finally{try{if(!h&&null!=n.return&&(s=n.return(),Object(s)!==s))return}finally{if(u)throw o}}return a}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _defineProperty(t,e,n){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,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 n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);n=n.call(t,e||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(0,_baseComponent.default)({relations:{"../swipe-action-group/index":{type:"ancestor"}},properties:{prefixCls:{type:String,value:"wux-swipe"},autoClose:{type:Boolean,value:!1},disabled:{type:Boolean,value:!1},left:{type:Array,value:[],observer:"updateBtns"},right:{type:Array,value:[],observer:"updateBtns"},useSlots:{type:Boolean,value:!1},data:{type:null,value:null}},data:{index:0,swiping:!1,showCover:!1,offsetStyle:""},computed:{classes:["prefixCls, swiping",function(t,e){return{wrap:(0,_classNames4.default)(t,_defineProperty({},"".concat(t,"--swiping"),e)),cover:"".concat(t,"__cover"),left:(0,_classNames4.default)("".concat(t,"__actions"),_defineProperty({},"".concat(t,"__actions--left"),!0)),right:(0,_classNames4.default)("".concat(t,"__actions"),_defineProperty({},"".concat(t,"__actions--right"),!0)),action:"".concat(t,"__action"),text:"".concat(t,"__text"),content:"".concat(t,"__content")}}]},methods:{updated:function(t){this.data.index!==t&&this.setData({index:t})},onCloseSwipe:function(){var t=this.getRelationsByName("../swipe-action-group/index")[0];t&&t.onCloseSwipe(this.data.index)},getContentEasing:function(t,e){var n=Math.abs(t)-Math.abs(e),i=0<e?1:-1;return 0<n&&(t=e+Math.pow(n,.85)*i,Math.abs(t)>Math.abs(e))?e:t},setStyle:function(t){var e=0<t?this.btnsLeftWidth:-this.btnsRightWidth,e=this.getContentEasing(t,e),e="left: ".concat(e,"px"),t=0<Math.abs(t);this.data.offsetStyle===e&&this.data.showCover===t||this.setData({offsetStyle:e,showCover:t})},updateBtns:function(){var n=this,t=this.data.prefixCls;(0,_useDOM.useRect)([".".concat(t,"__actions--left"),".".concat(t,"__actions--right")],this).then(function(t){var t=_slicedToArray(t,2),e=t[0],t=t[1];n.btnsLeftWidth=e?e.width:0,n.btnsRightWidth=t?t.width:0})},onTap:function(t){var e=t.currentTarget.dataset.type,t=_objectSpread(_objectSpread({},t.currentTarget.dataset),{},{buttons:this.data[e],data:this.data.data});this.data.autoClose&&this.onClose(),this.triggerEvent("click",t)},onAcitons:function(){this.data.autoClose&&this.onClose()},onOpen:function(t,e,n){this.openedLeft||this.openedRight||this.triggerEvent("open"),this.openedLeft=e,this.openedRight=n,this.setStyle(t)},onClose:function(){(this.openedLeft||this.openedRight)&&this.triggerEvent("close"),this.openedLeft=!1,this.openedRight=!1,this.setStyle(0)},onOpenLeft:function(){this.onOpen(this.btnsLeftWidth,!0,!1)},onOpenRight:function(){this.onOpen(-this.btnsRightWidth,!0,!1)},onTouchStart:function(t){this.data.disabled||1<(0,_gestures.getPointsNumber)(t)||(this.start=(0,_gestures.getTouchPoints)(t),this.onCloseSwipe())},onTouchMove:function(t){var e,n,i,o,r;this.data.disabled||1<(0,_gestures.getPointsNumber)(t)||(this.move=(0,_gestures.getTouchPoints)(t),t=this.move.x-this.start.x,n="Right"===(e=(0,_gestures.getSwipeDirection)(this.start.x,this.move.x,this.start.y,this.move.y)),((e="Left"===e)||n)&&(i=(r=this.data).left,o=r.right,r=r.useSlots,this.needShowRight=e&&(r||0<o.length),this.needShowLeft=n&&(r||0<i.length),this.needShowLeft||this.needShowRight)&&(this.swiping=!0,this.setData({swiping:!0}),this.setStyle(t)))},onTouchEnd:function(t){var e;this.data.disabled||1<(0,_gestures.getPointsNumber)(t)||!this.swiping||(this.end=(0,_gestures.getTouchPoints)(t),t=this.end.x-this.start.x,e=this.needShowRight&&Math.abs(t)>this.btnsRightWidth/2,t=this.needShowLeft&&Math.abs(t)>this.btnsLeftWidth/2,e?this.onOpenRight():t?this.onOpenLeft():this.onClose(),this.swiping=!1,this.setData({swiping:!1}),this.needShowLeft=!1,this.needShowRight=!1)},noop:function(){}},created:function(){this.btnsLeftWidth=0,this.btnsRightWidth=0,this.openedLeft=!1,this.openedRight=!1,this.needShowLeft=!1,this.needShowRight=!1},ready:function(){this.updateBtns()}});
|