UNPKG

vxe-table-select-area

Version:

一个基于 vxe-table 的可区域选中复制、粘贴的组件

1 lines 17.5 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0,exports.renderOptgroup=renderOptgroup,exports.renderOption=renderOption;var _xeUtils=_interopRequireDefault(require("xe-utils")),_input=_interopRequireDefault(require("../../input/src/input")),_conf=_interopRequireDefault(require("../../v-x-e-table/src/conf")),_size=_interopRequireDefault(require("../../mixins/size")),_utils=_interopRequireWildcard(require("../../tools/utils")),_dom=_interopRequireDefault(require("../../tools/dom")),_event=require("../../tools/event"),_vn=require("../../tools/vn");function _getRequireWildcardCache(e){var t,i;return"function"!=typeof WeakMap?null:(t=new WeakMap,i=new WeakMap,(_getRequireWildcardCache=function(e){return e?i:t})(e))}function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==_typeof(e)&&"function"!=typeof e)return{default:e};t=_getRequireWildcardCache(t);if(t&&t.has(e))return t.get(e);var i,n,o={},l=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&((n=l?Object.getOwnPropertyDescriptor(e,i):null)&&(n.get||n.set)?Object.defineProperty(o,i,n):o[i]=e[i]);return o.default=e,t&&t.set(e,o),o}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"===_typeof(e)?e:String(e)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0===i)return("string"===t?String:Number)(e);i=i.call(e,t||"default");if("object"!==_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}function isOptionVisible(e){return!1!==e.visible}function getOptUniqueId(){return _xeUtils.default.uniqueId("opt_")}function getOptkey(e){return e.optionOpts.keyField||e.optionId||"_X_OPTION_KEY"}function getOptid(e,t){t=t[getOptkey(e)];return t?encodeURIComponent(t):""}function findOffsetOption(e,t,i){var n,o,l,s,r=e.isGroup,a=e.visibleOptionList,u=e.visibleGroupList,c=e.valueField,f=e.groupOptionsField;if(r)for(var p=0;p<u.length;p++){var h=u[p],d=h[f],v=h.disabled;if(d)for(var b=0;b<d.length;b++){var g=d[b],O=isOptionVisible(g),m=v||g.disabled;if(n||m||(n=g),s&&O&&!m&&(l=g,!i))return{offsetOption:l};if(t===g[c]){if(s=g,i)return{offsetOption:o}}else O&&!m&&(o=g)}}else for(var _=0;_<a.length;_++){var x=a[_],y=x.disabled;if(n||y||(n=x),s&&!y&&(l=x,!i))return{offsetOption:l};if(t===x[c]){if(s=x,i)return{offsetOption:o}}else y||(o=x)}return{firstOption:n}}function findOption(e,t){var i=e.isGroup,n=e.fullOptionList,o=e.fullGroupList,l=e.valueField;if(i)for(var s=0;s<o.length;s++){var r=o[s];if(r.options)for(var a=0;a<r.options.length;a++){var u=r.options[a];if(t===u[l])return u}}return n.find(function(e){return t===e[l]})}function getRemoteSelectLabel(e,t){var i=e.remoteValueList.find(function(e){return t===e.key}),i=i?i.result:null;return _xeUtils.default.toValueString(i?i[e.labelField]:t)}function getSelectLabel(e,t){var i=findOption(e,t);return _xeUtils.default.toValueString(i?i[e.labelField]:t)}function checkOptionDisabled(e,t,i,n){return!!i.disabled||!(!n||!n.disabled)||!(!e.isMaximize||t)}function renderOption(a,u,e,c){var f=u.isGroup,p=u.labelField,h=u.valueField,d=u.optionKey,v=u.value,b=u.multiple,g=u.currentValue,O=u.optionOpts.useKey;return e.map(function(t,e){var i=t.slots,n=t[h],o=b?v&&-1<v.indexOf(n):v===n,l=!f||isOptionVisible(t),s=checkOptionDisabled(u,o,t,c),r=getOptid(u,t),i=i?i.default:null;return l?a("div",{key:O||d?r:e,class:["vxe-select-option",t.className,{"is--disabled":s,"is--selected":o,"is--hover":g===n}],attrs:{optid:r},on:{mousedown:u.mousedownOptionEvent,click:function(e){s||u.changeOptionEvent(e,n,t)},mouseenter:function(){s||u.setCurrentOption(t)}}},i?u.callSlot(i,{option:t,$select:u},a):_utils.default.formatText((0,_utils.getFuncText)(t[p]))):null})}function renderOptgroup(l,s){var r=s.optionKey,e=s.visibleGroupList,a=s.groupLabelField,u=s.groupOptionsField,c=s.optionOpts.useKey;return e.map(function(e,t){var i=e.slots,n=getOptid(s,e),o=e.disabled,i=i?i.default:null;return l("div",{key:c||r?n:t,class:["vxe-optgroup",e.className,{"is--disabled":o}],attrs:{optid:n}},[l("div",{class:"vxe-optgroup--title"},i?s.callSlot(i,{option:e,$select:s},l):(0,_utils.getFuncText)(e[a])),l("div",{class:"vxe-optgroup--wrapper"},renderOption(l,s,e[u],e))])})}function renderOpts(e,t){var i=t.isGroup,n=t.visibleGroupList,o=t.visibleOptionList;if(t.searchLoading)return[e("div",{class:"vxe-select--search-loading"},[e("i",{class:["vxe-select--search-icon",_conf.default.icon.SELECT_LOADED]}),e("span",{class:"vxe-select--search-text"},_conf.default.i18n("vxe.select.loadingText"))])];if(i){if(n.length)return renderOptgroup(e,t)}else if(o.length)return renderOption(e,t,o);return[e("div",{class:"vxe-select--empty-placeholder"},t.emptyText||_conf.default.i18n("vxe.select.emptyText"))]}var _default2={name:"VxeSelect",mixins:[_size.default],props:{value:null,clearable:Boolean,placeholder:String,loading:Boolean,disabled:Boolean,multiple:Boolean,multiCharOverflow:{type:[Number,String],default:function(){return _conf.default.select.multiCharOverflow}},prefixIcon:String,placement:String,options:Array,optionProps:Object,optionGroups:Array,optionGroupProps:Object,optionConfig:Object,className:[String,Function],max:[String,Number],size:{type:String,default:function(){return _conf.default.select.size||_conf.default.size}},filterable:Boolean,filterMethod:Function,remote:Boolean,remoteMethod:Function,emptyText:String,optionId:{type:String,default:function(){return _conf.default.select.optionId}},optionKey:Boolean,transfer:{type:Boolean,default:function(){return _conf.default.select.transfer}}},components:{VxeInput:_input.default},inject:{$xeform:{default:null},$xeformiteminfo:{default:null}},provide:function(){return{$xeselect:this}},data:function(){return{inited:!1,collectOption:[],fullGroupList:[],fullOptionList:[],visibleGroupList:[],visibleOptionList:[],remoteValueList:[],panelIndex:0,panelStyle:null,panelPlacement:null,currentOption:null,currentValue:null,visiblePanel:!1,animatVisible:!1,isActivated:!1,searchValue:"",searchLoading:!1}},computed:{propsOpts:function(){return this.optionProps||{}},groupPropsOpts:function(){return this.optionGroupProps||{}},labelField:function(){return this.propsOpts.label||"label"},valueField:function(){return this.propsOpts.value||"value"},groupLabelField:function(){return this.groupPropsOpts.label||"label"},groupOptionsField:function(){return this.groupPropsOpts.options||"options"},optionOpts:function(){return Object.assign({},_conf.default.select.optionConfig,this.optionConfig)},isGroup:function(){return this.fullGroupList.some(function(e){return e.options&&e.options.length})},multiMaxCharNum:function(){return _xeUtils.default.toNumber(this.multiCharOverflow)},selectLabel:function(){var t=this,e=this.value,i=this.multiple,n=this.remote,o=this.multiMaxCharNum;return e&&i?(i=_xeUtils.default.isArray(e)?e:[e],(n?i.map(function(e){return getRemoteSelectLabel(t,e)}):i.map(function(e){e=getSelectLabel(t,e);return 0<o&&e.length>o?"".concat(e.substring(0,o),"..."):e})).join(", ")):(n?getRemoteSelectLabel:getSelectLabel)(this,e)},isMaximize:function(){var e=this.value,t=this.multiple,i=this.max;return!(!t||!i)&&(e?e.length:0)>=_xeUtils.default.toNumber(i)}},watch:{collectOption:function(e){e.some(function(e){return e.options&&e.options.length})?(this.fullOptionList=[],this.fullGroupList=e):(this.fullGroupList=[],this.fullOptionList=e),this.cacheItemMap()},options:function(e){this.fullGroupList=[],this.fullOptionList=e,this.cacheItemMap()},optionGroups:function(e){this.fullOptionList=[],this.fullGroupList=e,this.cacheItemMap()}},created:function(){var e=this.options,t=this.optionGroups;t?this.fullGroupList=t:e&&(this.fullOptionList=e),this.cacheItemMap(),_event.GlobalEvent.on(this,"mousewheel",this.handleGlobalMousewheelEvent),_event.GlobalEvent.on(this,"mousedown",this.handleGlobalMousedownEvent),_event.GlobalEvent.on(this,"keydown",this.handleGlobalKeydownEvent),_event.GlobalEvent.on(this,"blur",this.handleGlobalBlurEvent)},beforeDestroy:function(){var e=this.$refs.panel;e&&e.parentNode&&e.parentNode.removeChild(e)},destroyed:function(){_event.GlobalEvent.off(this,"mousewheel"),_event.GlobalEvent.off(this,"mousedown"),_event.GlobalEvent.off(this,"keydown"),_event.GlobalEvent.off(this,"blur")},render:function(e){var t=this._e,i=this.$scopedSlots,n=this.vSize,o=this.className,l=this.inited,s=this.isActivated,r=this.loading,a=this.disabled,u=this.visiblePanel,c=this.filterable,f=i.prefix;return e("div",{class:["vxe-select",o?_xeUtils.default.isFunction(o)?o({$select:this}):o:"",(_defineProperty(i={},"size--".concat(n),n),_defineProperty(i,"is--visivle",u),_defineProperty(i,"is--disabled",a),_defineProperty(i,"is--filter",c),_defineProperty(i,"is--loading",r),_defineProperty(i,"is--active",s),i)]},[e("div",{class:"vxe-select-slots",ref:"hideOption"},this.$slots.default),e("vxe-input",{ref:"input",props:{clearable:this.clearable,placeholder:this.placeholder,readonly:!0,disabled:a,type:"text",prefixIcon:this.prefixIcon,suffixIcon:r?_conf.default.icon.SELECT_LOADED:u?_conf.default.icon.SELECT_OPEN:_conf.default.icon.SELECT_CLOSE,value:this.selectLabel},on:{clear:this.clearEvent,click:this.togglePanelEvent,focus:this.focusEvent,blur:this.blurEvent,"suffix-click":this.togglePanelEvent},scopedSlots:f?{prefix:function(){return f({})}}:{}}),e("div",{ref:"panel",class:["vxe-table--ignore-clear vxe-select--panel",(_defineProperty(o={},"size--".concat(n),n),_defineProperty(o,"is--transfer",this.transfer),_defineProperty(o,"animat--leave",!r&&this.animatVisible),_defineProperty(o,"animat--enter",!r&&u),o)],attrs:{placement:this.panelPlacement},style:this.panelStyle},l?[c?e("div",{class:"vxe-select-filter--wrapper"},[e("vxe-input",{ref:"inpSearch",class:"vxe-select-filter--input",props:{value:this.searchValue,type:"text",clearable:!0,placeholder:_conf.default.i18n("vxe.select.search"),prefixIcon:_conf.default.icon.INPUT_SEARCH},on:{modelValue:this.modelSearchEvent,focus:this.focusSearchEvent,keydown:this.keydownSearchEvent,change:this.triggerSearchEvent,search:this.triggerSearchEvent}})]):t(),e("div",{ref:"optWrapper",class:"vxe-select-option--wrapper"},renderOpts(e,this))]:null)])},methods:{callSlot:function(e,t,i){if(e){var n=this.$scopedSlots;if(_xeUtils.default.isString(e)&&(e=n[e]||null),_xeUtils.default.isFunction(e))return(0,_vn.getSlotVNs)(e.call(this,t,i))}return[]},cacheItemMap:function(){function t(e){getOptid(i,e)||(e[l]=getOptUniqueId())}var i=this,e=this.fullOptionList,n=this.fullGroupList,o=this.groupOptionsField,l=getOptkey(this);n.length?n.forEach(function(e){t(e),e[o]&&e[o].forEach(t)}):e.length&&e.forEach(t),this.refreshOption()},refreshOption:function(){var e=this.isGroup,t=this.fullOptionList,i=this.fullGroupList,n=this.filterable,o=this.filterMethod,l=this.searchValue,s=this.labelField,r=this.groupLabelField;return e?this.visibleGroupList=n&&o?i.filter(function(e){return isOptionVisible(e)&&o({group:e,option:null,searchValue:l})}):n?i.filter(function(e){return isOptionVisible(e)&&(!l||-1<"".concat(e[r]).indexOf(l))}):i.filter(isOptionVisible):this.visibleOptionList=n&&o?t.filter(function(e){return isOptionVisible(e)&&o({group:null,option:e,searchValue:l})}):n?t.filter(function(e){return isOptionVisible(e)&&(!l||-1<"".concat(e[s]).indexOf(l))}):t.filter(isOptionVisible),this.$nextTick()},setCurrentOption:function(e){e&&(this.currentOption=e,this.currentValue=e[this.valueField])},scrollToOption:function(n,o){var l=this;return this.$nextTick().then(function(){var e,t,i;n&&(e=(t=l.$refs).optWrapper,t=t.panel.querySelector("[optid='".concat(getOptid(l,n),"']")),e)&&t&&(i=e.offsetHeight,o?t.offsetTop+t.offsetHeight-e.scrollTop>i&&(e.scrollTop=t.offsetTop+t.offsetHeight-i):(t.offsetTop+5<e.scrollTop||t.offsetTop+5>e.scrollTop+e.clientHeight)&&(e.scrollTop=t.offsetTop-5))})},clearEvent:function(e,t){this.clearValueEvent(t,null),this.hideOptionPanel()},clearValueEvent:function(e,t){this.remoteValueList=[],this.changeEvent(e,t),this.$emit("clear",{value:t,$event:e})},changeEvent:function(e,t){t!==this.value&&(this.$emit("input",t),this.$emit("change",{value:t,$event:e}),this.$xeform)&&this.$xeformiteminfo&&this.$xeform.triggerItemEvent(e,this.$xeformiteminfo.itemConfig.field,t)},mousedownOptionEvent:function(e){0===e.button&&e.stopPropagation()},changeOptionEvent:function(e,t,i){var n=this.value,o=this.multiple,l=this.remoteValueList;o?(o=n?-1===n.indexOf(t)?n.concat([t]):n.filter(function(e){return e!==t}):[t],(n=l.find(function(e){return e.key===t}))?n.result=i:l.push({key:t,result:i}),this.changeEvent(e,o)):(this.remoteValueList=[{key:t,result:i}],this.changeEvent(e,t),this.hideOptionPanel())},handleGlobalMousewheelEvent:function(e){var t=this.$refs,i=this.disabled,n=this.visiblePanel;i||n&&(_dom.default.getEventTargetNode(e,t.panel).flag?this.updatePlacement():this.hideOptionPanel())},handleGlobalMousedownEvent:function(e){var t=this.$refs,i=this.$el,n=this.disabled,o=this.visiblePanel;n||(this.isActivated=_dom.default.getEventTargetNode(e,i).flag||_dom.default.getEventTargetNode(e,t.panel).flag,o&&!this.isActivated&&this.hideOptionPanel())},handleGlobalKeydownEvent:function(e){var t,i,n,o,l,s,r,a=this.visiblePanel,u=this.currentValue,c=this.currentOption,f=this.clearable;this.disabled||(t=13===(r=e.keyCode),s=27===r,i=38===r,n=40===r,o=46===r,l=32===r,(r=9===r)&&(this.isActivated=!1),a?s||r?this.hideOptionPanel():t?(e.preventDefault(),e.stopPropagation(),this.changeOptionEvent(e,u,c)):i||n?(e.preventDefault(),s=(a=findOffsetOption(this,u,i)).firstOption,(r=a.offsetOption)||findOption(this,u)||(r=s),this.setCurrentOption(r),this.scrollToOption(r,n)):l&&e.preventDefault():(i||n||t||l)&&this.isActivated&&(e.preventDefault(),this.showOptionPanel()),this.isActivated&&o&&f&&this.clearValueEvent(e,null))},handleGlobalBlurEvent:function(){this.hideOptionPanel()},updateZindex:function(){this.panelIndex<_utils.default.getLastZIndex()&&(this.panelIndex=_utils.default.nextZIndex())},handleFocusSearch:function(){var e=this;this.filterable&&this.$nextTick(function(){e.$refs.inpSearch&&e.$refs.inpSearch.focus()})},focusEvent:function(e){this.disabled||(this.isActivated=!0),this.$emit("focus",{$event:e})},blurEvent:function(e){this.isActivated=!1,this.$emit("blur",{$event:e})},modelSearchEvent:function(e){this.searchValue=e},focusSearchEvent:function(){this.isActivated=!0},keydownSearchEvent:function(e){e=e.$event;(0,_event.hasEventKey)(e,_event.EVENT_KEYS.ENTER)&&(e.preventDefault(),e.stopPropagation())},triggerSearchEvent:_xeUtils.default.debounce(function(){var e=this,t=this.remote,i=this.remoteMethod,n=this.searchValue;t&&i?(this.searchLoading=!0,Promise.resolve(i({searchValue:n})).then(function(){return e.$nextTick()}).catch(function(){return e.$nextTick()}).finally(function(){e.searchLoading=!1,e.refreshOption()})):this.refreshOption()},350,{trailing:!0}),isPanelVisible:function(){return this.visiblePanel},togglePanel:function(){this.visiblePanel?this.hideOptionPanel():this.showOptionPanel(),this.$nextTick()},hidePanel:function(){this.visiblePanel&&this.hideOptionPanel(),this.$nextTick()},showPanel:function(){this.visiblePanel||this.showOptionPanel(),this.$nextTick()},togglePanelEvent:function(e){e.$event.preventDefault(),this.visiblePanel?this.hideOptionPanel():this.showOptionPanel()},showOptionPanel:function(){var i=this,e=this.loading,t=this.disabled,n=this.filterable;e||t||(this.searchList=this.option,clearTimeout(this.hidePanelTimeout),this.inited||(this.inited=!0,this.transfer&&document.body.appendChild(this.$refs.panel)),this.isActivated=!0,this.animatVisible=!0,n&&this.refreshOption(),setTimeout(function(){var e=i.value,t=i.multiple,t=findOption(i,t&&e?e[0]:e);i.visiblePanel=!0,t&&(i.setCurrentOption(t),i.scrollToOption(t)),i.handleFocusSearch()},10),this.updateZindex(),this.updatePlacement())},hideOptionPanel:function(){var e=this;this.searchValue="",this.searchLoading=!1,this.visiblePanel=!1,this.hidePanelTimeout=setTimeout(function(){e.animatVisible=!1,e.searchValue=""},350)},updatePlacement:function(){var p=this;return this.$nextTick().then(function(){var e,t,i,n,o,l,s,r=p.$refs,a=p.transfer,u=p.placement,c=p.panelIndex,f=r.input.$el,r=r.panel;if(r&&f)return e=f.offsetHeight,t=f.offsetWidth,i=r.offsetHeight,r=r.offsetWidth,c={zIndex:c},n=(f=_dom.default.getAbsolutePos(f)).boundingTop,s=f.boundingLeft,o=f.visibleHeight,f=f.visibleWidth,l="bottom",a?(a=n+e,"top"===u?(l="top",a=n-i):u||(o<a+i+5&&(l="top",a=n-i),a<5&&(l="bottom",a=n+e)),f<(s=s)+r+5&&(s-=s+r+5-f),s<5&&(s=5),Object.assign(c,{left:"".concat(s,"px"),top:"".concat(a,"px"),minWidth:"".concat(t,"px")})):"top"===u?(l="top",c.bottom="".concat(e,"px")):u||o<n+e+i&&5<n-e-i&&(l="top",c.bottom="".concat(e,"px")),p.panelStyle=c,p.panelPlacement=l,p.$nextTick()})},focus:function(){return this.isActivated=!0,this.$refs.input.focus(),this.$nextTick()},blur:function(){return this.hideOptionPanel(),this.$refs.input.blur(),this.$nextTick()}}};exports.default=_default2;