2 lines
19 KiB
JavaScript
2 lines
19 KiB
JavaScript
import{D as e,E as t,M as n,a as r,c as i,ct as a,d as o,h as s,i as c,j as l,l as u,m as d,ot as f,st as p,u as m,w as h}from"./_plugin-vue_export-helper-Conii5fq.js";import{c as g,o as _,s as v,t as y}from"./runtime-dom.esm-bundler-CI28bPhn.js";function b(e){return e===0?!1:Array.isArray(e)&&e.length===0?!0:!e}function x(e){return(...t)=>!e(...t)}function S(e,t){return e===void 0&&(e=`undefined`),e===null&&(e=`null`),e===!1&&(e=`false`),e.toString().toLowerCase().indexOf(t.trim())!==-1}function C(e){return e.filter(e=>!e.$isLabel)}function w(e,t){return n=>n.reduce((n,r)=>r[e]&&r[e].length?(n.push({$groupLabel:r[t],$isLabel:!0}),n.concat(r[e])):n,[])}var T=(...e)=>t=>e.reduce((e,t)=>t(e),t),E={name:`vue-multiselect`,mixins:[{data(){return{search:``,isOpen:!1,preferredOpenDirection:`below`,optimizedHeight:this.maxHeight}},props:{internalSearch:{type:Boolean,default:!0},options:{type:Array,required:!0},multiple:{type:Boolean,default:!1},trackBy:{type:String},label:{type:String},searchable:{type:Boolean,default:!0},clearOnSelect:{type:Boolean,default:!0},hideSelected:{type:Boolean,default:!1},placeholder:{type:String,default:`Select option`},allowEmpty:{type:Boolean,default:!0},resetAfter:{type:Boolean,default:!1},closeOnSelect:{type:Boolean,default:!0},customLabel:{type:Function,default(e,t){return b(e)?``:t?e[t]:e}},taggable:{type:Boolean,default:!1},tagPlaceholder:{type:String,default:`Press enter to create a tag`},tagPosition:{type:String,default:`top`},max:{type:[Number,Boolean],default:!1},id:{default:null},optionsLimit:{type:Number,default:1e3},groupValues:{type:String},groupLabel:{type:String},groupSelect:{type:Boolean,default:!1},blockKeys:{type:Array,default(){return[]}},preserveSearch:{type:Boolean,default:!1},preselectFirst:{type:Boolean,default:!1},preventAutofocus:{type:Boolean,default:!1},filteringSortFunc:{type:Function,default:null}},mounted(){!this.multiple&&this.max&&console.warn(`[Vue-Multiselect warn]: Max prop should not be used when prop Multiple equals false.`),this.preselectFirst&&!this.internalValue.length&&this.options.length&&this.select(this.filteredOptions[0])},computed:{internalValue(){return this.modelValue||this.modelValue===0?Array.isArray(this.modelValue)?this.modelValue:[this.modelValue]:[]},filteredOptions(){let e=this.search||``,t=e.toLowerCase().trim(),n=this.options.concat();return n=this.internalSearch?this.groupValues?this.filterAndFlat(n,t,this.label):this.filterOptions(n,t,this.label,this.customLabel):this.groupValues?w(this.groupValues,this.groupLabel)(n):n,n=this.hideSelected?n.filter(x(this.isSelected)):n,this.taggable&&t.length&&!this.isExistingOption(t)&&(this.tagPosition===`bottom`?n.push({isTag:!0,label:e}):n.unshift({isTag:!0,label:e})),n.slice(0,this.optionsLimit)},valueKeys(){return this.trackBy?this.internalValue.map(e=>e[this.trackBy]):this.internalValue},optionKeys(){return(this.groupValues?this.flatAndStrip(this.options):this.options).map(e=>this.customLabel(e,this.label).toString().toLowerCase())},currentOptionLabel(){return this.multiple?this.searchable?``:this.placeholder:this.internalValue.length?this.getOptionLabel(this.internalValue[0]):this.searchable?``:this.placeholder}},watch:{internalValue:{handler(){this.resetAfter&&this.internalValue.length&&(this.search=``,this.$emit(`update:modelValue`,this.multiple?[]:null))},deep:!0},search(){this.$emit(`search-change`,this.search)}},emits:[`open`,`search-change`,`close`,`select`,`update:modelValue`,`remove`,`tag`],methods:{getValue(){return this.multiple?this.internalValue:this.internalValue.length===0?null:this.internalValue[0]},filterAndFlat(e,t,n){return T(this.filterGroups(t,n,this.groupValues,this.groupLabel,this.customLabel),w(this.groupValues,this.groupLabel))(e)},flatAndStrip(e){return T(w(this.groupValues,this.groupLabel),C)(e)},updateSearch(e){this.search=e},isExistingOption(e){return this.options?this.optionKeys.indexOf(e)>-1:!1},isSelected(e){let t=this.trackBy?e[this.trackBy]:e;return this.valueKeys.indexOf(t)>-1},isOptionDisabled(e){return!!e.$isDisabled},getOptionLabel(e){if(b(e))return``;if(e.isTag)return e.label;if(e.$isLabel)return e.$groupLabel;let t=this.customLabel(e,this.label);return b(t)?``:t},select(e,t){if(e.$isLabel&&this.groupSelect){this.selectGroup(e);return}if(!(this.blockKeys.indexOf(t)!==-1||this.disabled||e.$isDisabled||e.$isLabel)&&!(this.max&&this.multiple&&this.internalValue.length===this.max)&&!(t===`Tab`&&!this.pointerDirty)){if(e.isTag)this.$emit(`tag`,e.label,this.id),this.search=``,this.closeOnSelect&&!this.multiple&&this.deactivate();else{if(this.isSelected(e)){t!==`Tab`&&this.removeElement(e);return}this.multiple?this.$emit(`update:modelValue`,this.internalValue.concat([e])):this.$emit(`update:modelValue`,e),this.$emit(`select`,e,this.id),this.clearOnSelect&&(this.search=``)}this.closeOnSelect&&this.deactivate()}},selectGroup(e){let t=this.options.find(t=>t[this.groupLabel]===e.$groupLabel);if(t){if(this.wholeGroupSelected(t)){this.$emit(`remove`,t[this.groupValues],this.id);let e=this.trackBy?t[this.groupValues].map(e=>e[this.trackBy]):t[this.groupValues],n=this.internalValue.filter(t=>e.indexOf(this.trackBy?t[this.trackBy]:t)===-1);this.$emit(`update:modelValue`,n)}else{let e=t[this.groupValues].filter(e=>!(this.isOptionDisabled(e)||this.isSelected(e)));this.max&&e.splice(this.max-this.internalValue.length),this.$emit(`select`,e,this.id),this.$emit(`update:modelValue`,this.internalValue.concat(e))}this.closeOnSelect&&this.deactivate()}},wholeGroupSelected(e){return e[this.groupValues].every(e=>this.isSelected(e)||this.isOptionDisabled(e))},wholeGroupDisabled(e){return e[this.groupValues].every(this.isOptionDisabled)},removeElement(e,t=!0){if(this.disabled||e.$isDisabled)return;if(!this.allowEmpty&&this.internalValue.length<=1){this.deactivate();return}let n=typeof e==`object`?this.valueKeys.indexOf(e[this.trackBy]):this.valueKeys.indexOf(e);if(this.multiple){let e=this.internalValue.slice(0,n).concat(this.internalValue.slice(n+1));this.$emit(`update:modelValue`,e)}else this.$emit(`update:modelValue`,null);this.$emit(`remove`,e,this.id),this.closeOnSelect&&t&&this.deactivate()},removeLastElement(){this.blockKeys.indexOf(`Delete`)===-1&&this.search.length===0&&Array.isArray(this.internalValue)&&this.internalValue.length&&this.removeElement(this.internalValue[this.internalValue.length-1],!1)},activate(){this.isOpen||this.disabled||(this.adjustPosition(),this.groupValues&&this.pointer===0&&this.filteredOptions.length&&(this.pointer=1),this.isOpen=!0,this.searchable?(this.preserveSearch||(this.search=``),this.preventAutofocus||this.$nextTick(()=>this.$refs.search&&this.$refs.search.focus())):this.preventAutofocus||this.$el!==void 0&&this.$el.focus(),this.$emit(`open`,this.id))},deactivate(){this.isOpen&&(this.isOpen=!1,this.searchable?this.$refs.search!==null&&this.$refs.search!==void 0&&this.$refs.search.blur():this.$el!==void 0&&this.$el.blur(),this.preserveSearch||(this.search=``),this.$emit(`close`,this.getValue(),this.id))},toggle(){this.isOpen?this.deactivate():this.activate()},adjustPosition(){if(typeof window>`u`)return;let e=this.$el.getBoundingClientRect().top,t=window.innerHeight-this.$el.getBoundingClientRect().bottom;t>this.maxHeight||t>e||this.openDirection===`below`||this.openDirection===`bottom`?(this.preferredOpenDirection=`below`,this.optimizedHeight=Math.min(t-40,this.maxHeight)):(this.preferredOpenDirection=`above`,this.optimizedHeight=Math.min(e-40,this.maxHeight))},filterOptions(e,t,n,r){return t?e.filter(e=>S(r(e,n),t)).sort((e,t)=>typeof this.filteringSortFunc==`function`?this.filteringSortFunc(e,t):r(e,n).length-r(t,n).length):e},filterGroups(e,t,n,r,i){return a=>a.map(a=>{if(!a[n])return console.warn(`Options passed to vue-multiselect do not contain groups, despite the config.`),[];let o=this.filterOptions(a[n],e,t,i);return o.length?{[r]:a[r],[n]:o}:[]})}}},{data(){return{pointer:0,pointerDirty:!1}},props:{showPointer:{type:Boolean,default:!0},optionHeight:{type:Number,default:40}},computed:{pointerPosition(){return this.pointer*this.optionHeight},visibleElements(){return this.optimizedHeight/this.optionHeight}},watch:{filteredOptions(){this.pointerAdjust()},isOpen(){this.pointerDirty=!1},pointer(){this.$refs.search&&this.$refs.search.setAttribute(`aria-activedescendant`,this.id+`-`+this.pointer.toString())}},methods:{optionHighlight(e,t){return{"multiselect__option--highlight":e===this.pointer&&this.showPointer,"multiselect__option--selected":this.isSelected(t)}},groupHighlight(e,t){if(!this.groupSelect)return[`multiselect__option--disabled`,{"multiselect__option--group":t.$isLabel}];let n=this.options.find(e=>e[this.groupLabel]===t.$groupLabel);return n&&!this.wholeGroupDisabled(n)?[`multiselect__option--group`,{"multiselect__option--highlight":e===this.pointer&&this.showPointer},{"multiselect__option--group-selected":this.wholeGroupSelected(n)}]:`multiselect__option--disabled`},addPointerElement({key:e}=`Enter`){this.filteredOptions.length>0&&this.select(this.filteredOptions[this.pointer],e),this.pointerReset()},pointerForward(){this.pointer<this.filteredOptions.length-1&&(this.pointer++,this.$refs.list?.scrollTop<=this.pointerPosition-(this.visibleElements-1)*this.optionHeight&&(this.$refs.list.scrollTop=this.pointerPosition-(this.visibleElements-1)*this.optionHeight),this.filteredOptions[this.pointer]&&this.filteredOptions[this.pointer].$isLabel&&!this.groupSelect&&this.pointerForward()),this.pointerDirty=!0},pointerBackward(){this.pointer>0?(this.pointer--,this.$refs.list?.scrollTop>=this.pointerPosition&&(this.$refs.list.scrollTop=this.pointerPosition),this.filteredOptions[this.pointer]&&this.filteredOptions[this.pointer].$isLabel&&!this.groupSelect&&this.pointerBackward()):this.filteredOptions[this.pointer]&&this.filteredOptions[0].$isLabel&&!this.groupSelect&&this.pointerForward(),this.pointerDirty=!0},pointerReset(){this.closeOnSelect&&(this.pointer=0,this.$refs.list&&(this.$refs.list.scrollTop=0))},pointerAdjust(){this.pointer>=this.filteredOptions.length-1&&(this.pointer=this.filteredOptions.length?this.filteredOptions.length-1:0),this.filteredOptions.length>0&&this.filteredOptions[this.pointer]&&this.filteredOptions[this.pointer].$isLabel&&!this.groupSelect&&this.pointerForward()},pointerSet(e){this.pointer=e,this.pointerDirty=!0}}}],compatConfig:{MODE:3,ATTR_ENUMERATED_COERCION:!1},props:{name:{type:String,default:``},modelValue:{type:null,default(){return[]}},selectLabel:{type:String,default:`Press enter to select`},selectGroupLabel:{type:String,default:`Press enter to select group`},selectedLabel:{type:String,default:`Selected`},deselectLabel:{type:String,default:`Press enter to remove`},deselectGroupLabel:{type:String,default:`Press enter to deselect group`},showLabels:{type:Boolean,default:!0},limit:{type:Number,default:99999},maxHeight:{type:Number,default:300},limitText:{type:Function,default:e=>`and ${e} more`},loading:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},spellcheck:{type:Boolean,default:!1},openDirection:{type:String,default:``},showNoOptions:{type:Boolean,default:!0},showNoResults:{type:Boolean,default:!0},tabindex:{type:Number,default:0},required:{type:Boolean,default:!1},useTeleport:{type:Boolean,default:!1},teleportTarget:{type:[String,Object],default:`body`},contentWrapperClass:{type:[String,Array,Object],default:``}},data(){return{dropdownStyles:{},ready:!1}},computed:{hasOptionGroup(){return this.groupValues&&this.groupLabel&&this.groupSelect},isSingleLabelVisible(){return(this.singleValue||this.singleValue===0)&&(!this.isOpen||!this.searchable)&&!this.visibleValues.length},isPlaceholderVisible(){return!this.internalValue.length&&(!this.searchable||!this.isOpen)},visibleValues(){return this.multiple?this.internalValue.slice(0,this.limit):[]},singleValue(){return this.internalValue[0]},deselectLabelText(){return this.showLabels?this.deselectLabel:``},deselectGroupLabelText(){return this.showLabels?this.deselectGroupLabel:``},selectLabelText(){return this.showLabels?this.selectLabel:``},selectGroupLabelText(){return this.showLabels?this.selectGroupLabel:``},selectedLabelText(){return this.showLabels?this.selectedLabel:``},inputStyle(){return this.searchable||this.multiple&&this.modelValue&&this.modelValue.length?this.isOpen?{width:`100%`}:{width:`0`,position:`absolute`,padding:`0`}:``},contentStyle(){return this.options.length?{display:`inline-block`}:{display:`block`}},isAbove(){return this.openDirection===`above`||this.openDirection===`top`?!0:this.openDirection===`below`||this.openDirection===`bottom`?!1:this.preferredOpenDirection===`above`},showSearchInput(){return this.searchable&&(this.hasSingleSelectedSlot&&(this.visibleSingleValue||this.visibleSingleValue===0)?this.isOpen:!0)},isRequired(){return this.required===!1?!1:this.internalValue.length<=0}},watch:{isOpen(e){e&&(this.useTeleport?(this.ready=!1,this.$nextTick(()=>{let e=this.$el.getBoundingClientRect();this.dropdownStyles={position:`absolute`,top:`${e.bottom+window.scrollY}px`,left:`${e.left+window.scrollX}px`,width:`${e.width}px`,zIndex:9999},this.ready=!0})):this.ready=!0)}}},D=[`tabindex`,`aria-expanded`,`aria-owns`,`aria-activedescendant`],O={ref:`tags`,class:`multiselect__tags`},k={class:`multiselect__tags-wrap`},A=[`textContent`],j=[`onKeydown`,`onMousedown`],M=[`textContent`],N={class:`multiselect__spinner`},P=[`name`,`id`,`spellcheck`,`placeholder`,`required`,`value`,`disabled`,`tabindex`,`aria-label`,`aria-controls`],F=[`id`,`aria-multiselectable`],I={key:0},L={class:`multiselect__option`},R=[`aria-selected`,`id`,`role`],z=[`onClick`,`onMouseenter`,`data-select`,`data-selected`,`data-deselect`],B=[`data-select`,`data-deselect`,`onMouseenter`,`onMousedown`],V={class:`multiselect__option`},H={class:`multiselect__option`};function U(b,x,S,C,w,T){return h(),o(`div`,{tabindex:b.searchable?-1:S.tabindex,class:f([{"multiselect--active":b.isOpen,"multiselect--disabled":S.disabled,"multiselect--above":T.isAbove,"multiselect--has-options-group":T.hasOptionGroup},`multiselect`]),onFocus:x[14]||=e=>b.activate(),onBlur:x[15]||=e=>b.searchable?!1:b.deactivate(),onKeydown:[x[16]||=v(g(e=>b.pointerForward(),[`self`,`prevent`]),[`down`]),x[17]||=v(g(e=>b.pointerBackward(),[`self`,`prevent`]),[`up`]),x[18]||=v(g(e=>b.addPointerElement(e),[`stop`,`self`]),[`enter`,`tab`])],onKeyup:x[19]||=v(e=>b.deactivate(),[`esc`]),role:`combobox`,"aria-expanded":b.isOpen,"aria-owns":`listbox-`+b.id,"aria-activedescendant":b.isOpen&&b.pointer!==null?b.id+`-`+b.pointer:null},[e(b.$slots,`caret`,{toggle:b.toggle},()=>[i(`div`,{onMousedown:x[0]||=g(e=>b.toggle(),[`prevent`,`stop`]),class:`multiselect__select`},null,32)]),e(b.$slots,`clear`,{search:b.search}),i(`div`,O,[e(b.$slots,`selection`,{search:b.search,remove:b.removeElement,values:T.visibleValues,isOpen:b.isOpen},()=>[n(i(`div`,k,[(h(!0),o(c,null,t(T.visibleValues,(t,n)=>e(b.$slots,`tag`,{option:t,search:b.search,remove:b.removeElement},()=>[(h(),o(`span`,{class:`multiselect__tag`,key:n,onMousedown:x[1]||=g(()=>{},[`prevent`])},[i(`span`,{textContent:a(b.getOptionLabel(t))},null,8,A),i(`i`,{tabindex:`1`,onKeydown:v(g(e=>b.removeElement(t),[`prevent`]),[`enter`]),onMousedown:g(e=>b.removeElement(t),[`prevent`]),class:`multiselect__tag-icon`},null,40,j)],32))])),256))],512),[[_,T.visibleValues.length>0]]),b.internalValue&&b.internalValue.length>S.limit?e(b.$slots,`limit`,{key:0},()=>[i(`strong`,{class:`multiselect__strong`,textContent:a(S.limitText(b.internalValue.length-S.limit))},null,8,M)]):m(`v-if`,!0)]),s(y,{name:`multiselect__loading`},{default:l(()=>[e(b.$slots,`loading`,{},()=>[n(i(`div`,N,null,512),[[_,S.loading]])])]),_:3}),b.searchable?(h(),o(`input`,{key:0,ref:`search`,name:S.name,id:b.id,type:`text`,autocomplete:`off`,spellcheck:S.spellcheck,placeholder:b.placeholder,required:T.isRequired,style:p(T.inputStyle),value:b.search,disabled:S.disabled,tabindex:S.tabindex,"aria-label":S.name+`-searchbox`,onInput:x[2]||=e=>b.updateSearch(e.target.value),onFocus:x[3]||=g(e=>b.activate(),[`prevent`]),onBlur:x[4]||=g(e=>b.deactivate(),[`prevent`]),onKeyup:x[5]||=v(e=>b.deactivate(),[`esc`]),onKeydown:[x[6]||=v(g(e=>b.pointerForward(),[`prevent`]),[`down`]),x[7]||=v(g(e=>b.pointerBackward(),[`prevent`]),[`up`]),x[8]||=v(g(e=>b.addPointerElement(e),[`prevent`,`stop`,`self`]),[`enter`]),x[9]||=v(g(e=>b.removeLastElement(),[`stop`]),[`delete`])],class:`multiselect__input`,"aria-controls":`listbox-`+b.id},null,44,P)):m(`v-if`,!0),T.isSingleLabelVisible?(h(),o(`span`,{key:1,class:`multiselect__single`,onMousedown:x[10]||=g((...e)=>b.toggle&&b.toggle(...e),[`prevent`])},[e(b.$slots,`singleLabel`,{option:T.singleValue},()=>[d(a(b.currentOptionLabel),1)])],32)):m(`v-if`,!0),T.isPlaceholderVisible?(h(),o(`span`,{key:2,class:`multiselect__placeholder`,onMousedown:x[11]||=g((...e)=>b.toggle&&b.toggle(...e),[`prevent`])},[e(b.$slots,`placeholder`,{},()=>[d(a(b.placeholder),1)])],32)):m(`v-if`,!0)],512),(h(),u(r,{to:S.teleportTarget,disabled:!S.useTeleport},[s(y,{name:`multiselect`},{default:l(()=>[b.isOpen&&w.ready?(h(),o(`div`,{key:0,class:f([`multiselect__content-wrapper`,S.contentWrapperClass]),onFocus:x[12]||=(...e)=>b.activate&&b.activate(...e),tabindex:`-1`,onMousedown:x[13]||=g(()=>{},[`prevent`]),style:p([w.dropdownStyles,{maxHeight:b.optimizedHeight+`px`}]),ref:`list`},[i(`ul`,{class:`multiselect__content`,style:p(T.contentStyle),role:`listbox`,id:`listbox-`+b.id,"aria-multiselectable":b.multiple},[e(b.$slots,`beforeList`),b.multiple&&b.max===b.internalValue.length?(h(),o(`li`,I,[i(`span`,L,[e(b.$slots,`maxElements`,{},()=>[d(`Maximum of `+a(b.max)+` options selected. First remove a selected option to select another.`,1)])])])):m(`v-if`,!0),!b.max||b.internalValue.length<b.max?(h(!0),o(c,{key:1},t(b.filteredOptions,(t,n)=>(h(),o(`li`,{class:`multiselect__element`,key:n,"aria-selected":b.isSelected(t),id:b.id+`-`+n,role:t&&(t.$isLabel||t.$isDisabled)?null:`option`},[t&&(t.$isLabel||t.$isDisabled)?m(`v-if`,!0):(h(),o(`span`,{key:0,class:f([b.optionHighlight(n,t),`multiselect__option`]),onClick:g(e=>b.select(t),[`stop`]),onMouseenter:g(e=>b.pointerSet(n),[`self`]),"data-select":t&&t.isTag?b.tagPlaceholder:T.selectLabelText,"data-selected":T.selectedLabelText,"data-deselect":T.deselectLabelText},[e(b.$slots,`option`,{option:t,search:b.search,index:n},()=>[i(`span`,null,a(b.getOptionLabel(t)),1)])],42,z)),t&&(t.$isLabel||t.$isDisabled)?(h(),o(`span`,{key:1,"data-select":b.groupSelect&&T.selectGroupLabelText,"data-deselect":b.groupSelect&&T.deselectGroupLabelText,class:f([b.groupHighlight(n,t),`multiselect__option`]),onMouseenter:g(e=>b.groupSelect&&b.pointerSet(n),[`self`]),onMousedown:g(e=>b.selectGroup(t),[`prevent`])},[e(b.$slots,`option`,{option:t,search:b.search,index:n},()=>[i(`span`,null,a(b.getOptionLabel(t)),1)])],42,B)):m(`v-if`,!0)],8,R))),128)):m(`v-if`,!0),n(i(`li`,null,[i(`span`,V,[e(b.$slots,`noResult`,{search:b.search},()=>[x[20]||=d(`No elements found. Consider changing the search query.`)])])],512),[[_,S.showNoResults&&b.filteredOptions.length===0&&b.search&&!S.loading]]),n(i(`li`,null,[i(`span`,H,[e(b.$slots,`noOptions`,{},()=>[x[21]||=d(`List is empty.`)])])],512),[[_,S.showNoOptions&&b.filteredOptions.length===0&&!b.search&&!S.loading]]),e(b.$slots,`afterList`)],12,F)],38)):m(`v-if`,!0)]),_:3})],8,[`to`,`disabled`]))],42,D)}E.render=U;export{E as t};
|
|
//# sourceMappingURL=vue-multiselect.esm-bMCye0Qz.js.map
|