index.js 7.1 KB

1
  1. "use strict";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)}var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames2=_interopRequireDefault(require("../helpers/libs/classNames")),_styleToCssString=_interopRequireDefault(require("../helpers/libs/styleToCssString")),_index=require("../index"),_useDOM=require("../helpers/hooks/useDOM");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_unsupportedIterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t))return _arrayLikeToArray(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.")}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,o=new Array(e);r<e;r++)o[r]=t[r];return o}function _iterableToArrayLimit(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var o,l,i,n,a=[],s=!0,p=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(o=i.call(r)).done)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){p=!0,l=t}finally{try{if(!s&&null!=r.return&&(n=r.return(),Object(n)!==n))return}finally{if(p)throw l}}return a}}function _arrayWithHoles(t){if(Array.isArray(t))return t}var getPlacements=function(){var t=_slicedToArray(0<arguments.length&&void 0!==arguments[0]?arguments[0]:rects,4),e=t[0],r=t[1],o=t[2],l=t[3];switch(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"top"){case"topLeft":return{top:l?e.top-o.height-l.top:r.scrollTop+e.top-o.height-4,left:l?e.left:r.scrollLeft+e.left};case"top":return{top:l?e.top-o.height-l.top:r.scrollTop+e.top-o.height-4,left:l?e.left+(e.width-o.width)/2:r.scrollLeft+e.left+(e.width-o.width)/2};case"topRight":return{top:l?e.top-o.height-l.top:r.scrollTop+e.top-o.height-4,left:l?e.left+e.width-o.width:r.scrollLeft+e.left+e.width-o.width};case"rightTop":return{top:l?e.top-l.top:r.scrollTop+e.top,left:l?e.left+e.width:r.scrollLeft+e.left+e.width+4};case"right":return{top:l?e.top+(e.height-o.height)/2-l.top:r.scrollTop+e.top+(e.height-o.height)/2,left:l?e.left+e.width:r.scrollLeft+e.left+e.width+4};case"rightBottom":return{top:l?e.top+e.height-o.height-l.top:r.scrollTop+e.top+e.height-o.height,left:l?e.left+e.width:r.scrollLeft+e.left+e.width+4};case"bottomRight":return{top:l?e.top+e.height-l.top:r.scrollTop+e.top+e.height+4,left:l?e.left+e.width-o.width:r.scrollLeft+e.left+e.width-o.width};case"bottom":return{top:l?e.top+e.height-l.top:r.scrollTop+e.top+e.height+4,left:l?e.left+(e.width-o.width)/2:r.scrollLeft+e.left+(e.width-o.width)/2};case"bottomLeft":return{top:l?e.top+e.height-l.top:r.scrollTop+e.top+e.height+4,left:l?e.left:r.scrollLeft+e.left};case"leftBottom":return{top:l?e.top+e.height-o.height-l.top:r.scrollTop+e.top+e.height-o.height,left:l?e.left-o.width:r.scrollLeft+e.left-o.width-4};case"left":return{top:l?e.top+(e.height-o.height)/2-l.top:r.scrollTop+e.top+(e.height-o.height)/2,left:l?e.left-o.width:r.scrollLeft+e.left-o.width-4};case"leftTop":return{top:l?e.top-l.top:r.scrollTop+e.top,left:l?e.left-o.width:r.scrollLeft+e.left-o.width-4};default:return{left:0,top:0}}};(0,_baseComponent.default)({properties:{prefixCls:{type:String,value:"wux-popover"},classNames:{type:null,value:"wux-animate--fadeIn"},theme:{type:String,value:"light"},title:{type:String,value:""},content:{type:String,value:""},placement:{type:String,value:"top"},trigger:{type:String,value:"click"},bodyStyle:{type:[String,Object],value:"",observer:function(t){this.setData({extStyle:(0,_styleToCssString.default)(t)})}},defaultVisible:{type:Boolean,value:!1},visible:{type:Boolean,value:!1,observer:function(t){this.data.controlled&&this.updated(t)}},controlled:{type:Boolean,value:!1},mask:{type:Boolean,value:!1},maskClosable:{type:Boolean,value:!0},useSlot:{type:Boolean,value:!0},slotRect:{type:Object,value:null},relativeRect:{type:Object,value:null}},data:{extStyle:"",popoverStyle:"",popoverVisible:!1},computed:{classes:["prefixCls, theme, placement",function(t,e,r){return{wrap:(0,_classNames2.default)(t,_defineProperty(_defineProperty({},"".concat(t,"--theme-").concat(e),e),"".concat(t,"--placement-").concat(r),r)),content:"".concat(t,"__content"),arrow:"".concat(t,"__arrow"),inner:"".concat(t,"__inner"),title:"".concat(t,"__title"),innerContent:"".concat(t,"__inner-content"),element:"".concat(t,"__element")}}]},methods:{updated:function(t){this.data.popoverVisible!==t&&(this.setData({popoverVisible:t}),this.setBackdropVisible(t))},getPopoverStyle:function(){var e=this,t=this.data,r=t.prefixCls,o=t.placement,l=t.slotRect,i=t.relativeRect,t=[];this.data.useSlot&&t.push((0,_useDOM.useRect)(".".concat(r,"__element"),this)),t.push((0,_useDOM.useScrollOffset)(this)),t.push((0,_useDOM.useRect)(".".concat(r),this)),Promise.all(t).then(function(t){t.filter(function(t){return!t}).length||(t=(3===t.length?[]:[l]).concat(_toConsumableArray(t),[i]),t=getPlacements(t,o),t=(0,_styleToCssString.default)(t),e.setData({popoverStyle:t}))})},onEnter:function(){this.getPopoverStyle()},onChange:function(){var t=this.data,e=!t.popoverVisible;t.controlled||this.updated(e),this.triggerEvent("change",{visible:e})},onClick:function(){"click"===this.data.trigger&&this.onChange()},setBackdropVisible:function(t){this.data.mask&&this.$wuxBackdrop&&this.$wuxBackdrop[t?"retain":"release"]()},onMaskClick:function(){var t=this.data,e=t.maskClosable,t=t.popoverVisible;e&&t&&this.onChange()}},ready:function(){var t=this.data,e=t.defaultVisible,r=t.visible,t=t.controlled?r:e;this.data.mask&&(this.$wuxBackdrop=(0,_index.$wuxBackdrop)("#wux-backdrop",this)),this.updated(t)}});