@vueform/multiselect
Advanced tools
Comparing version 1.3.7 to 1.4.0
@@ -0,1 +1,9 @@ | ||
## v1.4.0 | ||
> `2021-04-06` | ||
### 🎉 Feature | ||
- **BREAKING**: array `options` are no longer treated as objects, but both option value and label will equal to array item value. Eg. `option: ['v1','v2']` used to be equal to `{0: 'v1', 1: 'v2'}`, now they're equal to `{v1: 'v1', v2: 'v2'}`. | ||
- Optimized variable names for lower package size. | ||
## v1.3.7 | ||
@@ -2,0 +10,0 @@ |
@@ -1,1 +0,1 @@ | ||
var VueformMultiselect=function(e,t){"use strict";function l(e){return-1!==[null,void 0,!1].indexOf(e)}function n(e){return(n="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 a(e,t,l){return t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l,e}function r(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var l=Object.prototype.toString.call(e).slice(8,-1);"Object"===l&&e.constructor&&(l=e.constructor.name);if("Map"===l||"Set"===l)return Array.from(e);if("Arguments"===l||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(l))return u(e,t)}(e)||function(){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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var l=0,n=new Array(t);l<t;l++)n[l]=e[l];return n}function o(e){return String(e).toLowerCase().trim()}var i={};function c(t,r,u){var c=e.toRefs(t),s=c.options,d=c.mode,v=c.trackBy,p=c.limit,f=c.hideSelected,h=c.createTag,m=c.label,y=c.appendNewTag,g=c.multipleLabel,b=c.object,w=c.loading,S=c.delay,k=c.resolveOnLoad,V=c.minChars,O=c.filterResults,B=c.clearOnSearch,N=c.clearOnSelect,x=c.valueProp,q=c.canDeselect,T=c.max,M=u.internalValue,P=u.externalValue,C=u.currentValue,D=u.search,I=u.blurSearch,K=u.clearSearch,A=u.update,j=u.blurInput,R=u.pointer,E=e.ref([]),$=e.ref([]),L=e.ref(!1),H=e.computed((function(){var e,t=$.value||[];return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(t=Object.keys(t).map((function(e){var l,n=t[e];return a(l={},x.value,e),a(l,v.value,n),a(l,m.value,n),l}))),t=t.map((function(e,t){var l;return"object"===n(e)?e:(a(l={},x.value,t),a(l,v.value,e),a(l,m.value,e),l)})),E.value.length&&(t=t.concat(E.value)),t})),F=e.computed((function(){var e=H.value;return z.value.length&&(e=z.value.concat(e)),D.value&&O.value&&(e=e.filter((function(e){return-1!==o(e[v.value]).indexOf(o(D.value))}))),f.value&&(e=e.filter((function(e){return!oe(e)}))),p.value>0&&(e=e.slice(0,p.value)),e})),J=e.computed((function(){switch(d.value){case"single":return!l(M.value[x.value]);case"multiple":case"tags":return!l(M.value)&&M.value.length>0}})),_=e.computed((function(){return void 0!==g&&void 0!==g.value?g.value(M.value):M.value&&M.value.length>1?"".concat(M.value.length," options selected"):"1 option selected"})),W=e.computed((function(){return!H.value.length&&!L.value})),U=e.computed((function(){return H.value.length>0&&0==F.value.length})),z=e.computed((function(){var e;return!1!==h.value&&D.value?-1!==ue(D.value)?[]:[(e={},a(e,x.value,D.value),a(e,m.value,D.value),a(e,v.value,D.value),e)]:[]})),G=e.computed((function(){switch(d.value){case"single":return null;case"multiple":case"tags":return[]}})),Q=e.computed((function(){return w.value||L.value})),X=function(e){switch("object"!==n(e)&&(e=re(e)),d.value){case"single":A(e);break;case"multiple":case"tags":A(M.value.concat(e))}r.emit("select",Z(e))},Y=function(e){switch("object"!==n(e)&&(e=re(e)),d.value){case"single":te();break;case"tags":case"multiple":A(M.value.filter((function(t){return t[x.value]!=e[x.value]})))}r.emit("deselect",Z(e))},Z=function(e){return b.value?e:e[x.value]},ee=function(e){Y(e)},te=function(){A(G.value)},le=function(e){switch(d.value){case"single":return!l(M.value)&&M.value[x.value]==e[x.value];case"tags":case"multiple":return!l(M.value)&&-1!==M.value.map((function(e){return e[x.value]})).indexOf(e[x.value])}},ne=function(e){return!0===e.disabled},ae=function(){return!(void 0===T||-1===T.value||!J.value&&T.value>0)&&M.value.length>=T.value},re=function(e){return H.value[H.value.map((function(e){return String(e[x.value])})).indexOf(String(e))]},ue=function(e){return H.value.map((function(e){return o(e[v.value])})).indexOf(o(e))},oe=function(e){return"tags"===d.value&&f.value&&le(e)},ie=function(e){E.value.push(e)},ce=function(){l(P.value)||(M.value=de(P.value))},se=function(e){L.value=!0,s.value(D.value).then((function(t){$.value=t,"function"==typeof e&&e(t),L.value=!1}))},de=function(e){return l(e)?"single"===d.value?{}:[]:b.value?e:"single"===d.value?re(e)||{}:e.filter((function(e){return!!re(e)})).map((function(e){return re(e)}))};if("single"!==d.value&&!l(P.value)&&!Array.isArray(P.value))throw new Error('v-model must be an array when using "'.concat(d.value,'" mode'));return s&&"function"==typeof s.value?k.value?se(ce):1==b.value&&ce():($.value=s.value,ce()),S.value>-1&&e.watch(D,(function(e){e.length<V.value||(L.value=!0,B.value&&($.value=[]),setTimeout((function(){e==D.value&&s.value(D.value).then((function(t){e==D.value&&($.value=t,R.value=F.value.filter((function(e){return!0!==e.disabled}))[0]||null,L.value=!1)}))}),S.value))}),{flush:"sync"}),e.watch(P,(function(e){var t,n,a;if(l(e))M.value=de(e);else switch(d.value){case"single":(b.value?e[x.value]!=M.value[x.value]:e!=M.value[x.value])&&(M.value=de(e));break;case"multiple":case"tags":t=b.value?e.map((function(e){return e[x.value]})):e,n=M.value.map((function(e){return e[x.value]})),a=n.slice().sort(),t.length===n.length&&t.slice().sort().every((function(e,t){return e===a[t]}))||(M.value=de(e))}}),{deep:!0}),"function"!=typeof t.options&&(e.watch((function(){return t.options}),(function(e,l){$.value=t.options})),e.watch(H,(function(e,t){if(Object.keys(M.value).length||ce(),e.length&&C.value&&C.value.length){var l;if("single"===d.value){if(l=e[e.map((function(e){return e[x.value]})).indexOf(C.value)],JSON.stringify(l)===JSON.stringify(M.value))return}else if(l=[],C.value.forEach((function(t){l.push(e[e.map((function(e){return e[x.value]})).indexOf(t)])})),function(e,t){var l=e.length===t.length;if(!l)return l;try{e.every((function(e,l){if(JSON.stringify(e)!==JSON.stringify(t[l]))throw i}))}catch(e){if(e!==i)throw e;l=!1}return l}(l,M.value))return;b.value?A(l):M.value=l}}),{flush:"sync",deep:!0,immediate:!1})),{filteredOptions:F,hasSelected:J,multipleLabelText:_,extendedOptions:H,noOptions:W,noResults:U,resolving:L,busy:Q,select:X,deselect:Y,remove:ee,clear:te,isSelected:le,isDisabled:ne,isMax:ae,getOption:re,handleOptionClick:function(e){if(!ne(e))switch(d.value){case"single":if(le(e))return void(q.value&&Y(e));X(e),I(),j();break;case"multiple":if(le(e))return void Y(e);if(ae())return;X(e),N.value&&K();break;case"tags":if(le(e))return void Y(e);if(ae())return;void 0===re(e[x.value])&&h.value&&(r.emit("tag",e[x.value]),y.value&&ie(e),K()),N.value&&K(),X(e)}},handleTagRemove:function(e,t){0===t.button?ee(e):t.preventDefault()},refreshOptions:function(e){se(e)},resolveOptions:se}}var s={name:"Multiselect",emits:["open","close","select","deselect","input","search-change","tag","update:modelValue","change"],props:{value:{required:!1},modelValue:{required:!1},options:{type:[Array,Object,Function],required:!1,default:()=>[]},id:{type:[String,Number],required:!1,default:"multiselect"},name:{type:[String,Number],required:!1,default:"multiselect"},disabled:{type:Boolean,required:!1,default:!1},label:{type:String,required:!1,default:"label"},trackBy:{type:String,required:!1,default:"label"},valueProp:{type:String,required:!1,default:"value"},placeholder:{type:String,required:!1,default:null},mode:{type:String,required:!1,default:"single"},searchable:{type:Boolean,required:!1,default:!1},limit:{type:Number,required:!1,default:-1},maxHeight:{type:Number,required:!1,default:160},hideSelected:{type:Boolean,required:!1,default:!0},createTag:{type:Boolean,required:!1,default:!1},appendNewTag:{type:Boolean,required:!1,default:!0},caret:{type:Boolean,required:!1,default:!0},loading:{type:Boolean,required:!1,default:!1},noOptionsText:{type:String,required:!1,default:"The list is empty"},noResultsText:{type:String,required:!1,default:"No results found"},multipleLabel:{type:Function,required:!1},object:{type:Boolean,required:!1,default:!1},delay:{type:Number,required:!1,default:-1},minChars:{type:Number,required:!1,default:0},resolveOnLoad:{type:Boolean,required:!1,default:!0},filterResults:{type:Boolean,required:!1,default:!0},clearOnSearch:{type:Boolean,required:!1,default:!1},clearOnSelect:{type:Boolean,required:!1,default:!0},canDeselect:{type:Boolean,required:!1,default:!0},max:{type:Number,required:!1,default:-1},showOptions:{type:Boolean,required:!1,default:!0},addTagOn:{type:Array,required:!1,default:()=>["enter"]},required:{type:Boolean,required:!1,default:!1}},setup(t,n){const a=function(t,l){var n=e.toRefs(t),a=n.value,r=n.modelValue,u=n.mode,o=n.valueProp,i=e.ref("single"!==u.value?[]:{}),c=void 0!==l.expose?r:a,s=e.computed((function(){return Object.keys(i.value).length?"single"!==u.value?i.value.map((function(e){return e[o.value]})):i.value[o.value]:i.value})),d=e.computed((function(){return"single"!==u.value?i.value.map((function(e){return e[o.value]})).join(","):i.value[o.value]}));return{internalValue:i,externalValue:c,currentValue:s,textValue:d}}(t,n),u=function(t,l,n){var a=e.toRefs(t),r=a.searchable,u=(a.id,e.ref(null)),o=e.computed((function(){return r.value?-1:0}));return{multiselect:u,tabindex:o,focusInput:function(){u.value.querySelector(".multiselect-input").focus()},blurInput:function(){u.value.querySelector(".multiselect-input").blur()}}}(t),o={pointer:e.ref(null)},i=function(t,n,a){var r=e.toRefs(t),u=r.object,o=r.valueProp,i=r.mode,c=a.internalValue,s=function(e){return u.value||l(e)?e:Array.isArray(e)?e.map((function(e){return e[o.value]})):e[o.value]},d=function(e){return l(e)?"single"===i.value?{}:[]:e};return{update:function(e){c.value=d(e);var t=s(e);n.emit("change",t),n.emit("input",t),n.emit("update:modelValue",t)}}}(t,n,{internalValue:a.internalValue}),s=function(t,l,n){var a=e.toRefs(t),r=a.searchable,u=a.mode,o=n.internalValue,i=e.ref(null),c=e.ref(null),s=e.computed((function(){return i.value?"".concat(i.value.length,"ch"):"tags"===u.value&&-1===[null,void 0].indexOf(o.value)&&o.value.length?"1ch":"100%"}));return e.watch(i,(function(e){l.emit("search-change",e)})),{search:i,input:c,tagsSearchWidth:s,clearSearch:function(){i.value=""},focusSearch:function(){c.value.focus()},blurSearch:function(){r.value&&c.value.blur()}}}(t,n,{internalValue:a.internalValue}),d=function(t,l,n){var a=e.toRefs(t),r=a.maxHeight,u=a.disabled,o=a.searchable,i=n.multiselect,c=n.blurInput,s=n.blurSearch,d=n.focusInput,v=n.focusSearch,p=e.ref(!1),f=e.computed((function(){return"".concat(r.value,"px")}));return{isOpen:p,contentMaxHeight:f,openDropdown:function(){u.value||(p.value=!0,l.emit("open"))},closeDropdown:function(){p.value=!1,l.emit("close")},open:function(){o&&o.value?v():d()},close:function(){o&&o.value?s():c()},handleInputMousedown:function(e){p.value&&!o.value&&(i.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),i.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(t,n,{multiselect:u.multiselect,blurInput:u.blurInput,blurSearch:s.blurSearch,focusInput:u.focusInput,focusSearch:s.focusSearch}),v=c(t,n,{externalValue:a.externalValue,internalValue:a.internalValue,currentValue:a.currentValue,search:s.search,blurSearch:s.blurSearch,clearSearch:s.clearSearch,update:i.update,blurInput:u.blurInput,pointer:o.pointer}),p=function(t,l,n){var a=e.toRefs(t),r=a.id,u=a.valueProp,o=n.filteredOptions,i=n.handleOptionClick,c=n.search,s=n.pointer,d=e.computed((function(){return o.value.filter((function(e){return!0!==e.disabled}))})),v=function(e){s.value=e},p=function(){s.value=d.value[0]||null},f=function(){s.value=null},h=function(){var e=document.getElementById(r.value).querySelector(".is-pointed");if(e){var t=e.parentElement;e.offsetTop+e.offsetHeight>t.clientHeight+t.scrollTop&&(t.scrollTop=e.offsetTop+e.offsetHeight-t.clientHeight),e.offsetTop<t.scrollTop&&(t.scrollTop=e.offsetTop)}};return e.watch(c,(function(e){p()})),{pointer:s,isPointed:function(e){return!!s.value&&s.value[u.value]==e[u.value]},setPointer:v,setPointerFirst:p,clearPointer:f,selectPointer:function(){s.value&&!0!==s.value.disabled?(i(s.value),f()):f()},forwardPointer:function(){if(null===s.value)v(d.value[0]||null);else{var t=d.value.map((function(e){return e[u.value]})).indexOf(s.value[u.value])+1;d.value.length<=t&&(t=0),v(d.value[t]||null)}e.nextTick((function(){h()}))},backwardPointer:function(){if(null===s.value)v(d.value[d.value.length-1]||null);else{var t=d.value.map((function(e){return e[u.value]})).indexOf(s.value[u.value])-1;t<0&&(t=d.value.length-1),v(d.value[t]||null)}e.nextTick((function(){h()}))}}}(t,0,{filteredOptions:v.filteredOptions,handleOptionClick:v.handleOptionClick,search:s.search,pointer:o.pointer}),f=function(t,l,n){var a=e.toRefs(t),u=a.mode,o=a.addTagOn,i=a.createTag,c=n.internalValue,s=n.update,d=n.closeDropdown,v=n.clearPointer,p=n.search,f=n.selectPointer;return{handleBackspace:function(e){"single"!==u.value&&s(r(c.value).slice(0,-1))},handleEsc:function(e){d(),v(),e.target.blur()},handleSearchBackspace:function(e){""!==p.value&&e.stopPropagation()},handleSearchInput:function(e){p.value=e.target.value},handleAddTag:function(t){13!==t.keyCode||-1===o.value.indexOf("enter")&&i.value?32===t.keyCode&&-1!==o.value.indexOf("space")&&i.value&&(p.value=p.value.trim(),e.nextTick((function(){f()}))):f()}}}(t,0,{internalValue:a.internalValue,update:i.update,closeDropdown:d.closeDropdown,clearPointer:p.clearPointer,search:s.search,selectPointer:p.selectPointer});return{...a,...d,...u,...o,...i,...s,...v,...p,...f}}};const d={class:"multiselect-single-label"},v={class:"multiselect-multiple-label"},p={key:2,class:"multiselect-search"},f={key:3,class:"multiselect-tags"},h={class:"multiselect-tag"},m={class:"multiselect-placeholder"},y=t.createVNode("span",{class:"multiselect-caret"},null,-1),g={key:0},b=t.createVNode("span",{class:"multiselect-spinner"},null,-1),w={class:"multiselect-no-options"},S={class:"multiselect-no-results"};return s.render=function(e,l,n,a,r,u){return t.openBlock(),t.createBlock("div",{class:["multiselect",[`is-${n.mode}`,{"is-open":e.isOpen,"is-searchable":n.searchable,"is-disabled":n.disabled,"no-caret":!n.caret}]],id:n.id,onKeydown:l[29]||(l[29]=t.withKeys(t.withModifiers((()=>{}),["prevent"]),["enter"])),ref:"multiselect"},[t.createVNode("div",{class:"multiselect-input",tabindex:e.tabindex,onMousedown:l[20]||(l[20]=(...t)=>e.handleInputMousedown&&e.handleInputMousedown(...t)),onFocus:l[21]||(l[21]=(...t)=>e.openDropdown&&e.openDropdown(...t)),onBlur:l[22]||(l[22]=(...t)=>e.closeDropdown&&e.closeDropdown(...t)),onKeyup:[l[23]||(l[23]=t.withKeys(((...t)=>e.handleEsc&&e.handleEsc(...t)),["esc"])),l[24]||(l[24]=t.withKeys(((...t)=>e.selectPointer&&e.selectPointer(...t)),["enter"]))],onKeydown:[l[25]||(l[25]=t.withKeys(t.withModifiers(((...t)=>e.handleBackspace&&e.handleBackspace(...t)),["prevent"]),["delete"])),l[26]||(l[26]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["prevent"]),["up"])),l[27]||(l[27]=t.withKeys(t.withModifiers(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["prevent"]),["down"]))]},[t.createCommentVNode(" Single label "),"single"==n.mode&&e.hasSelected&&!e.search&&e.internalValue?t.renderSlot(e.$slots,"singlelabel",{key:0,value:e.internalValue},(()=>[t.createVNode("div",d,t.toDisplayString(e.internalValue[n.label]),1)])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Multiple label "),"multiple"==n.mode&&e.hasSelected&&!e.search?t.renderSlot(e.$slots,"multiplelabel",{key:1,values:e.internalValue},(()=>[t.createVNode("div",v,t.toDisplayString(e.multipleLabelText),1)])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Search "),"tags"!==n.mode&&n.searchable&&!n.disabled?(t.openBlock(),t.createBlock("div",p,[t.createVNode("input",{modelValue:e.search,value:e.search,onFocus:l[1]||(l[1]=t.withModifiers(((...t)=>e.openDropdown&&e.openDropdown(...t)),["stop"])),onBlur:l[2]||(l[2]=t.withModifiers(((...t)=>e.closeDropdown&&e.closeDropdown(...t)),["stop"])),onKeyup:[l[3]||(l[3]=t.withKeys(t.withModifiers(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),l[4]||(l[4]=t.withKeys(t.withModifiers(((...t)=>e.selectPointer&&e.selectPointer(...t)),["stop"]),["enter"]))],onKeydown:[l[5]||(l[5]=t.withKeys(((...t)=>e.handleSearchBackspace&&e.handleSearchBackspace(...t)),["delete"])),l[6]||(l[6]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["stop"]),["up"])),l[7]||(l[7]=t.withKeys(t.withModifiers(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["stop"]),["down"]))],onInput:l[8]||(l[8]=(...t)=>e.handleSearchInput&&e.handleSearchInput(...t)),ref:"input"},null,40,["modelValue","value"])])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Tags (with search) "),"tags"==n.mode?(t.openBlock(),t.createBlock("div",f,[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.internalValue,((a,r,u)=>(t.openBlock(),t.createBlock("span",{key:u},[t.renderSlot(e.$slots,"tag",{option:a,handleTagRemove:e.handleTagRemove,disabled:n.disabled},(()=>[t.createVNode("div",h,[t.createTextVNode(t.toDisplayString(a[n.label])+" ",1),n.disabled?t.createCommentVNode("v-if",!0):(t.openBlock(),t.createBlock("i",{key:0,onClick:l[9]||(l[9]=t.withModifiers((()=>{}),["prevent"])),onMousedown:t.withModifiers((t=>e.handleTagRemove(a,t)),["prevent","stop"])},null,40,["onMousedown"]))])]))])))),128)),n.searchable&&!n.disabled?(t.openBlock(),t.createBlock("div",{key:0,class:"multiselect-search",style:{width:e.tagsSearchWidth}},[t.createVNode("input",{modelValue:e.search,value:e.search,onFocus:l[10]||(l[10]=t.withModifiers(((...t)=>e.openDropdown&&e.openDropdown(...t)),["stop"])),onBlur:l[11]||(l[11]=t.withModifiers(((...t)=>e.closeDropdown&&e.closeDropdown(...t)),["stop"])),onKeyup:[l[12]||(l[12]=t.withKeys(t.withModifiers(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),l[13]||(l[13]=t.withKeys(t.withModifiers(((...t)=>e.handleAddTag&&e.handleAddTag(...t)),["stop"]),["enter"])),l[14]||(l[14]=t.withKeys(t.withModifiers(((...t)=>e.handleAddTag&&e.handleAddTag(...t)),["stop"]),["space"]))],onKeydown:[l[15]||(l[15]=t.withKeys(((...t)=>e.handleSearchBackspace&&e.handleSearchBackspace(...t)),["delete"])),l[16]||(l[16]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["stop"]),["up"])),l[17]||(l[17]=t.withKeys(t.withModifiers(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["stop"]),["down"]))],onInput:l[18]||(l[18]=(...t)=>e.handleSearchInput&&e.handleSearchInput(...t)),style:{width:e.tagsSearchWidth},ref:"input"},null,44,["modelValue","value"])],4)):t.createCommentVNode("v-if",!0)])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Placeholder "),!n.placeholder||e.hasSelected||e.search?t.createCommentVNode("v-if",!0):t.renderSlot(e.$slots,"placeholder",{key:4},(()=>[t.createVNode("div",m,t.toDisplayString(n.placeholder),1)])),n.caret&&!e.busy?t.renderSlot(e.$slots,"caret",{key:5},(()=>[y])):t.createCommentVNode("v-if",!0),t.createVNode(t.Transition,{name:"multiselect-loading"},{default:t.withCtx((()=>[e.busy?(t.openBlock(),t.createBlock("span",g,[t.renderSlot(e.$slots,"spinner",{},(()=>[b]))])):t.createCommentVNode("v-if",!0)])),_:1}),e.hasSelected&&!n.disabled?t.renderSlot(e.$slots,"clear",{key:6,clear:e.clear},(()=>[t.createVNode("a",{class:"multiselect-clear",onClick:l[19]||(l[19]=t.withModifiers(((...t)=>e.clear&&e.clear(...t)),["prevent"]))})])):t.createCommentVNode("v-if",!0)],40,["tabindex"]),t.createCommentVNode(" Options "),e.resolving&&n.clearOnSearch?t.createCommentVNode("v-if",!0):(t.openBlock(),t.createBlock(t.Transition,{key:0,name:"multiselect",onAfterLeave:e.clearSearch},{default:t.withCtx((()=>[t.withDirectives(t.createVNode("div",{class:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[t.renderSlot(e.$slots,"beforelist"),(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.filteredOptions,((a,r,u)=>(t.openBlock(),t.createBlock("span",{tabindex:-1,class:["multiselect-option",{"is-pointed":e.isPointed(a),"is-selected":e.isSelected(a),"is-disabled":e.isDisabled(a)}],key:u,onMousedown:l[28]||(l[28]=t.withModifiers((()=>{}),["prevent"])),onMouseenter:t=>e.setPointer(a),onClick:t.withModifiers((t=>e.handleOptionClick(a)),["stop","prevent"])},[t.renderSlot(e.$slots,"option",{option:a,search:e.search},(()=>[t.createVNode("span",null,t.toDisplayString(a[n.label]),1)]))],42,["onMouseenter","onClick"])))),128)),t.withDirectives(t.createVNode("span",null,[t.renderSlot(e.$slots,"nooptions",{},(()=>[t.createVNode("div",w,t.toDisplayString(n.noOptionsText),1)]))],512),[[t.vShow,e.noOptions]]),t.withDirectives(t.createVNode("span",null,[t.renderSlot(e.$slots,"noresults",{},(()=>[t.createVNode("div",S,t.toDisplayString(n.noResultsText),1)]))],512),[[t.vShow,e.noResults]]),t.renderSlot(e.$slots,"afterlist")],4),[[t.vShow,e.isOpen&&n.showOptions]])])),_:3},8,["onAfterLeave"])),t.createCommentVNode(" Hacky input element to show HTML5 required warning "),n.required?(t.openBlock(),t.createBlock("input",{key:1,class:"multiselect-fake-input",tabindex:"-1",value:e.textValue,required:""},null,8,["value"])):t.createCommentVNode("v-if",!0)],42,["id"])},s.__file="src/Multiselect.vue",s}(Vue,Vue); | ||
var VueformMultiselect=function(e,t){"use strict";function l(e){return-1!==[null,void 0,!1].indexOf(e)}function n(e){return(n="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 a(e,t,l){return t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l,e}function r(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var l=Object.prototype.toString.call(e).slice(8,-1);"Object"===l&&e.constructor&&(l=e.constructor.name);if("Map"===l||"Set"===l)return Array.from(e);if("Arguments"===l||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(l))return u(e,t)}(e)||function(){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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var l=0,n=new Array(t);l<t;l++)n[l]=e[l];return n}function o(e){return String(e).toLowerCase().trim()}function i(t,r,u){var i=e.toRefs(t),c=i.options,s=i.mode,d=i.trackBy,v=i.limit,p=i.hideSelected,f=i.createTag,h=i.label,m=i.appendNewTag,y=i.multipleLabel,g=i.object,b=i.loading,w=i.delay,S=i.resolveOnLoad,k=i.minChars,B=i.filterResults,V=i.clearOnSearch,N=i.clearOnSelect,O=i.valueProp,q=i.canDeselect,T=i.max,x=u.iv,M=u.ev,P=u.search,C=u.blurSearch,D=u.clearSearch,I=u.update,K=u.blurInput,A=u.pointer,j=e.ref([]),R=e.ref([]),E=e.ref(!1),$=e.computed((function(){var e,t=R.value||[];return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(t=Object.keys(t).map((function(e){var l,n=t[e];return a(l={},O.value,e),a(l,d.value,n),a(l,h.value,n),l}))),t=t.map((function(e,t){var l;return"object"===n(e)?e:(a(l={},O.value,e),a(l,d.value,e),a(l,h.value,e),l)})),j.value.length&&(t=t.concat(j.value)),t})),L=e.computed((function(){var e=$.value;return U.value.length&&(e=U.value.concat(e)),P.value&&B.value&&(e=e.filter((function(e){return-1!==o(e[d.value]).indexOf(o(P.value))}))),p.value&&(e=e.filter((function(e){return!re(e)}))),v.value>0&&(e=e.slice(0,v.value)),e})),H=e.computed((function(){switch(s.value){case"single":return!l(x.value[O.value]);case"multiple":case"tags":return!l(x.value)&&x.value.length>0}})),F=e.computed((function(){return void 0!==y&&void 0!==y.value?y.value(x.value):x.value&&x.value.length>1?"".concat(x.value.length," options selected"):"1 option selected"})),_=e.computed((function(){return!$.value.length&&!E.value})),W=e.computed((function(){return $.value.length>0&&0==L.value.length})),U=e.computed((function(){var e;return!1!==f.value&&P.value?-1!==ae(P.value)?[]:[(e={},a(e,O.value,P.value),a(e,h.value,P.value),a(e,d.value,P.value),e)]:[]})),z=e.computed((function(){switch(s.value){case"single":return null;case"multiple":case"tags":return[]}})),G=e.computed((function(){return b.value||E.value})),J=function(e){switch("object"!==n(e)&&(e=ne(e)),s.value){case"single":I(e);break;case"multiple":case"tags":I(x.value.concat(e))}r.emit("select",X(e))},Q=function(e){switch("object"!==n(e)&&(e=ne(e)),s.value){case"single":Z();break;case"tags":case"multiple":I(x.value.filter((function(t){return t[O.value]!=e[O.value]})))}r.emit("deselect",X(e))},X=function(e){return g.value?e:e[O.value]},Y=function(e){Q(e)},Z=function(){I(z.value)},ee=function(e){switch(s.value){case"single":return!l(x.value)&&x.value[O.value]==e[O.value];case"tags":case"multiple":return!l(x.value)&&-1!==x.value.map((function(e){return e[O.value]})).indexOf(e[O.value])}},te=function(e){return!0===e.disabled},le=function(){return!(void 0===T||-1===T.value||!H.value&&T.value>0)&&x.value.length>=T.value},ne=function(e){return $.value[$.value.map((function(e){return String(e[O.value])})).indexOf(String(e))]},ae=function(e){return $.value.map((function(e){return o(e[d.value])})).indexOf(o(e))},re=function(e){return"tags"===s.value&&p.value&&ee(e)},ue=function(e){j.value.push(e)},oe=function(){l(M.value)||(x.value=ce(M.value))},ie=function(e){E.value=!0,c.value(P.value).then((function(t){R.value=t,"function"==typeof e&&e(t),E.value=!1}))},ce=function(e){return l(e)?"single"===s.value?{}:[]:g.value?e:"single"===s.value?ne(e)||{}:e.filter((function(e){return!!ne(e)})).map((function(e){return ne(e)}))};if("single"!==s.value&&!l(M.value)&&!Array.isArray(M.value))throw new Error('v-model must be an array when using "'.concat(s.value,'" mode'));return c&&"function"==typeof c.value?S.value?ie(oe):1==g.value&&oe():(R.value=c.value,oe()),w.value>-1&&e.watch(P,(function(e){e.length<k.value||(E.value=!0,V.value&&(R.value=[]),setTimeout((function(){e==P.value&&c.value(P.value).then((function(t){e==P.value&&(R.value=t,A.value=L.value.filter((function(e){return!0!==e.disabled}))[0]||null,E.value=!1)}))}),w.value))}),{flush:"sync"}),e.watch(M,(function(e){var t,n,a;if(l(e))x.value=ce(e);else switch(s.value){case"single":(g.value?e[O.value]!=x.value[O.value]:e!=x.value[O.value])&&(x.value=ce(e));break;case"multiple":case"tags":t=g.value?e.map((function(e){return e[O.value]})):e,n=x.value.map((function(e){return e[O.value]})),a=n.slice().sort(),t.length===n.length&&t.slice().sort().every((function(e,t){return e===a[t]}))||(x.value=ce(e))}}),{deep:!0}),"function"!=typeof t.options&&e.watch(c,(function(e,l){R.value=t.options,Object.keys(x.value).length||oe(),function(){if(H.value)if("single"===s.value){var e=ne(x.value[O.value])[h.value];x.value[h.value]=e,g.value&&(M.value[h.value]=e)}else x.value.forEach((function(e,t){var l=ne(x.value[t][O.value])[h.value];x.value[t][h.value]=l,g.value&&(M.value[t][h.value]=l)}))}()})),{fo:L,hasSelected:H,multipleLabelText:F,eo:$,noOptions:_,noResults:W,resolving:E,busy:G,select:J,deselect:Q,remove:Y,clear:Z,isSelected:ee,isDisabled:te,isMax:le,getOption:ne,handleOptionClick:function(e){if(!te(e))switch(s.value){case"single":if(ee(e))return void(q.value&&Q(e));J(e),C(),K();break;case"multiple":if(ee(e))return void Q(e);if(le())return;J(e),N.value&&D();break;case"tags":if(ee(e))return void Q(e);if(le())return;void 0===ne(e[O.value])&&f.value&&(r.emit("tag",e[O.value]),m.value&&ue(e),D()),N.value&&D(),J(e)}},handleTagRemove:function(e,t){0===t.button?Y(e):t.preventDefault()},refreshOptions:function(e){ie(e)},resolveOptions:ie}}var c={name:"Multiselect",emits:["open","close","select","deselect","input","search-change","tag","update:modelValue","change"],props:{value:{required:!1},modelValue:{required:!1},options:{type:[Array,Object,Function],required:!1,default:()=>[]},id:{type:[String,Number],required:!1,default:"multiselect"},name:{type:[String,Number],required:!1,default:"multiselect"},disabled:{type:Boolean,required:!1,default:!1},label:{type:String,required:!1,default:"label"},trackBy:{type:String,required:!1,default:"label"},valueProp:{type:String,required:!1,default:"value"},placeholder:{type:String,required:!1,default:null},mode:{type:String,required:!1,default:"single"},searchable:{type:Boolean,required:!1,default:!1},limit:{type:Number,required:!1,default:-1},maxHeight:{type:Number,required:!1,default:160},hideSelected:{type:Boolean,required:!1,default:!0},createTag:{type:Boolean,required:!1,default:!1},appendNewTag:{type:Boolean,required:!1,default:!0},caret:{type:Boolean,required:!1,default:!0},loading:{type:Boolean,required:!1,default:!1},noOptionsText:{type:String,required:!1,default:"The list is empty"},noResultsText:{type:String,required:!1,default:"No results found"},multipleLabel:{type:Function,required:!1},object:{type:Boolean,required:!1,default:!1},delay:{type:Number,required:!1,default:-1},minChars:{type:Number,required:!1,default:0},resolveOnLoad:{type:Boolean,required:!1,default:!0},filterResults:{type:Boolean,required:!1,default:!0},clearOnSearch:{type:Boolean,required:!1,default:!1},clearOnSelect:{type:Boolean,required:!1,default:!0},canDeselect:{type:Boolean,required:!1,default:!0},max:{type:Number,required:!1,default:-1},showOptions:{type:Boolean,required:!1,default:!0},addTagOn:{type:Array,required:!1,default:()=>["enter"]},required:{type:Boolean,required:!1,default:!1}},setup(t,n){const a=function(t,l){var n=e.toRefs(t),a=n.value,r=n.modelValue,u=n.mode,o=n.valueProp,i=e.ref("single"!==u.value?[]:{}),c=void 0!==l.expose?r:a,s=e.computed((function(){return"single"!==u.value?i.value.map((function(e){return e[o.value]})).join(","):i.value[o.value]}));return{iv:i,ev:c,textValue:s}}(t,n),u=function(t,l,n){var a=e.toRefs(t),r=a.searchable,u=(a.id,e.ref(null)),o=e.computed((function(){return r.value?-1:0}));return{multiselect:u,tabindex:o,focusInput:function(){u.value.querySelector(".multiselect-input").focus()},blurInput:function(){u.value.querySelector(".multiselect-input").blur()}}}(t),o={pointer:e.ref(null)},c=function(t,n,a){var r=e.toRefs(t),u=r.object,o=r.valueProp,i=r.mode,c=a.iv,s=function(e){return u.value||l(e)?e:Array.isArray(e)?e.map((function(e){return e[o.value]})):e[o.value]},d=function(e){return l(e)?"single"===i.value?{}:[]:e};return{update:function(e){c.value=d(e);var t=s(e);n.emit("change",t),n.emit("input",t),n.emit("update:modelValue",t)}}}(t,n,{iv:a.iv}),s=function(t,l,n){var a=e.toRefs(t),r=a.searchable,u=a.mode,o=n.iv,i=e.ref(null),c=e.ref(null),s=e.computed((function(){return i.value?"".concat(i.value.length,"ch"):"tags"===u.value&&-1===[null,void 0].indexOf(o.value)&&o.value.length?"1ch":"100%"}));return e.watch(i,(function(e){l.emit("search-change",e)})),{search:i,input:c,tagsSearchWidth:s,clearSearch:function(){i.value=""},focusSearch:function(){c.value.focus()},blurSearch:function(){r.value&&c.value.blur()}}}(t,n,{iv:a.iv}),d=function(t,l,n){var a=e.toRefs(t),r=a.maxHeight,u=a.disabled,o=a.searchable,i=n.multiselect,c=n.blurInput,s=n.blurSearch,d=n.focusInput,v=n.focusSearch,p=e.ref(!1),f=e.computed((function(){return"".concat(r.value,"px")}));return{isOpen:p,contentMaxHeight:f,openDropdown:function(){u.value||(p.value=!0,l.emit("open"))},closeDropdown:function(){p.value=!1,l.emit("close")},open:function(){o&&o.value?v():d()},close:function(){o&&o.value?s():c()},handleInputMousedown:function(e){p.value&&!o.value&&(i.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),i.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(t,n,{multiselect:u.multiselect,blurInput:u.blurInput,blurSearch:s.blurSearch,focusInput:u.focusInput,focusSearch:s.focusSearch}),v=i(t,n,{ev:a.ev,iv:a.iv,search:s.search,blurSearch:s.blurSearch,clearSearch:s.clearSearch,update:c.update,blurInput:u.blurInput,pointer:o.pointer}),p=function(t,l,n){var a=e.toRefs(t),r=a.id,u=a.valueProp,o=n.fo,i=n.handleOptionClick,c=n.search,s=n.pointer,d=e.computed((function(){return o.value.filter((function(e){return!0!==e.disabled}))})),v=function(e){s.value=e},p=function(){s.value=d.value[0]||null},f=function(){s.value=null},h=function(){var e=document.getElementById(r.value).querySelector(".is-pointed");if(e){var t=e.parentElement;e.offsetTop+e.offsetHeight>t.clientHeight+t.scrollTop&&(t.scrollTop=e.offsetTop+e.offsetHeight-t.clientHeight),e.offsetTop<t.scrollTop&&(t.scrollTop=e.offsetTop)}};return e.watch(c,(function(e){p()})),{pointer:s,isPointed:function(e){return!!s.value&&s.value[u.value]==e[u.value]},setPointer:v,setPointerFirst:p,clearPointer:f,selectPointer:function(){s.value&&!0!==s.value.disabled?(i(s.value),f()):f()},forwardPointer:function(){if(null===s.value)v(d.value[0]||null);else{var t=d.value.map((function(e){return e[u.value]})).indexOf(s.value[u.value])+1;d.value.length<=t&&(t=0),v(d.value[t]||null)}e.nextTick((function(){h()}))},backwardPointer:function(){if(null===s.value)v(d.value[d.value.length-1]||null);else{var t=d.value.map((function(e){return e[u.value]})).indexOf(s.value[u.value])-1;t<0&&(t=d.value.length-1),v(d.value[t]||null)}e.nextTick((function(){h()}))}}}(t,0,{fo:v.fo,handleOptionClick:v.handleOptionClick,search:s.search,pointer:o.pointer}),f=function(t,l,n){var a=e.toRefs(t),u=a.mode,o=a.addTagOn,i=a.createTag,c=n.iv,s=n.update,d=n.closeDropdown,v=n.clearPointer,p=n.search,f=n.selectPointer;return{handleBackspace:function(e){"single"!==u.value&&s(r(c.value).slice(0,-1))},handleEsc:function(e){d(),v(),e.target.blur()},handleSearchBackspace:function(e){""!==p.value&&e.stopPropagation()},handleSearchInput:function(e){p.value=e.target.value},handleAddTag:function(t){13!==t.keyCode||-1===o.value.indexOf("enter")&&i.value?32===t.keyCode&&-1!==o.value.indexOf("space")&&i.value&&(p.value=p.value.trim(),e.nextTick((function(){f()}))):f()}}}(t,0,{iv:a.iv,update:c.update,closeDropdown:d.closeDropdown,clearPointer:p.clearPointer,search:s.search,selectPointer:p.selectPointer});return{...a,...d,...u,...o,...c,...s,...v,...p,...f}}};const s={class:"multiselect-single-label"},d={class:"multiselect-multiple-label"},v={key:2,class:"multiselect-search"},p={key:3,class:"multiselect-tags"},f={class:"multiselect-tag"},h={class:"multiselect-placeholder"},m=t.createVNode("span",{class:"multiselect-caret"},null,-1),y={key:0},g=t.createVNode("span",{class:"multiselect-spinner"},null,-1),b={class:"multiselect-no-options"},w={class:"multiselect-no-results"};return c.render=function(e,l,n,a,r,u){return t.openBlock(),t.createBlock("div",{class:["multiselect",[`is-${n.mode}`,{"is-open":e.isOpen,"is-searchable":n.searchable,"is-disabled":n.disabled,"no-caret":!n.caret}]],id:n.id,onKeydown:l[29]||(l[29]=t.withKeys(t.withModifiers((()=>{}),["prevent"]),["enter"])),ref:"multiselect"},[t.createVNode("div",{class:"multiselect-input",tabindex:e.tabindex,onMousedown:l[20]||(l[20]=(...t)=>e.handleInputMousedown&&e.handleInputMousedown(...t)),onFocus:l[21]||(l[21]=(...t)=>e.openDropdown&&e.openDropdown(...t)),onBlur:l[22]||(l[22]=(...t)=>e.closeDropdown&&e.closeDropdown(...t)),onKeyup:[l[23]||(l[23]=t.withKeys(((...t)=>e.handleEsc&&e.handleEsc(...t)),["esc"])),l[24]||(l[24]=t.withKeys(((...t)=>e.selectPointer&&e.selectPointer(...t)),["enter"]))],onKeydown:[l[25]||(l[25]=t.withKeys(t.withModifiers(((...t)=>e.handleBackspace&&e.handleBackspace(...t)),["prevent"]),["delete"])),l[26]||(l[26]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["prevent"]),["up"])),l[27]||(l[27]=t.withKeys(t.withModifiers(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["prevent"]),["down"]))]},[t.createCommentVNode(" Single label "),"single"==n.mode&&e.hasSelected&&!e.search&&e.iv?t.renderSlot(e.$slots,"singlelabel",{key:0,value:e.iv},(()=>[t.createVNode("div",s,t.toDisplayString(e.iv[n.label]),1)])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Multiple label "),"multiple"==n.mode&&e.hasSelected&&!e.search?t.renderSlot(e.$slots,"multiplelabel",{key:1,values:e.iv},(()=>[t.createVNode("div",d,t.toDisplayString(e.multipleLabelText),1)])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Search "),"tags"!==n.mode&&n.searchable&&!n.disabled?(t.openBlock(),t.createBlock("div",v,[t.createVNode("input",{modelValue:e.search,value:e.search,onFocus:l[1]||(l[1]=t.withModifiers(((...t)=>e.openDropdown&&e.openDropdown(...t)),["stop"])),onBlur:l[2]||(l[2]=t.withModifiers(((...t)=>e.closeDropdown&&e.closeDropdown(...t)),["stop"])),onKeyup:[l[3]||(l[3]=t.withKeys(t.withModifiers(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),l[4]||(l[4]=t.withKeys(t.withModifiers(((...t)=>e.selectPointer&&e.selectPointer(...t)),["stop"]),["enter"]))],onKeydown:[l[5]||(l[5]=t.withKeys(((...t)=>e.handleSearchBackspace&&e.handleSearchBackspace(...t)),["delete"])),l[6]||(l[6]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["stop"]),["up"])),l[7]||(l[7]=t.withKeys(t.withModifiers(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["stop"]),["down"]))],onInput:l[8]||(l[8]=(...t)=>e.handleSearchInput&&e.handleSearchInput(...t)),ref:"input"},null,40,["modelValue","value"])])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Tags (with search) "),"tags"==n.mode?(t.openBlock(),t.createBlock("div",p,[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.iv,((a,r,u)=>(t.openBlock(),t.createBlock("span",{key:u},[t.renderSlot(e.$slots,"tag",{option:a,handleTagRemove:e.handleTagRemove,disabled:n.disabled},(()=>[t.createVNode("div",f,[t.createTextVNode(t.toDisplayString(a[n.label])+" ",1),n.disabled?t.createCommentVNode("v-if",!0):(t.openBlock(),t.createBlock("i",{key:0,onClick:l[9]||(l[9]=t.withModifiers((()=>{}),["prevent"])),onMousedown:t.withModifiers((t=>e.handleTagRemove(a,t)),["prevent","stop"])},null,40,["onMousedown"]))])]))])))),128)),n.searchable&&!n.disabled?(t.openBlock(),t.createBlock("div",{key:0,class:"multiselect-search",style:{width:e.tagsSearchWidth}},[t.createVNode("input",{modelValue:e.search,value:e.search,onFocus:l[10]||(l[10]=t.withModifiers(((...t)=>e.openDropdown&&e.openDropdown(...t)),["stop"])),onBlur:l[11]||(l[11]=t.withModifiers(((...t)=>e.closeDropdown&&e.closeDropdown(...t)),["stop"])),onKeyup:[l[12]||(l[12]=t.withKeys(t.withModifiers(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),l[13]||(l[13]=t.withKeys(t.withModifiers(((...t)=>e.handleAddTag&&e.handleAddTag(...t)),["stop"]),["enter"])),l[14]||(l[14]=t.withKeys(t.withModifiers(((...t)=>e.handleAddTag&&e.handleAddTag(...t)),["stop"]),["space"]))],onKeydown:[l[15]||(l[15]=t.withKeys(((...t)=>e.handleSearchBackspace&&e.handleSearchBackspace(...t)),["delete"])),l[16]||(l[16]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["stop"]),["up"])),l[17]||(l[17]=t.withKeys(t.withModifiers(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["stop"]),["down"]))],onInput:l[18]||(l[18]=(...t)=>e.handleSearchInput&&e.handleSearchInput(...t)),style:{width:e.tagsSearchWidth},ref:"input"},null,44,["modelValue","value"])],4)):t.createCommentVNode("v-if",!0)])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Placeholder "),!n.placeholder||e.hasSelected||e.search?t.createCommentVNode("v-if",!0):t.renderSlot(e.$slots,"placeholder",{key:4},(()=>[t.createVNode("div",h,t.toDisplayString(n.placeholder),1)])),n.caret&&!e.busy?t.renderSlot(e.$slots,"caret",{key:5},(()=>[m])):t.createCommentVNode("v-if",!0),t.createVNode(t.Transition,{name:"multiselect-loading"},{default:t.withCtx((()=>[e.busy?(t.openBlock(),t.createBlock("span",y,[t.renderSlot(e.$slots,"spinner",{},(()=>[g]))])):t.createCommentVNode("v-if",!0)])),_:1}),e.hasSelected&&!n.disabled?t.renderSlot(e.$slots,"clear",{key:6,clear:e.clear},(()=>[t.createVNode("a",{class:"multiselect-clear",onClick:l[19]||(l[19]=t.withModifiers(((...t)=>e.clear&&e.clear(...t)),["prevent"]))})])):t.createCommentVNode("v-if",!0)],40,["tabindex"]),t.createCommentVNode(" Options "),e.resolving&&n.clearOnSearch?t.createCommentVNode("v-if",!0):(t.openBlock(),t.createBlock(t.Transition,{key:0,name:"multiselect",onAfterLeave:e.clearSearch},{default:t.withCtx((()=>[t.withDirectives(t.createVNode("div",{class:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[t.renderSlot(e.$slots,"beforelist"),(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.fo,((a,r,u)=>(t.openBlock(),t.createBlock("span",{tabindex:-1,class:["multiselect-option",{"is-pointed":e.isPointed(a),"is-selected":e.isSelected(a),"is-disabled":e.isDisabled(a)}],key:u,onMousedown:l[28]||(l[28]=t.withModifiers((()=>{}),["prevent"])),onMouseenter:t=>e.setPointer(a),onClick:t.withModifiers((t=>e.handleOptionClick(a)),["stop","prevent"])},[t.renderSlot(e.$slots,"option",{option:a,search:e.search},(()=>[t.createVNode("span",null,t.toDisplayString(a[n.label]),1)]))],42,["onMouseenter","onClick"])))),128)),t.withDirectives(t.createVNode("span",null,[t.renderSlot(e.$slots,"nooptions",{},(()=>[t.createVNode("div",b,t.toDisplayString(n.noOptionsText),1)]))],512),[[t.vShow,e.noOptions]]),t.withDirectives(t.createVNode("span",null,[t.renderSlot(e.$slots,"noresults",{},(()=>[t.createVNode("div",w,t.toDisplayString(n.noResultsText),1)]))],512),[[t.vShow,e.noResults]]),t.renderSlot(e.$slots,"afterlist")],4),[[t.vShow,e.isOpen&&n.showOptions]])])),_:3},8,["onAfterLeave"])),t.createCommentVNode(" Hacky input element to show HTML5 required warning "),n.required?(t.openBlock(),t.createBlock("input",{key:1,class:"multiselect-fake-input",tabindex:"-1",value:e.textValue,required:""},null,8,["value"])):t.createCommentVNode("v-if",!0)],42,["id"])},c.__file="src/Multiselect.vue",c}(Vue,Vue); |
@@ -1,1 +0,1 @@ | ||
import{toRefs as e,ref as l,computed as t,watch as n,nextTick as a,openBlock as u,createBlock as r,withKeys as o,withModifiers as i,createVNode as c,createCommentVNode as s,renderSlot as d,toDisplayString as v,Fragment as p,renderList as f,createTextVNode as h,Transition as m,withCtx as g,withDirectives as b,vShow as y}from"vue";function S(e){return-1!==[null,void 0,!1].indexOf(e)}function w(e){return String(e).toLowerCase().trim()}var O={};function k(e){return(k="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 q(e,l,t){return l in e?Object.defineProperty(e,l,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[l]=t,e}function x(a,u,r){var o=e(a),i=o.options,c=o.mode,s=o.trackBy,d=o.limit,v=o.hideSelected,p=o.createTag,f=o.label,h=o.appendNewTag,m=o.multipleLabel,g=o.object,b=o.loading,y=o.delay,x=o.resolveOnLoad,P=o.minChars,V=o.filterResults,T=o.clearOnSearch,B=o.clearOnSelect,I=o.valueProp,D=o.canDeselect,A=o.max,j=r.internalValue,M=r.externalValue,C=r.currentValue,E=r.search,N=r.blurSearch,$=r.clearSearch,H=r.update,L=r.blurInput,R=r.pointer,K=l([]),F=l([]),J=l(!1),_=t((function(){var e,l=F.value||[];return e=l,"[object Object]"===Object.prototype.toString.call(e)&&(l=Object.keys(l).map((function(e){var t,n=l[e];return q(t={},I.value,e),q(t,s.value,n),q(t,f.value,n),t}))),l=l.map((function(e,l){var t;return"object"===k(e)?e:(q(t={},I.value,l),q(t,s.value,e),q(t,f.value,e),t)})),K.value.length&&(l=l.concat(K.value)),l})),W=t((function(){var e=_.value;return X.value.length&&(e=X.value.concat(e)),E.value&&V.value&&(e=e.filter((function(e){return-1!==w(e[s.value]).indexOf(w(E.value))}))),v.value&&(e=e.filter((function(e){return!se(e)}))),d.value>0&&(e=e.slice(0,d.value)),e})),U=t((function(){switch(c.value){case"single":return!S(j.value[I.value]);case"multiple":case"tags":return!S(j.value)&&j.value.length>0}})),z=t((function(){return void 0!==m&&void 0!==m.value?m.value(j.value):j.value&&j.value.length>1?"".concat(j.value.length," options selected"):"1 option selected"})),G=t((function(){return!_.value.length&&!J.value})),Q=t((function(){return _.value.length>0&&0==W.value.length})),X=t((function(){var e;return!1!==p.value&&E.value?-1!==ce(E.value)?[]:[(e={},q(e,I.value,E.value),q(e,f.value,E.value),q(e,s.value,E.value),e)]:[]})),Y=t((function(){switch(c.value){case"single":return null;case"multiple":case"tags":return[]}})),Z=t((function(){return b.value||J.value})),ee=function(e){switch("object"!==k(e)&&(e=ie(e)),c.value){case"single":H(e);break;case"multiple":case"tags":H(j.value.concat(e))}u.emit("select",te(e))},le=function(e){switch("object"!==k(e)&&(e=ie(e)),c.value){case"single":ae();break;case"tags":case"multiple":H(j.value.filter((function(l){return l[I.value]!=e[I.value]})))}u.emit("deselect",te(e))},te=function(e){return g.value?e:e[I.value]},ne=function(e){le(e)},ae=function(){H(Y.value)},ue=function(e){switch(c.value){case"single":return!S(j.value)&&j.value[I.value]==e[I.value];case"tags":case"multiple":return!S(j.value)&&-1!==j.value.map((function(e){return e[I.value]})).indexOf(e[I.value])}},re=function(e){return!0===e.disabled},oe=function(){return!(void 0===A||-1===A.value||!U.value&&A.value>0)&&j.value.length>=A.value},ie=function(e){return _.value[_.value.map((function(e){return String(e[I.value])})).indexOf(String(e))]},ce=function(e){return _.value.map((function(e){return w(e[s.value])})).indexOf(w(e))},se=function(e){return"tags"===c.value&&v.value&&ue(e)},de=function(e){K.value.push(e)},ve=function(){S(M.value)||(j.value=fe(M.value))},pe=function(e){J.value=!0,i.value(E.value).then((function(l){F.value=l,"function"==typeof e&&e(l),J.value=!1}))},fe=function(e){return S(e)?"single"===c.value?{}:[]:g.value?e:"single"===c.value?ie(e)||{}:e.filter((function(e){return!!ie(e)})).map((function(e){return ie(e)}))};if("single"!==c.value&&!S(M.value)&&!Array.isArray(M.value))throw new Error('v-model must be an array when using "'.concat(c.value,'" mode'));return i&&"function"==typeof i.value?x.value?pe(ve):1==g.value&&ve():(F.value=i.value,ve()),y.value>-1&&n(E,(function(e){e.length<P.value||(J.value=!0,T.value&&(F.value=[]),setTimeout((function(){e==E.value&&i.value(E.value).then((function(l){e==E.value&&(F.value=l,R.value=W.value.filter((function(e){return!0!==e.disabled}))[0]||null,J.value=!1)}))}),y.value))}),{flush:"sync"}),n(M,(function(e){var l,t,n;if(S(e))j.value=fe(e);else switch(c.value){case"single":(g.value?e[I.value]!=j.value[I.value]:e!=j.value[I.value])&&(j.value=fe(e));break;case"multiple":case"tags":l=g.value?e.map((function(e){return e[I.value]})):e,t=j.value.map((function(e){return e[I.value]})),n=t.slice().sort(),l.length===t.length&&l.slice().sort().every((function(e,l){return e===n[l]}))||(j.value=fe(e))}}),{deep:!0}),"function"!=typeof a.options&&(n((function(){return a.options}),(function(e,l){F.value=a.options})),n(_,(function(e,l){if(Object.keys(j.value).length||ve(),e.length&&C.value&&C.value.length){var t;if("single"===c.value){if(t=e[e.map((function(e){return e[I.value]})).indexOf(C.value)],JSON.stringify(t)===JSON.stringify(j.value))return}else if(t=[],C.value.forEach((function(l){t.push(e[e.map((function(e){return e[I.value]})).indexOf(l)])})),function(e,l){var t=e.length===l.length;if(!t)return t;try{e.every((function(e,t){if(JSON.stringify(e)!==JSON.stringify(l[t]))throw O}))}catch(e){if(e!==O)throw e;t=!1}return t}(t,j.value))return;g.value?H(t):j.value=t}}),{flush:"sync",deep:!0,immediate:!1})),{filteredOptions:W,hasSelected:U,multipleLabelText:z,extendedOptions:_,noOptions:G,noResults:Q,resolving:J,busy:Z,select:ee,deselect:le,remove:ne,clear:ae,isSelected:ue,isDisabled:re,isMax:oe,getOption:ie,handleOptionClick:function(e){if(!re(e))switch(c.value){case"single":if(ue(e))return void(D.value&&le(e));ee(e),N(),L();break;case"multiple":if(ue(e))return void le(e);if(oe())return;ee(e),B.value&&$();break;case"tags":if(ue(e))return void le(e);if(oe())return;void 0===ie(e[I.value])&&p.value&&(u.emit("tag",e[I.value]),h.value&&de(e),$()),B.value&&$(),ee(e)}},handleTagRemove:function(e,l){0===l.button?ne(e):l.preventDefault()},refreshOptions:function(e){pe(e)},resolveOptions:pe}}function P(e){return function(e){if(Array.isArray(e))return V(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,l){if(!e)return;if("string"==typeof e)return V(e,l);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return V(e,l)}(e)||function(){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 V(e,l){(null==l||l>e.length)&&(l=e.length);for(var t=0,n=new Array(l);t<l;t++)n[t]=e[t];return n}var T={name:"Multiselect",emits:["open","close","select","deselect","input","search-change","tag","update:modelValue","change"],props:{value:{required:!1},modelValue:{required:!1},options:{type:[Array,Object,Function],required:!1,default:()=>[]},id:{type:[String,Number],required:!1,default:"multiselect"},name:{type:[String,Number],required:!1,default:"multiselect"},disabled:{type:Boolean,required:!1,default:!1},label:{type:String,required:!1,default:"label"},trackBy:{type:String,required:!1,default:"label"},valueProp:{type:String,required:!1,default:"value"},placeholder:{type:String,required:!1,default:null},mode:{type:String,required:!1,default:"single"},searchable:{type:Boolean,required:!1,default:!1},limit:{type:Number,required:!1,default:-1},maxHeight:{type:Number,required:!1,default:160},hideSelected:{type:Boolean,required:!1,default:!0},createTag:{type:Boolean,required:!1,default:!1},appendNewTag:{type:Boolean,required:!1,default:!0},caret:{type:Boolean,required:!1,default:!0},loading:{type:Boolean,required:!1,default:!1},noOptionsText:{type:String,required:!1,default:"The list is empty"},noResultsText:{type:String,required:!1,default:"No results found"},multipleLabel:{type:Function,required:!1},object:{type:Boolean,required:!1,default:!1},delay:{type:Number,required:!1,default:-1},minChars:{type:Number,required:!1,default:0},resolveOnLoad:{type:Boolean,required:!1,default:!0},filterResults:{type:Boolean,required:!1,default:!0},clearOnSearch:{type:Boolean,required:!1,default:!1},clearOnSelect:{type:Boolean,required:!1,default:!0},canDeselect:{type:Boolean,required:!1,default:!0},max:{type:Number,required:!1,default:-1},showOptions:{type:Boolean,required:!1,default:!0},addTagOn:{type:Array,required:!1,default:()=>["enter"]},required:{type:Boolean,required:!1,default:!1}},setup(u,r){const o=function(n,a){var u=e(n),r=u.value,o=u.modelValue,i=u.mode,c=u.valueProp,s=l("single"!==i.value?[]:{}),d=void 0!==a.expose?o:r,v=t((function(){return Object.keys(s.value).length?"single"!==i.value?s.value.map((function(e){return e[c.value]})):s.value[c.value]:s.value})),p=t((function(){return"single"!==i.value?s.value.map((function(e){return e[c.value]})).join(","):s.value[c.value]}));return{internalValue:s,externalValue:d,currentValue:v,textValue:p}}(u,r),i=function(n,a,u){var r=e(n),o=r.searchable,i=(r.id,l(null)),c=t((function(){return o.value?-1:0}));return{multiselect:i,tabindex:c,focusInput:function(){i.value.querySelector(".multiselect-input").focus()},blurInput:function(){i.value.querySelector(".multiselect-input").blur()}}}(u),c={pointer:l(null)},s=function(l,t,n){var a=e(l),u=a.object,r=a.valueProp,o=a.mode,i=n.internalValue,c=function(e){return u.value||S(e)?e:Array.isArray(e)?e.map((function(e){return e[r.value]})):e[r.value]},s=function(e){return S(e)?"single"===o.value?{}:[]:e};return{update:function(e){i.value=s(e);var l=c(e);t.emit("change",l),t.emit("input",l),t.emit("update:modelValue",l)}}}(u,r,{internalValue:o.internalValue}),d=function(a,u,r){var o=e(a),i=o.searchable,c=o.mode,s=r.internalValue,d=l(null),v=l(null),p=t((function(){return d.value?"".concat(d.value.length,"ch"):"tags"===c.value&&-1===[null,void 0].indexOf(s.value)&&s.value.length?"1ch":"100%"}));return n(d,(function(e){u.emit("search-change",e)})),{search:d,input:v,tagsSearchWidth:p,clearSearch:function(){d.value=""},focusSearch:function(){v.value.focus()},blurSearch:function(){i.value&&v.value.blur()}}}(u,r,{internalValue:o.internalValue}),v=function(n,a,u){var r=e(n),o=r.maxHeight,i=r.disabled,c=r.searchable,s=u.multiselect,d=u.blurInput,v=u.blurSearch,p=u.focusInput,f=u.focusSearch,h=l(!1),m=t((function(){return"".concat(o.value,"px")}));return{isOpen:h,contentMaxHeight:m,openDropdown:function(){i.value||(h.value=!0,a.emit("open"))},closeDropdown:function(){h.value=!1,a.emit("close")},open:function(){c&&c.value?f():p()},close:function(){c&&c.value?v():d()},handleInputMousedown:function(e){h.value&&!c.value&&(s.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),s.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(u,r,{multiselect:i.multiselect,blurInput:i.blurInput,blurSearch:d.blurSearch,focusInput:i.focusInput,focusSearch:d.focusSearch}),p=x(u,r,{externalValue:o.externalValue,internalValue:o.internalValue,currentValue:o.currentValue,search:d.search,blurSearch:d.blurSearch,clearSearch:d.clearSearch,update:s.update,blurInput:i.blurInput,pointer:c.pointer}),f=function(l,u,r){var o=e(l),i=o.id,c=o.valueProp,s=r.filteredOptions,d=r.handleOptionClick,v=r.search,p=r.pointer,f=t((function(){return s.value.filter((function(e){return!0!==e.disabled}))})),h=function(e){p.value=e},m=function(){p.value=f.value[0]||null},g=function(){p.value=null},b=function(){var e=document.getElementById(i.value).querySelector(".is-pointed");if(e){var l=e.parentElement;e.offsetTop+e.offsetHeight>l.clientHeight+l.scrollTop&&(l.scrollTop=e.offsetTop+e.offsetHeight-l.clientHeight),e.offsetTop<l.scrollTop&&(l.scrollTop=e.offsetTop)}};return n(v,(function(e){m()})),{pointer:p,isPointed:function(e){return!!p.value&&p.value[c.value]==e[c.value]},setPointer:h,setPointerFirst:m,clearPointer:g,selectPointer:function(){p.value&&!0!==p.value.disabled?(d(p.value),g()):g()},forwardPointer:function(){if(null===p.value)h(f.value[0]||null);else{var e=f.value.map((function(e){return e[c.value]})).indexOf(p.value[c.value])+1;f.value.length<=e&&(e=0),h(f.value[e]||null)}a((function(){b()}))},backwardPointer:function(){if(null===p.value)h(f.value[f.value.length-1]||null);else{var e=f.value.map((function(e){return e[c.value]})).indexOf(p.value[c.value])-1;e<0&&(e=f.value.length-1),h(f.value[e]||null)}a((function(){b()}))}}}(u,0,{filteredOptions:p.filteredOptions,handleOptionClick:p.handleOptionClick,search:d.search,pointer:c.pointer}),h=function(l,t,n){var u=e(l),r=u.mode,o=u.addTagOn,i=u.createTag,c=n.internalValue,s=n.update,d=n.closeDropdown,v=n.clearPointer,p=n.search,f=n.selectPointer;return{handleBackspace:function(e){"single"!==r.value&&s(P(c.value).slice(0,-1))},handleEsc:function(e){d(),v(),e.target.blur()},handleSearchBackspace:function(e){""!==p.value&&e.stopPropagation()},handleSearchInput:function(e){p.value=e.target.value},handleAddTag:function(e){13!==e.keyCode||-1===o.value.indexOf("enter")&&i.value?32===e.keyCode&&-1!==o.value.indexOf("space")&&i.value&&(p.value=p.value.trim(),a((function(){f()}))):f()}}}(u,0,{internalValue:o.internalValue,update:s.update,closeDropdown:v.closeDropdown,clearPointer:f.clearPointer,search:d.search,selectPointer:f.selectPointer});return{...o,...v,...i,...c,...s,...d,...p,...f,...h}}};const B={class:"multiselect-single-label"},I={class:"multiselect-multiple-label"},D={key:2,class:"multiselect-search"},A={key:3,class:"multiselect-tags"},j={class:"multiselect-tag"},M={class:"multiselect-placeholder"},C=c("span",{class:"multiselect-caret"},null,-1),E={key:0},N=c("span",{class:"multiselect-spinner"},null,-1),$={class:"multiselect-no-options"},H={class:"multiselect-no-results"};T.render=function(e,l,t,n,a,S){return u(),r("div",{class:["multiselect",[`is-${t.mode}`,{"is-open":e.isOpen,"is-searchable":t.searchable,"is-disabled":t.disabled,"no-caret":!t.caret}]],id:t.id,onKeydown:l[29]||(l[29]=o(i((()=>{}),["prevent"]),["enter"])),ref:"multiselect"},[c("div",{class:"multiselect-input",tabindex:e.tabindex,onMousedown:l[20]||(l[20]=(...l)=>e.handleInputMousedown&&e.handleInputMousedown(...l)),onFocus:l[21]||(l[21]=(...l)=>e.openDropdown&&e.openDropdown(...l)),onBlur:l[22]||(l[22]=(...l)=>e.closeDropdown&&e.closeDropdown(...l)),onKeyup:[l[23]||(l[23]=o(((...l)=>e.handleEsc&&e.handleEsc(...l)),["esc"])),l[24]||(l[24]=o(((...l)=>e.selectPointer&&e.selectPointer(...l)),["enter"]))],onKeydown:[l[25]||(l[25]=o(i(((...l)=>e.handleBackspace&&e.handleBackspace(...l)),["prevent"]),["delete"])),l[26]||(l[26]=o(i(((...l)=>e.backwardPointer&&e.backwardPointer(...l)),["prevent"]),["up"])),l[27]||(l[27]=o(i(((...l)=>e.forwardPointer&&e.forwardPointer(...l)),["prevent"]),["down"]))]},[s(" Single label "),"single"==t.mode&&e.hasSelected&&!e.search&&e.internalValue?d(e.$slots,"singlelabel",{key:0,value:e.internalValue},(()=>[c("div",B,v(e.internalValue[t.label]),1)])):s("v-if",!0),s(" Multiple label "),"multiple"==t.mode&&e.hasSelected&&!e.search?d(e.$slots,"multiplelabel",{key:1,values:e.internalValue},(()=>[c("div",I,v(e.multipleLabelText),1)])):s("v-if",!0),s(" Search "),"tags"!==t.mode&&t.searchable&&!t.disabled?(u(),r("div",D,[c("input",{modelValue:e.search,value:e.search,onFocus:l[1]||(l[1]=i(((...l)=>e.openDropdown&&e.openDropdown(...l)),["stop"])),onBlur:l[2]||(l[2]=i(((...l)=>e.closeDropdown&&e.closeDropdown(...l)),["stop"])),onKeyup:[l[3]||(l[3]=o(i(((...l)=>e.handleEsc&&e.handleEsc(...l)),["stop"]),["esc"])),l[4]||(l[4]=o(i(((...l)=>e.selectPointer&&e.selectPointer(...l)),["stop"]),["enter"]))],onKeydown:[l[5]||(l[5]=o(((...l)=>e.handleSearchBackspace&&e.handleSearchBackspace(...l)),["delete"])),l[6]||(l[6]=o(i(((...l)=>e.backwardPointer&&e.backwardPointer(...l)),["stop"]),["up"])),l[7]||(l[7]=o(i(((...l)=>e.forwardPointer&&e.forwardPointer(...l)),["stop"]),["down"]))],onInput:l[8]||(l[8]=(...l)=>e.handleSearchInput&&e.handleSearchInput(...l)),ref:"input"},null,40,["modelValue","value"])])):s("v-if",!0),s(" Tags (with search) "),"tags"==t.mode?(u(),r("div",A,[(u(!0),r(p,null,f(e.internalValue,((n,a,o)=>(u(),r("span",{key:o},[d(e.$slots,"tag",{option:n,handleTagRemove:e.handleTagRemove,disabled:t.disabled},(()=>[c("div",j,[h(v(n[t.label])+" ",1),t.disabled?s("v-if",!0):(u(),r("i",{key:0,onClick:l[9]||(l[9]=i((()=>{}),["prevent"])),onMousedown:i((l=>e.handleTagRemove(n,l)),["prevent","stop"])},null,40,["onMousedown"]))])]))])))),128)),t.searchable&&!t.disabled?(u(),r("div",{key:0,class:"multiselect-search",style:{width:e.tagsSearchWidth}},[c("input",{modelValue:e.search,value:e.search,onFocus:l[10]||(l[10]=i(((...l)=>e.openDropdown&&e.openDropdown(...l)),["stop"])),onBlur:l[11]||(l[11]=i(((...l)=>e.closeDropdown&&e.closeDropdown(...l)),["stop"])),onKeyup:[l[12]||(l[12]=o(i(((...l)=>e.handleEsc&&e.handleEsc(...l)),["stop"]),["esc"])),l[13]||(l[13]=o(i(((...l)=>e.handleAddTag&&e.handleAddTag(...l)),["stop"]),["enter"])),l[14]||(l[14]=o(i(((...l)=>e.handleAddTag&&e.handleAddTag(...l)),["stop"]),["space"]))],onKeydown:[l[15]||(l[15]=o(((...l)=>e.handleSearchBackspace&&e.handleSearchBackspace(...l)),["delete"])),l[16]||(l[16]=o(i(((...l)=>e.backwardPointer&&e.backwardPointer(...l)),["stop"]),["up"])),l[17]||(l[17]=o(i(((...l)=>e.forwardPointer&&e.forwardPointer(...l)),["stop"]),["down"]))],onInput:l[18]||(l[18]=(...l)=>e.handleSearchInput&&e.handleSearchInput(...l)),style:{width:e.tagsSearchWidth},ref:"input"},null,44,["modelValue","value"])],4)):s("v-if",!0)])):s("v-if",!0),s(" Placeholder "),!t.placeholder||e.hasSelected||e.search?s("v-if",!0):d(e.$slots,"placeholder",{key:4},(()=>[c("div",M,v(t.placeholder),1)])),t.caret&&!e.busy?d(e.$slots,"caret",{key:5},(()=>[C])):s("v-if",!0),c(m,{name:"multiselect-loading"},{default:g((()=>[e.busy?(u(),r("span",E,[d(e.$slots,"spinner",{},(()=>[N]))])):s("v-if",!0)])),_:1}),e.hasSelected&&!t.disabled?d(e.$slots,"clear",{key:6,clear:e.clear},(()=>[c("a",{class:"multiselect-clear",onClick:l[19]||(l[19]=i(((...l)=>e.clear&&e.clear(...l)),["prevent"]))})])):s("v-if",!0)],40,["tabindex"]),s(" Options "),e.resolving&&t.clearOnSearch?s("v-if",!0):(u(),r(m,{key:0,name:"multiselect",onAfterLeave:e.clearSearch},{default:g((()=>[b(c("div",{class:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[d(e.$slots,"beforelist"),(u(!0),r(p,null,f(e.filteredOptions,((n,a,o)=>(u(),r("span",{tabindex:-1,class:["multiselect-option",{"is-pointed":e.isPointed(n),"is-selected":e.isSelected(n),"is-disabled":e.isDisabled(n)}],key:o,onMousedown:l[28]||(l[28]=i((()=>{}),["prevent"])),onMouseenter:l=>e.setPointer(n),onClick:i((l=>e.handleOptionClick(n)),["stop","prevent"])},[d(e.$slots,"option",{option:n,search:e.search},(()=>[c("span",null,v(n[t.label]),1)]))],42,["onMouseenter","onClick"])))),128)),b(c("span",null,[d(e.$slots,"nooptions",{},(()=>[c("div",$,v(t.noOptionsText),1)]))],512),[[y,e.noOptions]]),b(c("span",null,[d(e.$slots,"noresults",{},(()=>[c("div",H,v(t.noResultsText),1)]))],512),[[y,e.noResults]]),d(e.$slots,"afterlist")],4),[[y,e.isOpen&&t.showOptions]])])),_:3},8,["onAfterLeave"])),s(" Hacky input element to show HTML5 required warning "),t.required?(u(),r("input",{key:1,class:"multiselect-fake-input",tabindex:"-1",value:e.textValue,required:""},null,8,["value"])):s("v-if",!0)],42,["id"])},T.__file="src/Multiselect.vue";export default T; | ||
import{toRefs as e,ref as l,computed as t,watch as n,nextTick as a,openBlock as u,createBlock as r,withKeys as o,withModifiers as i,createVNode as c,createCommentVNode as s,renderSlot as v,toDisplayString as d,Fragment as p,renderList as f,createTextVNode as h,Transition as m,withCtx as b,withDirectives as g,vShow as y}from"vue";function S(e){return-1!==[null,void 0,!1].indexOf(e)}function w(e){return String(e).toLowerCase().trim()}function k(e){return(k="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 O(e,l,t){return l in e?Object.defineProperty(e,l,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[l]=t,e}function q(a,u,r){var o=e(a),i=o.options,c=o.mode,s=o.trackBy,v=o.limit,d=o.hideSelected,p=o.createTag,f=o.label,h=o.appendNewTag,m=o.multipleLabel,b=o.object,g=o.loading,y=o.delay,q=o.resolveOnLoad,P=o.minChars,x=o.filterResults,T=o.clearOnSearch,B=o.clearOnSelect,I=o.valueProp,D=o.canDeselect,A=o.max,j=r.iv,M=r.ev,C=r.search,E=r.blurSearch,$=r.clearSearch,H=r.update,L=r.blurInput,N=r.pointer,R=l([]),V=l([]),K=l(!1),F=t((function(){var e,l=V.value||[];return e=l,"[object Object]"===Object.prototype.toString.call(e)&&(l=Object.keys(l).map((function(e){var t,n=l[e];return O(t={},I.value,e),O(t,s.value,n),O(t,f.value,n),t}))),l=l.map((function(e,l){var t;return"object"===k(e)?e:(O(t={},I.value,e),O(t,s.value,e),O(t,f.value,e),t)})),R.value.length&&(l=l.concat(R.value)),l})),_=t((function(){var e=F.value;return J.value.length&&(e=J.value.concat(e)),C.value&&x.value&&(e=e.filter((function(e){return-1!==w(e[s.value]).indexOf(w(C.value))}))),d.value&&(e=e.filter((function(e){return!ie(e)}))),v.value>0&&(e=e.slice(0,v.value)),e})),W=t((function(){switch(c.value){case"single":return!S(j.value[I.value]);case"multiple":case"tags":return!S(j.value)&&j.value.length>0}})),U=t((function(){return void 0!==m&&void 0!==m.value?m.value(j.value):j.value&&j.value.length>1?"".concat(j.value.length," options selected"):"1 option selected"})),z=t((function(){return!F.value.length&&!K.value})),G=t((function(){return F.value.length>0&&0==_.value.length})),J=t((function(){var e;return!1!==p.value&&C.value?-1!==oe(C.value)?[]:[(e={},O(e,I.value,C.value),O(e,f.value,C.value),O(e,s.value,C.value),e)]:[]})),Q=t((function(){switch(c.value){case"single":return null;case"multiple":case"tags":return[]}})),X=t((function(){return g.value||K.value})),Y=function(e){switch("object"!==k(e)&&(e=re(e)),c.value){case"single":H(e);break;case"multiple":case"tags":H(j.value.concat(e))}u.emit("select",ee(e))},Z=function(e){switch("object"!==k(e)&&(e=re(e)),c.value){case"single":te();break;case"tags":case"multiple":H(j.value.filter((function(l){return l[I.value]!=e[I.value]})))}u.emit("deselect",ee(e))},ee=function(e){return b.value?e:e[I.value]},le=function(e){Z(e)},te=function(){H(Q.value)},ne=function(e){switch(c.value){case"single":return!S(j.value)&&j.value[I.value]==e[I.value];case"tags":case"multiple":return!S(j.value)&&-1!==j.value.map((function(e){return e[I.value]})).indexOf(e[I.value])}},ae=function(e){return!0===e.disabled},ue=function(){return!(void 0===A||-1===A.value||!W.value&&A.value>0)&&j.value.length>=A.value},re=function(e){return F.value[F.value.map((function(e){return String(e[I.value])})).indexOf(String(e))]},oe=function(e){return F.value.map((function(e){return w(e[s.value])})).indexOf(w(e))},ie=function(e){return"tags"===c.value&&d.value&&ne(e)},ce=function(e){R.value.push(e)},se=function(){S(M.value)||(j.value=de(M.value))},ve=function(e){K.value=!0,i.value(C.value).then((function(l){V.value=l,"function"==typeof e&&e(l),K.value=!1}))},de=function(e){return S(e)?"single"===c.value?{}:[]:b.value?e:"single"===c.value?re(e)||{}:e.filter((function(e){return!!re(e)})).map((function(e){return re(e)}))};if("single"!==c.value&&!S(M.value)&&!Array.isArray(M.value))throw new Error('v-model must be an array when using "'.concat(c.value,'" mode'));return i&&"function"==typeof i.value?q.value?ve(se):1==b.value&&se():(V.value=i.value,se()),y.value>-1&&n(C,(function(e){e.length<P.value||(K.value=!0,T.value&&(V.value=[]),setTimeout((function(){e==C.value&&i.value(C.value).then((function(l){e==C.value&&(V.value=l,N.value=_.value.filter((function(e){return!0!==e.disabled}))[0]||null,K.value=!1)}))}),y.value))}),{flush:"sync"}),n(M,(function(e){var l,t,n;if(S(e))j.value=de(e);else switch(c.value){case"single":(b.value?e[I.value]!=j.value[I.value]:e!=j.value[I.value])&&(j.value=de(e));break;case"multiple":case"tags":l=b.value?e.map((function(e){return e[I.value]})):e,t=j.value.map((function(e){return e[I.value]})),n=t.slice().sort(),l.length===t.length&&l.slice().sort().every((function(e,l){return e===n[l]}))||(j.value=de(e))}}),{deep:!0}),"function"!=typeof a.options&&n(i,(function(e,l){V.value=a.options,Object.keys(j.value).length||se(),function(){if(W.value)if("single"===c.value){var e=re(j.value[I.value])[f.value];j.value[f.value]=e,b.value&&(M.value[f.value]=e)}else j.value.forEach((function(e,l){var t=re(j.value[l][I.value])[f.value];j.value[l][f.value]=t,b.value&&(M.value[l][f.value]=t)}))}()})),{fo:_,hasSelected:W,multipleLabelText:U,eo:F,noOptions:z,noResults:G,resolving:K,busy:X,select:Y,deselect:Z,remove:le,clear:te,isSelected:ne,isDisabled:ae,isMax:ue,getOption:re,handleOptionClick:function(e){if(!ae(e))switch(c.value){case"single":if(ne(e))return void(D.value&&Z(e));Y(e),E(),L();break;case"multiple":if(ne(e))return void Z(e);if(ue())return;Y(e),B.value&&$();break;case"tags":if(ne(e))return void Z(e);if(ue())return;void 0===re(e[I.value])&&p.value&&(u.emit("tag",e[I.value]),h.value&&ce(e),$()),B.value&&$(),Y(e)}},handleTagRemove:function(e,l){0===l.button?le(e):l.preventDefault()},refreshOptions:function(e){ve(e)},resolveOptions:ve}}function P(e){return function(e){if(Array.isArray(e))return x(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,l){if(!e)return;if("string"==typeof e)return x(e,l);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return x(e,l)}(e)||function(){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 x(e,l){(null==l||l>e.length)&&(l=e.length);for(var t=0,n=new Array(l);t<l;t++)n[t]=e[t];return n}var T={name:"Multiselect",emits:["open","close","select","deselect","input","search-change","tag","update:modelValue","change"],props:{value:{required:!1},modelValue:{required:!1},options:{type:[Array,Object,Function],required:!1,default:()=>[]},id:{type:[String,Number],required:!1,default:"multiselect"},name:{type:[String,Number],required:!1,default:"multiselect"},disabled:{type:Boolean,required:!1,default:!1},label:{type:String,required:!1,default:"label"},trackBy:{type:String,required:!1,default:"label"},valueProp:{type:String,required:!1,default:"value"},placeholder:{type:String,required:!1,default:null},mode:{type:String,required:!1,default:"single"},searchable:{type:Boolean,required:!1,default:!1},limit:{type:Number,required:!1,default:-1},maxHeight:{type:Number,required:!1,default:160},hideSelected:{type:Boolean,required:!1,default:!0},createTag:{type:Boolean,required:!1,default:!1},appendNewTag:{type:Boolean,required:!1,default:!0},caret:{type:Boolean,required:!1,default:!0},loading:{type:Boolean,required:!1,default:!1},noOptionsText:{type:String,required:!1,default:"The list is empty"},noResultsText:{type:String,required:!1,default:"No results found"},multipleLabel:{type:Function,required:!1},object:{type:Boolean,required:!1,default:!1},delay:{type:Number,required:!1,default:-1},minChars:{type:Number,required:!1,default:0},resolveOnLoad:{type:Boolean,required:!1,default:!0},filterResults:{type:Boolean,required:!1,default:!0},clearOnSearch:{type:Boolean,required:!1,default:!1},clearOnSelect:{type:Boolean,required:!1,default:!0},canDeselect:{type:Boolean,required:!1,default:!0},max:{type:Number,required:!1,default:-1},showOptions:{type:Boolean,required:!1,default:!0},addTagOn:{type:Array,required:!1,default:()=>["enter"]},required:{type:Boolean,required:!1,default:!1}},setup(u,r){const o=function(n,a){var u=e(n),r=u.value,o=u.modelValue,i=u.mode,c=u.valueProp,s=l("single"!==i.value?[]:{}),v=void 0!==a.expose?o:r,d=t((function(){return"single"!==i.value?s.value.map((function(e){return e[c.value]})).join(","):s.value[c.value]}));return{iv:s,ev:v,textValue:d}}(u,r),i=function(n,a,u){var r=e(n),o=r.searchable,i=(r.id,l(null)),c=t((function(){return o.value?-1:0}));return{multiselect:i,tabindex:c,focusInput:function(){i.value.querySelector(".multiselect-input").focus()},blurInput:function(){i.value.querySelector(".multiselect-input").blur()}}}(u),c={pointer:l(null)},s=function(l,t,n){var a=e(l),u=a.object,r=a.valueProp,o=a.mode,i=n.iv,c=function(e){return u.value||S(e)?e:Array.isArray(e)?e.map((function(e){return e[r.value]})):e[r.value]},s=function(e){return S(e)?"single"===o.value?{}:[]:e};return{update:function(e){i.value=s(e);var l=c(e);t.emit("change",l),t.emit("input",l),t.emit("update:modelValue",l)}}}(u,r,{iv:o.iv}),v=function(a,u,r){var o=e(a),i=o.searchable,c=o.mode,s=r.iv,v=l(null),d=l(null),p=t((function(){return v.value?"".concat(v.value.length,"ch"):"tags"===c.value&&-1===[null,void 0].indexOf(s.value)&&s.value.length?"1ch":"100%"}));return n(v,(function(e){u.emit("search-change",e)})),{search:v,input:d,tagsSearchWidth:p,clearSearch:function(){v.value=""},focusSearch:function(){d.value.focus()},blurSearch:function(){i.value&&d.value.blur()}}}(u,r,{iv:o.iv}),d=function(n,a,u){var r=e(n),o=r.maxHeight,i=r.disabled,c=r.searchable,s=u.multiselect,v=u.blurInput,d=u.blurSearch,p=u.focusInput,f=u.focusSearch,h=l(!1),m=t((function(){return"".concat(o.value,"px")}));return{isOpen:h,contentMaxHeight:m,openDropdown:function(){i.value||(h.value=!0,a.emit("open"))},closeDropdown:function(){h.value=!1,a.emit("close")},open:function(){c&&c.value?f():p()},close:function(){c&&c.value?d():v()},handleInputMousedown:function(e){h.value&&!c.value&&(s.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),s.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(u,r,{multiselect:i.multiselect,blurInput:i.blurInput,blurSearch:v.blurSearch,focusInput:i.focusInput,focusSearch:v.focusSearch}),p=q(u,r,{ev:o.ev,iv:o.iv,search:v.search,blurSearch:v.blurSearch,clearSearch:v.clearSearch,update:s.update,blurInput:i.blurInput,pointer:c.pointer}),f=function(l,u,r){var o=e(l),i=o.id,c=o.valueProp,s=r.fo,v=r.handleOptionClick,d=r.search,p=r.pointer,f=t((function(){return s.value.filter((function(e){return!0!==e.disabled}))})),h=function(e){p.value=e},m=function(){p.value=f.value[0]||null},b=function(){p.value=null},g=function(){var e=document.getElementById(i.value).querySelector(".is-pointed");if(e){var l=e.parentElement;e.offsetTop+e.offsetHeight>l.clientHeight+l.scrollTop&&(l.scrollTop=e.offsetTop+e.offsetHeight-l.clientHeight),e.offsetTop<l.scrollTop&&(l.scrollTop=e.offsetTop)}};return n(d,(function(e){m()})),{pointer:p,isPointed:function(e){return!!p.value&&p.value[c.value]==e[c.value]},setPointer:h,setPointerFirst:m,clearPointer:b,selectPointer:function(){p.value&&!0!==p.value.disabled?(v(p.value),b()):b()},forwardPointer:function(){if(null===p.value)h(f.value[0]||null);else{var e=f.value.map((function(e){return e[c.value]})).indexOf(p.value[c.value])+1;f.value.length<=e&&(e=0),h(f.value[e]||null)}a((function(){g()}))},backwardPointer:function(){if(null===p.value)h(f.value[f.value.length-1]||null);else{var e=f.value.map((function(e){return e[c.value]})).indexOf(p.value[c.value])-1;e<0&&(e=f.value.length-1),h(f.value[e]||null)}a((function(){g()}))}}}(u,0,{fo:p.fo,handleOptionClick:p.handleOptionClick,search:v.search,pointer:c.pointer}),h=function(l,t,n){var u=e(l),r=u.mode,o=u.addTagOn,i=u.createTag,c=n.iv,s=n.update,v=n.closeDropdown,d=n.clearPointer,p=n.search,f=n.selectPointer;return{handleBackspace:function(e){"single"!==r.value&&s(P(c.value).slice(0,-1))},handleEsc:function(e){v(),d(),e.target.blur()},handleSearchBackspace:function(e){""!==p.value&&e.stopPropagation()},handleSearchInput:function(e){p.value=e.target.value},handleAddTag:function(e){13!==e.keyCode||-1===o.value.indexOf("enter")&&i.value?32===e.keyCode&&-1!==o.value.indexOf("space")&&i.value&&(p.value=p.value.trim(),a((function(){f()}))):f()}}}(u,0,{iv:o.iv,update:s.update,closeDropdown:d.closeDropdown,clearPointer:f.clearPointer,search:v.search,selectPointer:f.selectPointer});return{...o,...d,...i,...c,...s,...v,...p,...f,...h}}};const B={class:"multiselect-single-label"},I={class:"multiselect-multiple-label"},D={key:2,class:"multiselect-search"},A={key:3,class:"multiselect-tags"},j={class:"multiselect-tag"},M={class:"multiselect-placeholder"},C=c("span",{class:"multiselect-caret"},null,-1),E={key:0},$=c("span",{class:"multiselect-spinner"},null,-1),H={class:"multiselect-no-options"},L={class:"multiselect-no-results"};T.render=function(e,l,t,n,a,S){return u(),r("div",{class:["multiselect",[`is-${t.mode}`,{"is-open":e.isOpen,"is-searchable":t.searchable,"is-disabled":t.disabled,"no-caret":!t.caret}]],id:t.id,onKeydown:l[29]||(l[29]=o(i((()=>{}),["prevent"]),["enter"])),ref:"multiselect"},[c("div",{class:"multiselect-input",tabindex:e.tabindex,onMousedown:l[20]||(l[20]=(...l)=>e.handleInputMousedown&&e.handleInputMousedown(...l)),onFocus:l[21]||(l[21]=(...l)=>e.openDropdown&&e.openDropdown(...l)),onBlur:l[22]||(l[22]=(...l)=>e.closeDropdown&&e.closeDropdown(...l)),onKeyup:[l[23]||(l[23]=o(((...l)=>e.handleEsc&&e.handleEsc(...l)),["esc"])),l[24]||(l[24]=o(((...l)=>e.selectPointer&&e.selectPointer(...l)),["enter"]))],onKeydown:[l[25]||(l[25]=o(i(((...l)=>e.handleBackspace&&e.handleBackspace(...l)),["prevent"]),["delete"])),l[26]||(l[26]=o(i(((...l)=>e.backwardPointer&&e.backwardPointer(...l)),["prevent"]),["up"])),l[27]||(l[27]=o(i(((...l)=>e.forwardPointer&&e.forwardPointer(...l)),["prevent"]),["down"]))]},[s(" Single label "),"single"==t.mode&&e.hasSelected&&!e.search&&e.iv?v(e.$slots,"singlelabel",{key:0,value:e.iv},(()=>[c("div",B,d(e.iv[t.label]),1)])):s("v-if",!0),s(" Multiple label "),"multiple"==t.mode&&e.hasSelected&&!e.search?v(e.$slots,"multiplelabel",{key:1,values:e.iv},(()=>[c("div",I,d(e.multipleLabelText),1)])):s("v-if",!0),s(" Search "),"tags"!==t.mode&&t.searchable&&!t.disabled?(u(),r("div",D,[c("input",{modelValue:e.search,value:e.search,onFocus:l[1]||(l[1]=i(((...l)=>e.openDropdown&&e.openDropdown(...l)),["stop"])),onBlur:l[2]||(l[2]=i(((...l)=>e.closeDropdown&&e.closeDropdown(...l)),["stop"])),onKeyup:[l[3]||(l[3]=o(i(((...l)=>e.handleEsc&&e.handleEsc(...l)),["stop"]),["esc"])),l[4]||(l[4]=o(i(((...l)=>e.selectPointer&&e.selectPointer(...l)),["stop"]),["enter"]))],onKeydown:[l[5]||(l[5]=o(((...l)=>e.handleSearchBackspace&&e.handleSearchBackspace(...l)),["delete"])),l[6]||(l[6]=o(i(((...l)=>e.backwardPointer&&e.backwardPointer(...l)),["stop"]),["up"])),l[7]||(l[7]=o(i(((...l)=>e.forwardPointer&&e.forwardPointer(...l)),["stop"]),["down"]))],onInput:l[8]||(l[8]=(...l)=>e.handleSearchInput&&e.handleSearchInput(...l)),ref:"input"},null,40,["modelValue","value"])])):s("v-if",!0),s(" Tags (with search) "),"tags"==t.mode?(u(),r("div",A,[(u(!0),r(p,null,f(e.iv,((n,a,o)=>(u(),r("span",{key:o},[v(e.$slots,"tag",{option:n,handleTagRemove:e.handleTagRemove,disabled:t.disabled},(()=>[c("div",j,[h(d(n[t.label])+" ",1),t.disabled?s("v-if",!0):(u(),r("i",{key:0,onClick:l[9]||(l[9]=i((()=>{}),["prevent"])),onMousedown:i((l=>e.handleTagRemove(n,l)),["prevent","stop"])},null,40,["onMousedown"]))])]))])))),128)),t.searchable&&!t.disabled?(u(),r("div",{key:0,class:"multiselect-search",style:{width:e.tagsSearchWidth}},[c("input",{modelValue:e.search,value:e.search,onFocus:l[10]||(l[10]=i(((...l)=>e.openDropdown&&e.openDropdown(...l)),["stop"])),onBlur:l[11]||(l[11]=i(((...l)=>e.closeDropdown&&e.closeDropdown(...l)),["stop"])),onKeyup:[l[12]||(l[12]=o(i(((...l)=>e.handleEsc&&e.handleEsc(...l)),["stop"]),["esc"])),l[13]||(l[13]=o(i(((...l)=>e.handleAddTag&&e.handleAddTag(...l)),["stop"]),["enter"])),l[14]||(l[14]=o(i(((...l)=>e.handleAddTag&&e.handleAddTag(...l)),["stop"]),["space"]))],onKeydown:[l[15]||(l[15]=o(((...l)=>e.handleSearchBackspace&&e.handleSearchBackspace(...l)),["delete"])),l[16]||(l[16]=o(i(((...l)=>e.backwardPointer&&e.backwardPointer(...l)),["stop"]),["up"])),l[17]||(l[17]=o(i(((...l)=>e.forwardPointer&&e.forwardPointer(...l)),["stop"]),["down"]))],onInput:l[18]||(l[18]=(...l)=>e.handleSearchInput&&e.handleSearchInput(...l)),style:{width:e.tagsSearchWidth},ref:"input"},null,44,["modelValue","value"])],4)):s("v-if",!0)])):s("v-if",!0),s(" Placeholder "),!t.placeholder||e.hasSelected||e.search?s("v-if",!0):v(e.$slots,"placeholder",{key:4},(()=>[c("div",M,d(t.placeholder),1)])),t.caret&&!e.busy?v(e.$slots,"caret",{key:5},(()=>[C])):s("v-if",!0),c(m,{name:"multiselect-loading"},{default:b((()=>[e.busy?(u(),r("span",E,[v(e.$slots,"spinner",{},(()=>[$]))])):s("v-if",!0)])),_:1}),e.hasSelected&&!t.disabled?v(e.$slots,"clear",{key:6,clear:e.clear},(()=>[c("a",{class:"multiselect-clear",onClick:l[19]||(l[19]=i(((...l)=>e.clear&&e.clear(...l)),["prevent"]))})])):s("v-if",!0)],40,["tabindex"]),s(" Options "),e.resolving&&t.clearOnSearch?s("v-if",!0):(u(),r(m,{key:0,name:"multiselect",onAfterLeave:e.clearSearch},{default:b((()=>[g(c("div",{class:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[v(e.$slots,"beforelist"),(u(!0),r(p,null,f(e.fo,((n,a,o)=>(u(),r("span",{tabindex:-1,class:["multiselect-option",{"is-pointed":e.isPointed(n),"is-selected":e.isSelected(n),"is-disabled":e.isDisabled(n)}],key:o,onMousedown:l[28]||(l[28]=i((()=>{}),["prevent"])),onMouseenter:l=>e.setPointer(n),onClick:i((l=>e.handleOptionClick(n)),["stop","prevent"])},[v(e.$slots,"option",{option:n,search:e.search},(()=>[c("span",null,d(n[t.label]),1)]))],42,["onMouseenter","onClick"])))),128)),g(c("span",null,[v(e.$slots,"nooptions",{},(()=>[c("div",H,d(t.noOptionsText),1)]))],512),[[y,e.noOptions]]),g(c("span",null,[v(e.$slots,"noresults",{},(()=>[c("div",L,d(t.noResultsText),1)]))],512),[[y,e.noResults]]),v(e.$slots,"afterlist")],4),[[y,e.isOpen&&t.showOptions]])])),_:3},8,["onAfterLeave"])),s(" Hacky input element to show HTML5 required warning "),t.required?(u(),r("input",{key:1,class:"multiselect-fake-input",tabindex:"-1",value:e.textValue,required:""},null,8,["value"])):s("v-if",!0)],42,["id"])},T.__file="src/Multiselect.vue";export default T; |
@@ -1,1 +0,1 @@ | ||
var VueformMultiselect=function(e){"use strict";function t(e){return-1!==[null,void 0,!1].indexOf(e)}function n(e){return(n="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 a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e)||function(){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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function r(e){return String(e).toLowerCase().trim()}var i={};function o(l,u,o){var c=e.toRefs(l),s=c.options,d=c.mode,f=c.trackBy,p=c.limit,v=c.hideSelected,h=c.createTag,y=c.label,m=c.appendNewTag,g=c.multipleLabel,b=c.object,k=c.loading,_=c.delay,w=c.resolveOnLoad,O=c.minChars,S=c.filterResults,x=c.clearOnSearch,C=c.clearOnSelect,P=c.valueProp,q=c.canDeselect,D=c.max,T=o.internalValue,V=o.externalValue,B=o.currentValue,E=o.search,R=o.blurSearch,A=o.clearSearch,I=o.update,j=o.blurInput,N=o.pointer,H=e.ref([]),U=e.ref([]),M=e.ref(!1),$=e.computed((function(){var e,t=U.value||[];return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(t=Object.keys(t).map((function(e){var n,l=t[e];return a(n={},P.value,e),a(n,f.value,l),a(n,y.value,l),n}))),t=t.map((function(e,t){var l;return"object"===n(e)?e:(a(l={},P.value,t),a(l,f.value,e),a(l,y.value,e),l)})),H.value.length&&(t=t.concat(H.value)),t})),L=e.computed((function(){var e=$.value;return z.value.length&&(e=z.value.concat(e)),E.value&&S.value&&(e=e.filter((function(e){return-1!==r(e[f.value]).indexOf(r(E.value))}))),v.value&&(e=e.filter((function(e){return!ie(e)}))),p.value>0&&(e=e.slice(0,p.value)),e})),F=e.computed((function(){switch(d.value){case"single":return!t(T.value[P.value]);case"multiple":case"tags":return!t(T.value)&&T.value.length>0}})),J=e.computed((function(){return void 0!==g&&void 0!==g.value?g.value(T.value):T.value&&T.value.length>1?"".concat(T.value.length," options selected"):"1 option selected"})),W=e.computed((function(){return!$.value.length&&!M.value})),X=e.computed((function(){return $.value.length>0&&0==L.value.length})),z=e.computed((function(){var e;return!1!==h.value&&E.value?-1!==re(E.value)?[]:[(e={},a(e,P.value,E.value),a(e,y.value,E.value),a(e,f.value,E.value),e)]:[]})),G=e.computed((function(){switch(d.value){case"single":return null;case"multiple":case"tags":return[]}})),K=e.computed((function(){return k.value||M.value})),Q=function(e){switch("object"!==n(e)&&(e=ue(e)),d.value){case"single":I(e);break;case"multiple":case"tags":I(T.value.concat(e))}u.emit("select",Z(e))},Y=function(e){switch("object"!==n(e)&&(e=ue(e)),d.value){case"single":te();break;case"tags":case"multiple":I(T.value.filter((function(t){return t[P.value]!=e[P.value]})))}u.emit("deselect",Z(e))},Z=function(e){return b.value?e:e[P.value]},ee=function(e){Y(e)},te=function(){I(G.value)},ne=function(e){switch(d.value){case"single":return!t(T.value)&&T.value[P.value]==e[P.value];case"tags":case"multiple":return!t(T.value)&&-1!==T.value.map((function(e){return e[P.value]})).indexOf(e[P.value])}},ae=function(e){return!0===e.disabled},le=function(){return!(void 0===D||-1===D.value||!F.value&&D.value>0)&&T.value.length>=D.value},ue=function(e){return $.value[$.value.map((function(e){return String(e[P.value])})).indexOf(String(e))]},re=function(e){return $.value.map((function(e){return r(e[f.value])})).indexOf(r(e))},ie=function(e){return"tags"===d.value&&v.value&&ne(e)},oe=function(e){H.value.push(e)},ce=function(){t(V.value)||(T.value=de(V.value))},se=function(e){M.value=!0,s.value(E.value).then((function(t){U.value=t,"function"==typeof e&&e(t),M.value=!1}))},de=function(e){return t(e)?"single"===d.value?{}:[]:b.value?e:"single"===d.value?ue(e)||{}:e.filter((function(e){return!!ue(e)})).map((function(e){return ue(e)}))};if("single"!==d.value&&!t(V.value)&&!Array.isArray(V.value))throw new Error('v-model must be an array when using "'.concat(d.value,'" mode'));return s&&"function"==typeof s.value?w.value?se(ce):1==b.value&&ce():(U.value=s.value,ce()),_.value>-1&&e.watch(E,(function(e){e.length<O.value||(M.value=!0,x.value&&(U.value=[]),setTimeout((function(){e==E.value&&s.value(E.value).then((function(t){e==E.value&&(U.value=t,N.value=L.value.filter((function(e){return!0!==e.disabled}))[0]||null,M.value=!1)}))}),_.value))}),{flush:"sync"}),e.watch(V,(function(e){var n,a,l;if(t(e))T.value=de(e);else switch(d.value){case"single":(b.value?e[P.value]!=T.value[P.value]:e!=T.value[P.value])&&(T.value=de(e));break;case"multiple":case"tags":n=b.value?e.map((function(e){return e[P.value]})):e,a=T.value.map((function(e){return e[P.value]})),l=a.slice().sort(),n.length===a.length&&n.slice().sort().every((function(e,t){return e===l[t]}))||(T.value=de(e))}}),{deep:!0}),"function"!=typeof l.options&&(e.watch((function(){return l.options}),(function(e,t){U.value=l.options})),e.watch($,(function(e,t){if(Object.keys(T.value).length||ce(),e.length&&B.value&&B.value.length){var n;if("single"===d.value){if(n=e[e.map((function(e){return e[P.value]})).indexOf(B.value)],JSON.stringify(n)===JSON.stringify(T.value))return}else if(n=[],B.value.forEach((function(t){n.push(e[e.map((function(e){return e[P.value]})).indexOf(t)])})),function(e,t){var n=e.length===t.length;if(!n)return n;try{e.every((function(e,n){if(JSON.stringify(e)!==JSON.stringify(t[n]))throw i}))}catch(e){if(e!==i)throw e;n=!1}return n}(n,T.value))return;b.value?I(n):T.value=n}}),{flush:"sync",deep:!0,immediate:!1})),{filteredOptions:L,hasSelected:F,multipleLabelText:J,extendedOptions:$,noOptions:W,noResults:X,resolving:M,busy:K,select:Q,deselect:Y,remove:ee,clear:te,isSelected:ne,isDisabled:ae,isMax:le,getOption:ue,handleOptionClick:function(e){if(!ae(e))switch(d.value){case"single":if(ne(e))return void(q.value&&Y(e));Q(e),R(),j();break;case"multiple":if(ne(e))return void Y(e);if(le())return;Q(e),C.value&&A();break;case"tags":if(ne(e))return void Y(e);if(le())return;void 0===ue(e[P.value])&&h.value&&(u.emit("tag",e[P.value]),m.value&&oe(e),A()),C.value&&A(),Q(e)}},handleTagRemove:function(e,t){0===t.button?ee(e):t.preventDefault()},refreshOptions:function(e){se(e)},resolveOptions:se}}function c(e,t,n,a,l,u,r,i,o,c){"boolean"!=typeof r&&(o=i,i=r,r=!1);var s,d="function"==typeof n?n.options:n;if(e&&e.render&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0,l&&(d.functional=!0)),a&&(d._scopeId=a),u?(s=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,o(e)),e&&e._registeredComponents&&e._registeredComponents.add(u)},d._ssrRegister=s):t&&(s=r?function(e){t.call(this,c(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,i(e))}),s)if(d.functional){var f=d.render;d.render=function(e,t){return s.call(t),f(e,t)}}else{var p=d.beforeCreate;d.beforeCreate=p?[].concat(p,s):[s]}return n}const s={name:"Multiselect",emits:["open","close","select","deselect","input","search-change","tag","update:modelValue","change"],props:{value:{required:!1},modelValue:{required:!1},options:{type:[Array,Object,Function],required:!1,default:()=>[]},id:{type:[String,Number],required:!1,default:"multiselect"},name:{type:[String,Number],required:!1,default:"multiselect"},disabled:{type:Boolean,required:!1,default:!1},label:{type:String,required:!1,default:"label"},trackBy:{type:String,required:!1,default:"label"},valueProp:{type:String,required:!1,default:"value"},placeholder:{type:String,required:!1,default:null},mode:{type:String,required:!1,default:"single"},searchable:{type:Boolean,required:!1,default:!1},limit:{type:Number,required:!1,default:-1},maxHeight:{type:Number,required:!1,default:160},hideSelected:{type:Boolean,required:!1,default:!0},createTag:{type:Boolean,required:!1,default:!1},appendNewTag:{type:Boolean,required:!1,default:!0},caret:{type:Boolean,required:!1,default:!0},loading:{type:Boolean,required:!1,default:!1},noOptionsText:{type:String,required:!1,default:"The list is empty"},noResultsText:{type:String,required:!1,default:"No results found"},multipleLabel:{type:Function,required:!1},object:{type:Boolean,required:!1,default:!1},delay:{type:Number,required:!1,default:-1},minChars:{type:Number,required:!1,default:0},resolveOnLoad:{type:Boolean,required:!1,default:!0},filterResults:{type:Boolean,required:!1,default:!0},clearOnSearch:{type:Boolean,required:!1,default:!1},clearOnSelect:{type:Boolean,required:!1,default:!0},canDeselect:{type:Boolean,required:!1,default:!0},max:{type:Number,required:!1,default:-1},showOptions:{type:Boolean,required:!1,default:!0},addTagOn:{type:Array,required:!1,default:()=>["enter"]},required:{type:Boolean,required:!1,default:!1}},setup(n,a){const u=function(t,n){var a=e.toRefs(t),l=a.value,u=a.modelValue,r=a.mode,i=a.valueProp,o=e.ref("single"!==r.value?[]:{}),c=void 0!==n.expose?u:l,s=e.computed((function(){return Object.keys(o.value).length?"single"!==r.value?o.value.map((function(e){return e[i.value]})):o.value[i.value]:o.value})),d=e.computed((function(){return"single"!==r.value?o.value.map((function(e){return e[i.value]})).join(","):o.value[i.value]}));return{internalValue:o,externalValue:c,currentValue:s,textValue:d}}(n,a),r=function(t,n,a){var l=e.toRefs(t),u=l.searchable,r=(l.id,e.ref(null)),i=e.computed((function(){return u.value?-1:0}));return{multiselect:r,tabindex:i,focusInput:function(){r.value.querySelector(".multiselect-input").focus()},blurInput:function(){r.value.querySelector(".multiselect-input").blur()}}}(n),i={pointer:e.ref(null)},c=function(n,a,l){var u=e.toRefs(n),r=u.object,i=u.valueProp,o=u.mode,c=l.internalValue,s=function(e){return r.value||t(e)?e:Array.isArray(e)?e.map((function(e){return e[i.value]})):e[i.value]},d=function(e){return t(e)?"single"===o.value?{}:[]:e};return{update:function(e){c.value=d(e);var t=s(e);a.emit("change",t),a.emit("input",t),a.emit("update:modelValue",t)}}}(n,a,{internalValue:u.internalValue}),s=function(t,n,a){var l=e.toRefs(t),u=l.searchable,r=l.mode,i=a.internalValue,o=e.ref(null),c=e.ref(null),s=e.computed((function(){return o.value?"".concat(o.value.length,"ch"):"tags"===r.value&&-1===[null,void 0].indexOf(i.value)&&i.value.length?"1ch":"100%"}));return e.watch(o,(function(e){n.emit("search-change",e)})),{search:o,input:c,tagsSearchWidth:s,clearSearch:function(){o.value=""},focusSearch:function(){c.value.focus()},blurSearch:function(){u.value&&c.value.blur()}}}(n,a,{internalValue:u.internalValue}),d=function(t,n,a){var l=e.toRefs(t),u=l.maxHeight,r=l.disabled,i=l.searchable,o=a.multiselect,c=a.blurInput,s=a.blurSearch,d=a.focusInput,f=a.focusSearch,p=e.ref(!1),v=e.computed((function(){return"".concat(u.value,"px")}));return{isOpen:p,contentMaxHeight:v,openDropdown:function(){r.value||(p.value=!0,n.emit("open"))},closeDropdown:function(){p.value=!1,n.emit("close")},open:function(){i&&i.value?f():d()},close:function(){i&&i.value?s():c()},handleInputMousedown:function(e){p.value&&!i.value&&(o.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),o.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(n,a,{multiselect:r.multiselect,blurInput:r.blurInput,blurSearch:s.blurSearch,focusInput:r.focusInput,focusSearch:s.focusSearch}),f=o(n,a,{externalValue:u.externalValue,internalValue:u.internalValue,currentValue:u.currentValue,search:s.search,blurSearch:s.blurSearch,clearSearch:s.clearSearch,update:c.update,blurInput:r.blurInput,pointer:i.pointer}),p=function(t,n,a){var l=e.toRefs(t),u=l.id,r=l.valueProp,i=a.filteredOptions,o=a.handleOptionClick,c=a.search,s=a.pointer,d=e.computed((function(){return i.value.filter((function(e){return!0!==e.disabled}))})),f=function(e){s.value=e},p=function(){s.value=d.value[0]||null},v=function(){s.value=null},h=function(){var e=document.getElementById(u.value).querySelector(".is-pointed");if(e){var t=e.parentElement;e.offsetTop+e.offsetHeight>t.clientHeight+t.scrollTop&&(t.scrollTop=e.offsetTop+e.offsetHeight-t.clientHeight),e.offsetTop<t.scrollTop&&(t.scrollTop=e.offsetTop)}};return e.watch(c,(function(e){p()})),{pointer:s,isPointed:function(e){return!!s.value&&s.value[r.value]==e[r.value]},setPointer:f,setPointerFirst:p,clearPointer:v,selectPointer:function(){s.value&&!0!==s.value.disabled?(o(s.value),v()):v()},forwardPointer:function(){if(null===s.value)f(d.value[0]||null);else{var t=d.value.map((function(e){return e[r.value]})).indexOf(s.value[r.value])+1;d.value.length<=t&&(t=0),f(d.value[t]||null)}e.nextTick((function(){h()}))},backwardPointer:function(){if(null===s.value)f(d.value[d.value.length-1]||null);else{var t=d.value.map((function(e){return e[r.value]})).indexOf(s.value[r.value])-1;t<0&&(t=d.value.length-1),f(d.value[t]||null)}e.nextTick((function(){h()}))}}}(n,0,{filteredOptions:f.filteredOptions,handleOptionClick:f.handleOptionClick,search:s.search,pointer:i.pointer}),v=function(t,n,a){var u=e.toRefs(t),r=u.mode,i=u.addTagOn,o=u.createTag,c=a.internalValue,s=a.update,d=a.closeDropdown,f=a.clearPointer,p=a.search,v=a.selectPointer;return{handleBackspace:function(e){"single"!==r.value&&s(l(c.value).slice(0,-1))},handleEsc:function(e){d(),f(),e.target.blur()},handleSearchBackspace:function(e){""!==p.value&&e.stopPropagation()},handleSearchInput:function(e){p.value=e.target.value},handleAddTag:function(t){13!==t.keyCode||-1===i.value.indexOf("enter")&&o.value?32===t.keyCode&&-1!==i.value.indexOf("space")&&o.value&&(p.value=p.value.trim(),e.nextTick((function(){v()}))):v()}}}(n,0,{internalValue:u.internalValue,update:c.update,closeDropdown:d.closeDropdown,clearPointer:p.clearPointer,search:s.search,selectPointer:p.selectPointer});return{...u,...d,...r,...i,...c,...s,...f,...p,...v}}};var d=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{ref:"multiselect",staticClass:"multiselect",class:["is-"+e.mode,{"is-open":e.isOpen,"is-searchable":e.searchable,"is-disabled":e.disabled,"no-caret":!e.caret}],attrs:{id:e.id},on:{keydown:function(t){if(!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter"))return null;t.preventDefault()}}},[n("div",{staticClass:"multiselect-input",attrs:{tabindex:e.tabindex},on:{mousedown:e.handleInputMousedown,focus:e.openDropdown,blur:e.closeDropdown,keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:e.handleEsc(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:e.selectPointer(t)}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:(t.preventDefault(),e.handleBackspace(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.preventDefault(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.preventDefault(),e.forwardPointer(t))}]}},["single"==e.mode&&e.hasSelected&&!e.search&&e.internalValue?[e._t("singlelabel",[n("div",{staticClass:"multiselect-single-label"},[e._v("\n "+e._s(e.internalValue[e.label])+"\n ")])],{value:e.internalValue})]:e._e(),e._v(" "),"multiple"==e.mode&&e.hasSelected&&!e.search?[e._t("multiplelabel",[n("div",{staticClass:"multiselect-multiple-label"},[e._v("\n "+e._s(e.multipleLabelText)+"\n ")])],{values:e.internalValue})]:e._e(),e._v(" "),"tags"!==e.mode&&e.searchable&&!e.disabled?[n("div",{staticClass:"multiselect-search"},[n("input",{ref:"input",attrs:{modelValue:e.search},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.openDropdown(t)},blur:function(t){return t.stopPropagation(),e.closeDropdown(t)},keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:(t.stopPropagation(),e.handleEsc(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:(t.stopPropagation(),e.selectPointer(t))}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:e.handleSearchBackspace(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.stopPropagation(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.stopPropagation(),e.forwardPointer(t))}],input:e.handleSearchInput}})])]:e._e(),e._v(" "),"tags"==e.mode?[n("div",{staticClass:"multiselect-tags"},[e._l(e.internalValue,(function(t,a,l){return n("span",{key:l},[e._t("tag",[n("div",{staticClass:"multiselect-tag"},[e._v("\n "+e._s(t[e.label])+"\n "),e.disabled?e._e():n("i",{on:{click:function(e){e.preventDefault()},mousedown:function(n){return n.preventDefault(),n.stopPropagation(),e.handleTagRemove(t,n)}}})])],{option:t,handleTagRemove:e.handleTagRemove,disabled:e.disabled})],2)})),e._v(" "),e.searchable&&!e.disabled?n("div",{staticClass:"multiselect-search",style:{width:e.tagsSearchWidth}},[n("input",{ref:"input",style:{width:e.tagsSearchWidth},attrs:{modelValue:e.search},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.openDropdown(t)},blur:function(t){return t.stopPropagation(),e.closeDropdown(t)},keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:(t.stopPropagation(),e.handleEsc(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:(t.stopPropagation(),e.handleAddTag(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"space",32,t.key,[" ","Spacebar"])?null:(t.stopPropagation(),e.handleAddTag(t))}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:e.handleSearchBackspace(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.stopPropagation(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.stopPropagation(),e.forwardPointer(t))}],input:e.handleSearchInput}})]):e._e()],2)]:e._e(),e._v(" "),!e.placeholder||e.hasSelected||e.search?e._e():[e._t("placeholder",[n("div",{staticClass:"multiselect-placeholder"},[e._v("\n "+e._s(e.placeholder)+"\n ")])])],e._v(" "),e.caret&&!e.busy?e._t("caret",[n("span",{staticClass:"multiselect-caret"})]):e._e(),e._v(" "),n("transition",{attrs:{name:"multiselect-loading"}},[e.busy?n("span",[e._t("spinner",[n("span",{staticClass:"multiselect-spinner"})])],2):e._e()]),e._v(" "),e.hasSelected&&!e.disabled?e._t("clear",[n("a",{staticClass:"multiselect-clear",on:{click:function(t){return t.preventDefault(),e.clear(t)}}})],{clear:e.clear}):e._e()],2),e._v(" "),e.resolving&&e.clearOnSearch?e._e():n("transition",{attrs:{name:"multiselect"},on:{"after-leave":e.clearSearch}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.isOpen&&e.showOptions,expression:"isOpen && showOptions"}],staticClass:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[e._t("beforelist"),e._v(" "),e._l(e.filteredOptions,(function(t,a,l){return n("span",{key:l,staticClass:"multiselect-option",class:{"is-pointed":e.isPointed(t),"is-selected":e.isSelected(t),"is-disabled":e.isDisabled(t)},attrs:{tabindex:-1},on:{mousedown:function(e){e.preventDefault()},mouseenter:function(n){return e.setPointer(t)},click:function(n){return n.stopPropagation(),n.preventDefault(),e.handleOptionClick(t)}}},[e._t("option",[n("span",[e._v(e._s(t[e.label]))])],{option:t,search:e.search})],2)})),e._v(" "),n("span",{directives:[{name:"show",rawName:"v-show",value:e.noOptions,expression:"noOptions"}]},[e._t("nooptions",[n("div",{staticClass:"multiselect-no-options"},[e._v(e._s(e.noOptionsText))])])],2),e._v(" "),n("span",{directives:[{name:"show",rawName:"v-show",value:e.noResults,expression:"noResults"}]},[e._t("noresults",[n("div",{staticClass:"multiselect-no-results"},[e._v(e._s(e.noResultsText))])])],2),e._v(" "),e._t("afterlist")],2)]),e._v(" "),e.required?n("input",{staticClass:"multiselect-fake-input",attrs:{tabindex:"-1",required:""},domProps:{value:e.textValue}}):e._e()],1)};d._withStripped=!0;return c({render:d,staticRenderFns:[]},undefined,s,undefined,false,undefined,!1,void 0,void 0,void 0)}(VueCompositionAPI); | ||
var VueformMultiselect=function(e){"use strict";function t(e){return-1!==[null,void 0,!1].indexOf(e)}function n(e){return(n="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 a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e){return function(e){if(Array.isArray(e))return l(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return l(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return l(e,t)}(e)||function(){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 l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function r(e){return String(e).toLowerCase().trim()}function o(u,l,o){var i=e.toRefs(u),c=i.options,s=i.mode,d=i.trackBy,v=i.limit,p=i.hideSelected,f=i.createTag,h=i.label,y=i.appendNewTag,m=i.multipleLabel,g=i.object,b=i.loading,k=i.delay,_=i.resolveOnLoad,w=i.minChars,S=i.filterResults,O=i.clearOnSearch,x=i.clearOnSelect,C=i.valueProp,P=i.canDeselect,q=i.max,D=o.iv,T=o.ev,B=o.search,E=o.blurSearch,R=o.clearSearch,A=o.update,I=o.blurInput,j=o.pointer,N=e.ref([]),V=e.ref([]),H=e.ref(!1),U=e.computed((function(){var e,t=V.value||[];return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(t=Object.keys(t).map((function(e){var n,u=t[e];return a(n={},C.value,e),a(n,d.value,u),a(n,h.value,u),n}))),t=t.map((function(e,t){var u;return"object"===n(e)?e:(a(u={},C.value,e),a(u,d.value,e),a(u,h.value,e),u)})),N.value.length&&(t=t.concat(N.value)),t})),M=e.computed((function(){var e=U.value;return X.value.length&&(e=X.value.concat(e)),B.value&&S.value&&(e=e.filter((function(e){return-1!==r(e[d.value]).indexOf(r(B.value))}))),p.value&&(e=e.filter((function(e){return!le(e)}))),v.value>0&&(e=e.slice(0,v.value)),e})),$=e.computed((function(){switch(s.value){case"single":return!t(D.value[C.value]);case"multiple":case"tags":return!t(D.value)&&D.value.length>0}})),L=e.computed((function(){return void 0!==m&&void 0!==m.value?m.value(D.value):D.value&&D.value.length>1?"".concat(D.value.length," options selected"):"1 option selected"})),F=e.computed((function(){return!U.value.length&&!H.value})),W=e.computed((function(){return U.value.length>0&&0==M.value.length})),X=e.computed((function(){var e;return!1!==f.value&&B.value?-1!==ue(B.value)?[]:[(e={},a(e,C.value,B.value),a(e,h.value,B.value),a(e,d.value,B.value),e)]:[]})),z=e.computed((function(){switch(s.value){case"single":return null;case"multiple":case"tags":return[]}})),G=e.computed((function(){return b.value||H.value})),J=function(e){switch("object"!==n(e)&&(e=ae(e)),s.value){case"single":A(e);break;case"multiple":case"tags":A(D.value.concat(e))}l.emit("select",Q(e))},K=function(e){switch("object"!==n(e)&&(e=ae(e)),s.value){case"single":Z();break;case"tags":case"multiple":A(D.value.filter((function(t){return t[C.value]!=e[C.value]})))}l.emit("deselect",Q(e))},Q=function(e){return g.value?e:e[C.value]},Y=function(e){K(e)},Z=function(){A(z.value)},ee=function(e){switch(s.value){case"single":return!t(D.value)&&D.value[C.value]==e[C.value];case"tags":case"multiple":return!t(D.value)&&-1!==D.value.map((function(e){return e[C.value]})).indexOf(e[C.value])}},te=function(e){return!0===e.disabled},ne=function(){return!(void 0===q||-1===q.value||!$.value&&q.value>0)&&D.value.length>=q.value},ae=function(e){return U.value[U.value.map((function(e){return String(e[C.value])})).indexOf(String(e))]},ue=function(e){return U.value.map((function(e){return r(e[d.value])})).indexOf(r(e))},le=function(e){return"tags"===s.value&&p.value&&ee(e)},re=function(e){N.value.push(e)},oe=function(){t(T.value)||(D.value=ce(T.value))},ie=function(e){H.value=!0,c.value(B.value).then((function(t){V.value=t,"function"==typeof e&&e(t),H.value=!1}))},ce=function(e){return t(e)?"single"===s.value?{}:[]:g.value?e:"single"===s.value?ae(e)||{}:e.filter((function(e){return!!ae(e)})).map((function(e){return ae(e)}))};if("single"!==s.value&&!t(T.value)&&!Array.isArray(T.value))throw new Error('v-model must be an array when using "'.concat(s.value,'" mode'));return c&&"function"==typeof c.value?_.value?ie(oe):1==g.value&&oe():(V.value=c.value,oe()),k.value>-1&&e.watch(B,(function(e){e.length<w.value||(H.value=!0,O.value&&(V.value=[]),setTimeout((function(){e==B.value&&c.value(B.value).then((function(t){e==B.value&&(V.value=t,j.value=M.value.filter((function(e){return!0!==e.disabled}))[0]||null,H.value=!1)}))}),k.value))}),{flush:"sync"}),e.watch(T,(function(e){var n,a,u;if(t(e))D.value=ce(e);else switch(s.value){case"single":(g.value?e[C.value]!=D.value[C.value]:e!=D.value[C.value])&&(D.value=ce(e));break;case"multiple":case"tags":n=g.value?e.map((function(e){return e[C.value]})):e,a=D.value.map((function(e){return e[C.value]})),u=a.slice().sort(),n.length===a.length&&n.slice().sort().every((function(e,t){return e===u[t]}))||(D.value=ce(e))}}),{deep:!0}),"function"!=typeof u.options&&e.watch(c,(function(e,t){V.value=u.options,Object.keys(D.value).length||oe(),function(){if($.value)if("single"===s.value){var e=ae(D.value[C.value])[h.value];D.value[h.value]=e,g.value&&(T.value[h.value]=e)}else D.value.forEach((function(e,t){var n=ae(D.value[t][C.value])[h.value];D.value[t][h.value]=n,g.value&&(T.value[t][h.value]=n)}))}()})),{fo:M,hasSelected:$,multipleLabelText:L,eo:U,noOptions:F,noResults:W,resolving:H,busy:G,select:J,deselect:K,remove:Y,clear:Z,isSelected:ee,isDisabled:te,isMax:ne,getOption:ae,handleOptionClick:function(e){if(!te(e))switch(s.value){case"single":if(ee(e))return void(P.value&&K(e));J(e),E(),I();break;case"multiple":if(ee(e))return void K(e);if(ne())return;J(e),x.value&&R();break;case"tags":if(ee(e))return void K(e);if(ne())return;void 0===ae(e[C.value])&&f.value&&(l.emit("tag",e[C.value]),y.value&&re(e),R()),x.value&&R(),J(e)}},handleTagRemove:function(e,t){0===t.button?Y(e):t.preventDefault()},refreshOptions:function(e){ie(e)},resolveOptions:ie}}function i(e,t,n,a,u,l,r,o,i,c){"boolean"!=typeof r&&(i=o,o=r,r=!1);var s,d="function"==typeof n?n.options:n;if(e&&e.render&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0,u&&(d.functional=!0)),a&&(d._scopeId=a),l?(s=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,i(e)),e&&e._registeredComponents&&e._registeredComponents.add(l)},d._ssrRegister=s):t&&(s=r?function(e){t.call(this,c(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,o(e))}),s)if(d.functional){var v=d.render;d.render=function(e,t){return s.call(t),v(e,t)}}else{var p=d.beforeCreate;d.beforeCreate=p?[].concat(p,s):[s]}return n}const c={name:"Multiselect",emits:["open","close","select","deselect","input","search-change","tag","update:modelValue","change"],props:{value:{required:!1},modelValue:{required:!1},options:{type:[Array,Object,Function],required:!1,default:()=>[]},id:{type:[String,Number],required:!1,default:"multiselect"},name:{type:[String,Number],required:!1,default:"multiselect"},disabled:{type:Boolean,required:!1,default:!1},label:{type:String,required:!1,default:"label"},trackBy:{type:String,required:!1,default:"label"},valueProp:{type:String,required:!1,default:"value"},placeholder:{type:String,required:!1,default:null},mode:{type:String,required:!1,default:"single"},searchable:{type:Boolean,required:!1,default:!1},limit:{type:Number,required:!1,default:-1},maxHeight:{type:Number,required:!1,default:160},hideSelected:{type:Boolean,required:!1,default:!0},createTag:{type:Boolean,required:!1,default:!1},appendNewTag:{type:Boolean,required:!1,default:!0},caret:{type:Boolean,required:!1,default:!0},loading:{type:Boolean,required:!1,default:!1},noOptionsText:{type:String,required:!1,default:"The list is empty"},noResultsText:{type:String,required:!1,default:"No results found"},multipleLabel:{type:Function,required:!1},object:{type:Boolean,required:!1,default:!1},delay:{type:Number,required:!1,default:-1},minChars:{type:Number,required:!1,default:0},resolveOnLoad:{type:Boolean,required:!1,default:!0},filterResults:{type:Boolean,required:!1,default:!0},clearOnSearch:{type:Boolean,required:!1,default:!1},clearOnSelect:{type:Boolean,required:!1,default:!0},canDeselect:{type:Boolean,required:!1,default:!0},max:{type:Number,required:!1,default:-1},showOptions:{type:Boolean,required:!1,default:!0},addTagOn:{type:Array,required:!1,default:()=>["enter"]},required:{type:Boolean,required:!1,default:!1}},setup(n,a){const l=function(t,n){var a=e.toRefs(t),u=a.value,l=a.modelValue,r=a.mode,o=a.valueProp,i=e.ref("single"!==r.value?[]:{}),c=void 0!==n.expose?l:u,s=e.computed((function(){return"single"!==r.value?i.value.map((function(e){return e[o.value]})).join(","):i.value[o.value]}));return{iv:i,ev:c,textValue:s}}(n,a),r=function(t,n,a){var u=e.toRefs(t),l=u.searchable,r=(u.id,e.ref(null)),o=e.computed((function(){return l.value?-1:0}));return{multiselect:r,tabindex:o,focusInput:function(){r.value.querySelector(".multiselect-input").focus()},blurInput:function(){r.value.querySelector(".multiselect-input").blur()}}}(n),i={pointer:e.ref(null)},c=function(n,a,u){var l=e.toRefs(n),r=l.object,o=l.valueProp,i=l.mode,c=u.iv,s=function(e){return r.value||t(e)?e:Array.isArray(e)?e.map((function(e){return e[o.value]})):e[o.value]},d=function(e){return t(e)?"single"===i.value?{}:[]:e};return{update:function(e){c.value=d(e);var t=s(e);a.emit("change",t),a.emit("input",t),a.emit("update:modelValue",t)}}}(n,a,{iv:l.iv}),s=function(t,n,a){var u=e.toRefs(t),l=u.searchable,r=u.mode,o=a.iv,i=e.ref(null),c=e.ref(null),s=e.computed((function(){return i.value?"".concat(i.value.length,"ch"):"tags"===r.value&&-1===[null,void 0].indexOf(o.value)&&o.value.length?"1ch":"100%"}));return e.watch(i,(function(e){n.emit("search-change",e)})),{search:i,input:c,tagsSearchWidth:s,clearSearch:function(){i.value=""},focusSearch:function(){c.value.focus()},blurSearch:function(){l.value&&c.value.blur()}}}(n,a,{iv:l.iv}),d=function(t,n,a){var u=e.toRefs(t),l=u.maxHeight,r=u.disabled,o=u.searchable,i=a.multiselect,c=a.blurInput,s=a.blurSearch,d=a.focusInput,v=a.focusSearch,p=e.ref(!1),f=e.computed((function(){return"".concat(l.value,"px")}));return{isOpen:p,contentMaxHeight:f,openDropdown:function(){r.value||(p.value=!0,n.emit("open"))},closeDropdown:function(){p.value=!1,n.emit("close")},open:function(){o&&o.value?v():d()},close:function(){o&&o.value?s():c()},handleInputMousedown:function(e){p.value&&!o.value&&(i.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),i.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(n,a,{multiselect:r.multiselect,blurInput:r.blurInput,blurSearch:s.blurSearch,focusInput:r.focusInput,focusSearch:s.focusSearch}),v=o(n,a,{ev:l.ev,iv:l.iv,search:s.search,blurSearch:s.blurSearch,clearSearch:s.clearSearch,update:c.update,blurInput:r.blurInput,pointer:i.pointer}),p=function(t,n,a){var u=e.toRefs(t),l=u.id,r=u.valueProp,o=a.fo,i=a.handleOptionClick,c=a.search,s=a.pointer,d=e.computed((function(){return o.value.filter((function(e){return!0!==e.disabled}))})),v=function(e){s.value=e},p=function(){s.value=d.value[0]||null},f=function(){s.value=null},h=function(){var e=document.getElementById(l.value).querySelector(".is-pointed");if(e){var t=e.parentElement;e.offsetTop+e.offsetHeight>t.clientHeight+t.scrollTop&&(t.scrollTop=e.offsetTop+e.offsetHeight-t.clientHeight),e.offsetTop<t.scrollTop&&(t.scrollTop=e.offsetTop)}};return e.watch(c,(function(e){p()})),{pointer:s,isPointed:function(e){return!!s.value&&s.value[r.value]==e[r.value]},setPointer:v,setPointerFirst:p,clearPointer:f,selectPointer:function(){s.value&&!0!==s.value.disabled?(i(s.value),f()):f()},forwardPointer:function(){if(null===s.value)v(d.value[0]||null);else{var t=d.value.map((function(e){return e[r.value]})).indexOf(s.value[r.value])+1;d.value.length<=t&&(t=0),v(d.value[t]||null)}e.nextTick((function(){h()}))},backwardPointer:function(){if(null===s.value)v(d.value[d.value.length-1]||null);else{var t=d.value.map((function(e){return e[r.value]})).indexOf(s.value[r.value])-1;t<0&&(t=d.value.length-1),v(d.value[t]||null)}e.nextTick((function(){h()}))}}}(n,0,{fo:v.fo,handleOptionClick:v.handleOptionClick,search:s.search,pointer:i.pointer}),f=function(t,n,a){var l=e.toRefs(t),r=l.mode,o=l.addTagOn,i=l.createTag,c=a.iv,s=a.update,d=a.closeDropdown,v=a.clearPointer,p=a.search,f=a.selectPointer;return{handleBackspace:function(e){"single"!==r.value&&s(u(c.value).slice(0,-1))},handleEsc:function(e){d(),v(),e.target.blur()},handleSearchBackspace:function(e){""!==p.value&&e.stopPropagation()},handleSearchInput:function(e){p.value=e.target.value},handleAddTag:function(t){13!==t.keyCode||-1===o.value.indexOf("enter")&&i.value?32===t.keyCode&&-1!==o.value.indexOf("space")&&i.value&&(p.value=p.value.trim(),e.nextTick((function(){f()}))):f()}}}(n,0,{iv:l.iv,update:c.update,closeDropdown:d.closeDropdown,clearPointer:p.clearPointer,search:s.search,selectPointer:p.selectPointer});return{...l,...d,...r,...i,...c,...s,...v,...p,...f}}};var s=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{ref:"multiselect",staticClass:"multiselect",class:["is-"+e.mode,{"is-open":e.isOpen,"is-searchable":e.searchable,"is-disabled":e.disabled,"no-caret":!e.caret}],attrs:{id:e.id},on:{keydown:function(t){if(!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter"))return null;t.preventDefault()}}},[n("div",{staticClass:"multiselect-input",attrs:{tabindex:e.tabindex},on:{mousedown:e.handleInputMousedown,focus:e.openDropdown,blur:e.closeDropdown,keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:e.handleEsc(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:e.selectPointer(t)}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:(t.preventDefault(),e.handleBackspace(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.preventDefault(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.preventDefault(),e.forwardPointer(t))}]}},["single"==e.mode&&e.hasSelected&&!e.search&&e.iv?[e._t("singlelabel",[n("div",{staticClass:"multiselect-single-label"},[e._v("\n "+e._s(e.iv[e.label])+"\n ")])],{value:e.iv})]:e._e(),e._v(" "),"multiple"==e.mode&&e.hasSelected&&!e.search?[e._t("multiplelabel",[n("div",{staticClass:"multiselect-multiple-label"},[e._v("\n "+e._s(e.multipleLabelText)+"\n ")])],{values:e.iv})]:e._e(),e._v(" "),"tags"!==e.mode&&e.searchable&&!e.disabled?[n("div",{staticClass:"multiselect-search"},[n("input",{ref:"input",attrs:{modelValue:e.search},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.openDropdown(t)},blur:function(t){return t.stopPropagation(),e.closeDropdown(t)},keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:(t.stopPropagation(),e.handleEsc(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:(t.stopPropagation(),e.selectPointer(t))}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:e.handleSearchBackspace(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.stopPropagation(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.stopPropagation(),e.forwardPointer(t))}],input:e.handleSearchInput}})])]:e._e(),e._v(" "),"tags"==e.mode?[n("div",{staticClass:"multiselect-tags"},[e._l(e.iv,(function(t,a,u){return n("span",{key:u},[e._t("tag",[n("div",{staticClass:"multiselect-tag"},[e._v("\n "+e._s(t[e.label])+"\n "),e.disabled?e._e():n("i",{on:{click:function(e){e.preventDefault()},mousedown:function(n){return n.preventDefault(),n.stopPropagation(),e.handleTagRemove(t,n)}}})])],{option:t,handleTagRemove:e.handleTagRemove,disabled:e.disabled})],2)})),e._v(" "),e.searchable&&!e.disabled?n("div",{staticClass:"multiselect-search",style:{width:e.tagsSearchWidth}},[n("input",{ref:"input",style:{width:e.tagsSearchWidth},attrs:{modelValue:e.search},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.openDropdown(t)},blur:function(t){return t.stopPropagation(),e.closeDropdown(t)},keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:(t.stopPropagation(),e.handleEsc(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:(t.stopPropagation(),e.handleAddTag(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"space",32,t.key,[" ","Spacebar"])?null:(t.stopPropagation(),e.handleAddTag(t))}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:e.handleSearchBackspace(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.stopPropagation(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.stopPropagation(),e.forwardPointer(t))}],input:e.handleSearchInput}})]):e._e()],2)]:e._e(),e._v(" "),!e.placeholder||e.hasSelected||e.search?e._e():[e._t("placeholder",[n("div",{staticClass:"multiselect-placeholder"},[e._v("\n "+e._s(e.placeholder)+"\n ")])])],e._v(" "),e.caret&&!e.busy?e._t("caret",[n("span",{staticClass:"multiselect-caret"})]):e._e(),e._v(" "),n("transition",{attrs:{name:"multiselect-loading"}},[e.busy?n("span",[e._t("spinner",[n("span",{staticClass:"multiselect-spinner"})])],2):e._e()]),e._v(" "),e.hasSelected&&!e.disabled?e._t("clear",[n("a",{staticClass:"multiselect-clear",on:{click:function(t){return t.preventDefault(),e.clear(t)}}})],{clear:e.clear}):e._e()],2),e._v(" "),e.resolving&&e.clearOnSearch?e._e():n("transition",{attrs:{name:"multiselect"},on:{"after-leave":e.clearSearch}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.isOpen&&e.showOptions,expression:"isOpen && showOptions"}],staticClass:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[e._t("beforelist"),e._v(" "),e._l(e.fo,(function(t,a,u){return n("span",{key:u,staticClass:"multiselect-option",class:{"is-pointed":e.isPointed(t),"is-selected":e.isSelected(t),"is-disabled":e.isDisabled(t)},attrs:{tabindex:-1},on:{mousedown:function(e){e.preventDefault()},mouseenter:function(n){return e.setPointer(t)},click:function(n){return n.stopPropagation(),n.preventDefault(),e.handleOptionClick(t)}}},[e._t("option",[n("span",[e._v(e._s(t[e.label]))])],{option:t,search:e.search})],2)})),e._v(" "),n("span",{directives:[{name:"show",rawName:"v-show",value:e.noOptions,expression:"noOptions"}]},[e._t("nooptions",[n("div",{staticClass:"multiselect-no-options"},[e._v(e._s(e.noOptionsText))])])],2),e._v(" "),n("span",{directives:[{name:"show",rawName:"v-show",value:e.noResults,expression:"noResults"}]},[e._t("noresults",[n("div",{staticClass:"multiselect-no-results"},[e._v(e._s(e.noResultsText))])])],2),e._v(" "),e._t("afterlist")],2)]),e._v(" "),e.required?n("input",{staticClass:"multiselect-fake-input",attrs:{tabindex:"-1",required:""},domProps:{value:e.textValue}}):e._e()],1)};s._withStripped=!0;return i({render:s,staticRenderFns:[]},undefined,c,undefined,false,undefined,!1,void 0,void 0,void 0)}(VueCompositionAPI); |
@@ -1,1 +0,1 @@ | ||
import{toRefs as e,ref as t,computed as n,watch as l,nextTick as a}from"@vue/composition-api";function u(e){return-1!==[null,void 0,!1].indexOf(e)}function r(e){return String(e).toLowerCase().trim()}var i={};function o(e){return(o="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 c(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(a,s,d){var v=e(a),p=v.options,f=v.mode,h=v.trackBy,y=v.limit,m=v.hideSelected,g=v.createTag,b=v.label,k=v.appendNewTag,_=v.multipleLabel,O=v.object,w=v.loading,S=v.delay,x=v.resolveOnLoad,C=v.minChars,P=v.filterResults,q=v.clearOnSearch,D=v.clearOnSelect,V=v.valueProp,T=v.canDeselect,B=v.max,E=d.internalValue,A=d.externalValue,I=d.currentValue,j=d.search,N=d.blurSearch,R=d.clearSearch,H=d.update,U=d.blurInput,$=d.pointer,L=t([]),M=t([]),F=t(!1),J=n((function(){var e,t=M.value||[];return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(t=Object.keys(t).map((function(e){var n,l=t[e];return c(n={},V.value,e),c(n,h.value,l),c(n,b.value,l),n}))),t=t.map((function(e,t){var n;return"object"===o(e)?e:(c(n={},V.value,t),c(n,h.value,e),c(n,b.value,e),n)})),L.value.length&&(t=t.concat(L.value)),t})),W=n((function(){var e=J.value;return Q.value.length&&(e=Q.value.concat(e)),j.value&&P.value&&(e=e.filter((function(e){return-1!==r(e[h.value]).indexOf(r(j.value))}))),m.value&&(e=e.filter((function(e){return!se(e)}))),y.value>0&&(e=e.slice(0,y.value)),e})),X=n((function(){switch(f.value){case"single":return!u(E.value[V.value]);case"multiple":case"tags":return!u(E.value)&&E.value.length>0}})),z=n((function(){return void 0!==_&&void 0!==_.value?_.value(E.value):E.value&&E.value.length>1?"".concat(E.value.length," options selected"):"1 option selected"})),G=n((function(){return!J.value.length&&!F.value})),K=n((function(){return J.value.length>0&&0==W.value.length})),Q=n((function(){var e;return!1!==g.value&&j.value?-1!==ce(j.value)?[]:[(e={},c(e,V.value,j.value),c(e,b.value,j.value),c(e,h.value,j.value),e)]:[]})),Y=n((function(){switch(f.value){case"single":return null;case"multiple":case"tags":return[]}})),Z=n((function(){return w.value||F.value})),ee=function(e){switch("object"!==o(e)&&(e=oe(e)),f.value){case"single":H(e);break;case"multiple":case"tags":H(E.value.concat(e))}s.emit("select",ne(e))},te=function(e){switch("object"!==o(e)&&(e=oe(e)),f.value){case"single":ae();break;case"tags":case"multiple":H(E.value.filter((function(t){return t[V.value]!=e[V.value]})))}s.emit("deselect",ne(e))},ne=function(e){return O.value?e:e[V.value]},le=function(e){te(e)},ae=function(){H(Y.value)},ue=function(e){switch(f.value){case"single":return!u(E.value)&&E.value[V.value]==e[V.value];case"tags":case"multiple":return!u(E.value)&&-1!==E.value.map((function(e){return e[V.value]})).indexOf(e[V.value])}},re=function(e){return!0===e.disabled},ie=function(){return!(void 0===B||-1===B.value||!X.value&&B.value>0)&&E.value.length>=B.value},oe=function(e){return J.value[J.value.map((function(e){return String(e[V.value])})).indexOf(String(e))]},ce=function(e){return J.value.map((function(e){return r(e[h.value])})).indexOf(r(e))},se=function(e){return"tags"===f.value&&m.value&&ue(e)},de=function(e){L.value.push(e)},ve=function(){u(A.value)||(E.value=fe(A.value))},pe=function(e){F.value=!0,p.value(j.value).then((function(t){M.value=t,"function"==typeof e&&e(t),F.value=!1}))},fe=function(e){return u(e)?"single"===f.value?{}:[]:O.value?e:"single"===f.value?oe(e)||{}:e.filter((function(e){return!!oe(e)})).map((function(e){return oe(e)}))};if("single"!==f.value&&!u(A.value)&&!Array.isArray(A.value))throw new Error('v-model must be an array when using "'.concat(f.value,'" mode'));return p&&"function"==typeof p.value?x.value?pe(ve):1==O.value&&ve():(M.value=p.value,ve()),S.value>-1&&l(j,(function(e){e.length<C.value||(F.value=!0,q.value&&(M.value=[]),setTimeout((function(){e==j.value&&p.value(j.value).then((function(t){e==j.value&&(M.value=t,$.value=W.value.filter((function(e){return!0!==e.disabled}))[0]||null,F.value=!1)}))}),S.value))}),{flush:"sync"}),l(A,(function(e){var t,n,l;if(u(e))E.value=fe(e);else switch(f.value){case"single":(O.value?e[V.value]!=E.value[V.value]:e!=E.value[V.value])&&(E.value=fe(e));break;case"multiple":case"tags":t=O.value?e.map((function(e){return e[V.value]})):e,n=E.value.map((function(e){return e[V.value]})),l=n.slice().sort(),t.length===n.length&&t.slice().sort().every((function(e,t){return e===l[t]}))||(E.value=fe(e))}}),{deep:!0}),"function"!=typeof a.options&&(l((function(){return a.options}),(function(e,t){M.value=a.options})),l(J,(function(e,t){if(Object.keys(E.value).length||ve(),e.length&&I.value&&I.value.length){var n;if("single"===f.value){if(n=e[e.map((function(e){return e[V.value]})).indexOf(I.value)],JSON.stringify(n)===JSON.stringify(E.value))return}else if(n=[],I.value.forEach((function(t){n.push(e[e.map((function(e){return e[V.value]})).indexOf(t)])})),function(e,t){var n=e.length===t.length;if(!n)return n;try{e.every((function(e,n){if(JSON.stringify(e)!==JSON.stringify(t[n]))throw i}))}catch(e){if(e!==i)throw e;n=!1}return n}(n,E.value))return;O.value?H(n):E.value=n}}),{flush:"sync",deep:!0,immediate:!1})),{filteredOptions:W,hasSelected:X,multipleLabelText:z,extendedOptions:J,noOptions:G,noResults:K,resolving:F,busy:Z,select:ee,deselect:te,remove:le,clear:ae,isSelected:ue,isDisabled:re,isMax:ie,getOption:oe,handleOptionClick:function(e){if(!re(e))switch(f.value){case"single":if(ue(e))return void(T.value&&te(e));ee(e),N(),U();break;case"multiple":if(ue(e))return void te(e);if(ie())return;ee(e),D.value&&R();break;case"tags":if(ue(e))return void te(e);if(ie())return;void 0===oe(e[V.value])&&g.value&&(s.emit("tag",e[V.value]),k.value&&de(e),R()),D.value&&R(),ee(e)}},handleTagRemove:function(e,t){0===t.button?le(e):t.preventDefault()},refreshOptions:function(e){pe(e)},resolveOptions:pe}}function d(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}(e)||function(){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 v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,l=new Array(t);n<t;n++)l[n]=e[n];return l}function p(e,t,n,l,a,u,r,i,o,c){"boolean"!=typeof r&&(o=i,i=r,r=!1);var s,d="function"==typeof n?n.options:n;if(e&&e.render&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0,a&&(d.functional=!0)),l&&(d._scopeId=l),u?(s=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,o(e)),e&&e._registeredComponents&&e._registeredComponents.add(u)},d._ssrRegister=s):t&&(s=r?function(e){t.call(this,c(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,i(e))}),s)if(d.functional){var v=d.render;d.render=function(e,t){return s.call(t),v(e,t)}}else{var p=d.beforeCreate;d.beforeCreate=p?[].concat(p,s):[s]}return n}const f={name:"Multiselect",emits:["open","close","select","deselect","input","search-change","tag","update:modelValue","change"],props:{value:{required:!1},modelValue:{required:!1},options:{type:[Array,Object,Function],required:!1,default:()=>[]},id:{type:[String,Number],required:!1,default:"multiselect"},name:{type:[String,Number],required:!1,default:"multiselect"},disabled:{type:Boolean,required:!1,default:!1},label:{type:String,required:!1,default:"label"},trackBy:{type:String,required:!1,default:"label"},valueProp:{type:String,required:!1,default:"value"},placeholder:{type:String,required:!1,default:null},mode:{type:String,required:!1,default:"single"},searchable:{type:Boolean,required:!1,default:!1},limit:{type:Number,required:!1,default:-1},maxHeight:{type:Number,required:!1,default:160},hideSelected:{type:Boolean,required:!1,default:!0},createTag:{type:Boolean,required:!1,default:!1},appendNewTag:{type:Boolean,required:!1,default:!0},caret:{type:Boolean,required:!1,default:!0},loading:{type:Boolean,required:!1,default:!1},noOptionsText:{type:String,required:!1,default:"The list is empty"},noResultsText:{type:String,required:!1,default:"No results found"},multipleLabel:{type:Function,required:!1},object:{type:Boolean,required:!1,default:!1},delay:{type:Number,required:!1,default:-1},minChars:{type:Number,required:!1,default:0},resolveOnLoad:{type:Boolean,required:!1,default:!0},filterResults:{type:Boolean,required:!1,default:!0},clearOnSearch:{type:Boolean,required:!1,default:!1},clearOnSelect:{type:Boolean,required:!1,default:!0},canDeselect:{type:Boolean,required:!1,default:!0},max:{type:Number,required:!1,default:-1},showOptions:{type:Boolean,required:!1,default:!0},addTagOn:{type:Array,required:!1,default:()=>["enter"]},required:{type:Boolean,required:!1,default:!1}},setup(r,i){const o=function(l,a){var u=e(l),r=u.value,i=u.modelValue,o=u.mode,c=u.valueProp,s=t("single"!==o.value?[]:{}),d=void 0!==a.expose?i:r,v=n((function(){return Object.keys(s.value).length?"single"!==o.value?s.value.map((function(e){return e[c.value]})):s.value[c.value]:s.value})),p=n((function(){return"single"!==o.value?s.value.map((function(e){return e[c.value]})).join(","):s.value[c.value]}));return{internalValue:s,externalValue:d,currentValue:v,textValue:p}}(r,i),c=function(l,a,u){var r=e(l),i=r.searchable,o=(r.id,t(null)),c=n((function(){return i.value?-1:0}));return{multiselect:o,tabindex:c,focusInput:function(){o.value.querySelector(".multiselect-input").focus()},blurInput:function(){o.value.querySelector(".multiselect-input").blur()}}}(r),v={pointer:t(null)},p=function(t,n,l){var a=e(t),r=a.object,i=a.valueProp,o=a.mode,c=l.internalValue,s=function(e){return r.value||u(e)?e:Array.isArray(e)?e.map((function(e){return e[i.value]})):e[i.value]},d=function(e){return u(e)?"single"===o.value?{}:[]:e};return{update:function(e){c.value=d(e);var t=s(e);n.emit("change",t),n.emit("input",t),n.emit("update:modelValue",t)}}}(r,i,{internalValue:o.internalValue}),f=function(a,u,r){var i=e(a),o=i.searchable,c=i.mode,s=r.internalValue,d=t(null),v=t(null),p=n((function(){return d.value?"".concat(d.value.length,"ch"):"tags"===c.value&&-1===[null,void 0].indexOf(s.value)&&s.value.length?"1ch":"100%"}));return l(d,(function(e){u.emit("search-change",e)})),{search:d,input:v,tagsSearchWidth:p,clearSearch:function(){d.value=""},focusSearch:function(){v.value.focus()},blurSearch:function(){o.value&&v.value.blur()}}}(r,i,{internalValue:o.internalValue}),h=function(l,a,u){var r=e(l),i=r.maxHeight,o=r.disabled,c=r.searchable,s=u.multiselect,d=u.blurInput,v=u.blurSearch,p=u.focusInput,f=u.focusSearch,h=t(!1),y=n((function(){return"".concat(i.value,"px")}));return{isOpen:h,contentMaxHeight:y,openDropdown:function(){o.value||(h.value=!0,a.emit("open"))},closeDropdown:function(){h.value=!1,a.emit("close")},open:function(){c&&c.value?f():p()},close:function(){c&&c.value?v():d()},handleInputMousedown:function(e){h.value&&!c.value&&(s.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),s.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(r,i,{multiselect:c.multiselect,blurInput:c.blurInput,blurSearch:f.blurSearch,focusInput:c.focusInput,focusSearch:f.focusSearch}),y=s(r,i,{externalValue:o.externalValue,internalValue:o.internalValue,currentValue:o.currentValue,search:f.search,blurSearch:f.blurSearch,clearSearch:f.clearSearch,update:p.update,blurInput:c.blurInput,pointer:v.pointer}),m=function(t,u,r){var i=e(t),o=i.id,c=i.valueProp,s=r.filteredOptions,d=r.handleOptionClick,v=r.search,p=r.pointer,f=n((function(){return s.value.filter((function(e){return!0!==e.disabled}))})),h=function(e){p.value=e},y=function(){p.value=f.value[0]||null},m=function(){p.value=null},g=function(){var e=document.getElementById(o.value).querySelector(".is-pointed");if(e){var t=e.parentElement;e.offsetTop+e.offsetHeight>t.clientHeight+t.scrollTop&&(t.scrollTop=e.offsetTop+e.offsetHeight-t.clientHeight),e.offsetTop<t.scrollTop&&(t.scrollTop=e.offsetTop)}};return l(v,(function(e){y()})),{pointer:p,isPointed:function(e){return!!p.value&&p.value[c.value]==e[c.value]},setPointer:h,setPointerFirst:y,clearPointer:m,selectPointer:function(){p.value&&!0!==p.value.disabled?(d(p.value),m()):m()},forwardPointer:function(){if(null===p.value)h(f.value[0]||null);else{var e=f.value.map((function(e){return e[c.value]})).indexOf(p.value[c.value])+1;f.value.length<=e&&(e=0),h(f.value[e]||null)}a((function(){g()}))},backwardPointer:function(){if(null===p.value)h(f.value[f.value.length-1]||null);else{var e=f.value.map((function(e){return e[c.value]})).indexOf(p.value[c.value])-1;e<0&&(e=f.value.length-1),h(f.value[e]||null)}a((function(){g()}))}}}(r,0,{filteredOptions:y.filteredOptions,handleOptionClick:y.handleOptionClick,search:f.search,pointer:v.pointer}),g=function(t,n,l){var u=e(t),r=u.mode,i=u.addTagOn,o=u.createTag,c=l.internalValue,s=l.update,v=l.closeDropdown,p=l.clearPointer,f=l.search,h=l.selectPointer;return{handleBackspace:function(e){"single"!==r.value&&s(d(c.value).slice(0,-1))},handleEsc:function(e){v(),p(),e.target.blur()},handleSearchBackspace:function(e){""!==f.value&&e.stopPropagation()},handleSearchInput:function(e){f.value=e.target.value},handleAddTag:function(e){13!==e.keyCode||-1===i.value.indexOf("enter")&&o.value?32===e.keyCode&&-1!==i.value.indexOf("space")&&o.value&&(f.value=f.value.trim(),a((function(){h()}))):h()}}}(r,0,{internalValue:o.internalValue,update:p.update,closeDropdown:h.closeDropdown,clearPointer:m.clearPointer,search:f.search,selectPointer:m.selectPointer});return{...o,...h,...c,...v,...p,...f,...y,...m,...g}}};var h=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{ref:"multiselect",staticClass:"multiselect",class:["is-"+e.mode,{"is-open":e.isOpen,"is-searchable":e.searchable,"is-disabled":e.disabled,"no-caret":!e.caret}],attrs:{id:e.id},on:{keydown:function(t){if(!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter"))return null;t.preventDefault()}}},[n("div",{staticClass:"multiselect-input",attrs:{tabindex:e.tabindex},on:{mousedown:e.handleInputMousedown,focus:e.openDropdown,blur:e.closeDropdown,keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:e.handleEsc(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:e.selectPointer(t)}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:(t.preventDefault(),e.handleBackspace(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.preventDefault(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.preventDefault(),e.forwardPointer(t))}]}},["single"==e.mode&&e.hasSelected&&!e.search&&e.internalValue?[e._t("singlelabel",[n("div",{staticClass:"multiselect-single-label"},[e._v("\n "+e._s(e.internalValue[e.label])+"\n ")])],{value:e.internalValue})]:e._e(),e._v(" "),"multiple"==e.mode&&e.hasSelected&&!e.search?[e._t("multiplelabel",[n("div",{staticClass:"multiselect-multiple-label"},[e._v("\n "+e._s(e.multipleLabelText)+"\n ")])],{values:e.internalValue})]:e._e(),e._v(" "),"tags"!==e.mode&&e.searchable&&!e.disabled?[n("div",{staticClass:"multiselect-search"},[n("input",{ref:"input",attrs:{modelValue:e.search},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.openDropdown(t)},blur:function(t){return t.stopPropagation(),e.closeDropdown(t)},keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:(t.stopPropagation(),e.handleEsc(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:(t.stopPropagation(),e.selectPointer(t))}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:e.handleSearchBackspace(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.stopPropagation(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.stopPropagation(),e.forwardPointer(t))}],input:e.handleSearchInput}})])]:e._e(),e._v(" "),"tags"==e.mode?[n("div",{staticClass:"multiselect-tags"},[e._l(e.internalValue,(function(t,l,a){return n("span",{key:a},[e._t("tag",[n("div",{staticClass:"multiselect-tag"},[e._v("\n "+e._s(t[e.label])+"\n "),e.disabled?e._e():n("i",{on:{click:function(e){e.preventDefault()},mousedown:function(n){return n.preventDefault(),n.stopPropagation(),e.handleTagRemove(t,n)}}})])],{option:t,handleTagRemove:e.handleTagRemove,disabled:e.disabled})],2)})),e._v(" "),e.searchable&&!e.disabled?n("div",{staticClass:"multiselect-search",style:{width:e.tagsSearchWidth}},[n("input",{ref:"input",style:{width:e.tagsSearchWidth},attrs:{modelValue:e.search},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.openDropdown(t)},blur:function(t){return t.stopPropagation(),e.closeDropdown(t)},keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:(t.stopPropagation(),e.handleEsc(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:(t.stopPropagation(),e.handleAddTag(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"space",32,t.key,[" ","Spacebar"])?null:(t.stopPropagation(),e.handleAddTag(t))}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:e.handleSearchBackspace(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.stopPropagation(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.stopPropagation(),e.forwardPointer(t))}],input:e.handleSearchInput}})]):e._e()],2)]:e._e(),e._v(" "),!e.placeholder||e.hasSelected||e.search?e._e():[e._t("placeholder",[n("div",{staticClass:"multiselect-placeholder"},[e._v("\n "+e._s(e.placeholder)+"\n ")])])],e._v(" "),e.caret&&!e.busy?e._t("caret",[n("span",{staticClass:"multiselect-caret"})]):e._e(),e._v(" "),n("transition",{attrs:{name:"multiselect-loading"}},[e.busy?n("span",[e._t("spinner",[n("span",{staticClass:"multiselect-spinner"})])],2):e._e()]),e._v(" "),e.hasSelected&&!e.disabled?e._t("clear",[n("a",{staticClass:"multiselect-clear",on:{click:function(t){return t.preventDefault(),e.clear(t)}}})],{clear:e.clear}):e._e()],2),e._v(" "),e.resolving&&e.clearOnSearch?e._e():n("transition",{attrs:{name:"multiselect"},on:{"after-leave":e.clearSearch}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.isOpen&&e.showOptions,expression:"isOpen && showOptions"}],staticClass:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[e._t("beforelist"),e._v(" "),e._l(e.filteredOptions,(function(t,l,a){return n("span",{key:a,staticClass:"multiselect-option",class:{"is-pointed":e.isPointed(t),"is-selected":e.isSelected(t),"is-disabled":e.isDisabled(t)},attrs:{tabindex:-1},on:{mousedown:function(e){e.preventDefault()},mouseenter:function(n){return e.setPointer(t)},click:function(n){return n.stopPropagation(),n.preventDefault(),e.handleOptionClick(t)}}},[e._t("option",[n("span",[e._v(e._s(t[e.label]))])],{option:t,search:e.search})],2)})),e._v(" "),n("span",{directives:[{name:"show",rawName:"v-show",value:e.noOptions,expression:"noOptions"}]},[e._t("nooptions",[n("div",{staticClass:"multiselect-no-options"},[e._v(e._s(e.noOptionsText))])])],2),e._v(" "),n("span",{directives:[{name:"show",rawName:"v-show",value:e.noResults,expression:"noResults"}]},[e._t("noresults",[n("div",{staticClass:"multiselect-no-results"},[e._v(e._s(e.noResultsText))])])],2),e._v(" "),e._t("afterlist")],2)]),e._v(" "),e.required?n("input",{staticClass:"multiselect-fake-input",attrs:{tabindex:"-1",required:""},domProps:{value:e.textValue}}):e._e()],1)};h._withStripped=!0;const y=p({render:h,staticRenderFns:[]},undefined,f,undefined,false,undefined,!1,void 0,void 0,void 0);export default y; | ||
import{toRefs as e,ref as t,computed as n,watch as a,nextTick as l}from"@vue/composition-api";function u(e){return-1!==[null,void 0,!1].indexOf(e)}function r(e){return String(e).toLowerCase().trim()}function o(e){return(o="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 i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(l,c,s){var v=e(l),d=v.options,p=v.mode,f=v.trackBy,h=v.limit,y=v.hideSelected,m=v.createTag,g=v.label,b=v.appendNewTag,k=v.multipleLabel,_=v.object,w=v.loading,S=v.delay,O=v.resolveOnLoad,x=v.minChars,C=v.filterResults,P=v.clearOnSearch,q=v.clearOnSelect,D=v.valueProp,T=v.canDeselect,B=v.max,E=s.iv,A=s.ev,I=s.search,j=s.blurSearch,R=s.clearSearch,N=s.update,V=s.blurInput,H=s.pointer,U=t([]),$=t([]),L=t(!1),M=n((function(){var e,t=$.value||[];return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(t=Object.keys(t).map((function(e){var n,a=t[e];return i(n={},D.value,e),i(n,f.value,a),i(n,g.value,a),n}))),t=t.map((function(e,t){var n;return"object"===o(e)?e:(i(n={},D.value,e),i(n,f.value,e),i(n,g.value,e),n)})),U.value.length&&(t=t.concat(U.value)),t})),F=n((function(){var e=M.value;return J.value.length&&(e=J.value.concat(e)),I.value&&C.value&&(e=e.filter((function(e){return-1!==r(e[f.value]).indexOf(r(I.value))}))),y.value&&(e=e.filter((function(e){return!ie(e)}))),h.value>0&&(e=e.slice(0,h.value)),e})),W=n((function(){switch(p.value){case"single":return!u(E.value[D.value]);case"multiple":case"tags":return!u(E.value)&&E.value.length>0}})),X=n((function(){return void 0!==k&&void 0!==k.value?k.value(E.value):E.value&&E.value.length>1?"".concat(E.value.length," options selected"):"1 option selected"})),z=n((function(){return!M.value.length&&!L.value})),G=n((function(){return M.value.length>0&&0==F.value.length})),J=n((function(){var e;return!1!==m.value&&I.value?-1!==oe(I.value)?[]:[(e={},i(e,D.value,I.value),i(e,g.value,I.value),i(e,f.value,I.value),e)]:[]})),K=n((function(){switch(p.value){case"single":return null;case"multiple":case"tags":return[]}})),Q=n((function(){return w.value||L.value})),Y=function(e){switch("object"!==o(e)&&(e=re(e)),p.value){case"single":N(e);break;case"multiple":case"tags":N(E.value.concat(e))}c.emit("select",ee(e))},Z=function(e){switch("object"!==o(e)&&(e=re(e)),p.value){case"single":ne();break;case"tags":case"multiple":N(E.value.filter((function(t){return t[D.value]!=e[D.value]})))}c.emit("deselect",ee(e))},ee=function(e){return _.value?e:e[D.value]},te=function(e){Z(e)},ne=function(){N(K.value)},ae=function(e){switch(p.value){case"single":return!u(E.value)&&E.value[D.value]==e[D.value];case"tags":case"multiple":return!u(E.value)&&-1!==E.value.map((function(e){return e[D.value]})).indexOf(e[D.value])}},le=function(e){return!0===e.disabled},ue=function(){return!(void 0===B||-1===B.value||!W.value&&B.value>0)&&E.value.length>=B.value},re=function(e){return M.value[M.value.map((function(e){return String(e[D.value])})).indexOf(String(e))]},oe=function(e){return M.value.map((function(e){return r(e[f.value])})).indexOf(r(e))},ie=function(e){return"tags"===p.value&&y.value&&ae(e)},ce=function(e){U.value.push(e)},se=function(){u(A.value)||(E.value=de(A.value))},ve=function(e){L.value=!0,d.value(I.value).then((function(t){$.value=t,"function"==typeof e&&e(t),L.value=!1}))},de=function(e){return u(e)?"single"===p.value?{}:[]:_.value?e:"single"===p.value?re(e)||{}:e.filter((function(e){return!!re(e)})).map((function(e){return re(e)}))};if("single"!==p.value&&!u(A.value)&&!Array.isArray(A.value))throw new Error('v-model must be an array when using "'.concat(p.value,'" mode'));return d&&"function"==typeof d.value?O.value?ve(se):1==_.value&&se():($.value=d.value,se()),S.value>-1&&a(I,(function(e){e.length<x.value||(L.value=!0,P.value&&($.value=[]),setTimeout((function(){e==I.value&&d.value(I.value).then((function(t){e==I.value&&($.value=t,H.value=F.value.filter((function(e){return!0!==e.disabled}))[0]||null,L.value=!1)}))}),S.value))}),{flush:"sync"}),a(A,(function(e){var t,n,a;if(u(e))E.value=de(e);else switch(p.value){case"single":(_.value?e[D.value]!=E.value[D.value]:e!=E.value[D.value])&&(E.value=de(e));break;case"multiple":case"tags":t=_.value?e.map((function(e){return e[D.value]})):e,n=E.value.map((function(e){return e[D.value]})),a=n.slice().sort(),t.length===n.length&&t.slice().sort().every((function(e,t){return e===a[t]}))||(E.value=de(e))}}),{deep:!0}),"function"!=typeof l.options&&a(d,(function(e,t){$.value=l.options,Object.keys(E.value).length||se(),function(){if(W.value)if("single"===p.value){var e=re(E.value[D.value])[g.value];E.value[g.value]=e,_.value&&(A.value[g.value]=e)}else E.value.forEach((function(e,t){var n=re(E.value[t][D.value])[g.value];E.value[t][g.value]=n,_.value&&(A.value[t][g.value]=n)}))}()})),{fo:F,hasSelected:W,multipleLabelText:X,eo:M,noOptions:z,noResults:G,resolving:L,busy:Q,select:Y,deselect:Z,remove:te,clear:ne,isSelected:ae,isDisabled:le,isMax:ue,getOption:re,handleOptionClick:function(e){if(!le(e))switch(p.value){case"single":if(ae(e))return void(T.value&&Z(e));Y(e),j(),V();break;case"multiple":if(ae(e))return void Z(e);if(ue())return;Y(e),q.value&&R();break;case"tags":if(ae(e))return void Z(e);if(ue())return;void 0===re(e[D.value])&&m.value&&(c.emit("tag",e[D.value]),b.value&&ce(e),R()),q.value&&R(),Y(e)}},handleTagRemove:function(e,t){0===t.button?te(e):t.preventDefault()},refreshOptions:function(e){ve(e)},resolveOptions:ve}}function s(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}(e)||function(){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 v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function d(e,t,n,a,l,u,r,o,i,c){"boolean"!=typeof r&&(i=o,o=r,r=!1);var s,v="function"==typeof n?n.options:n;if(e&&e.render&&(v.render=e.render,v.staticRenderFns=e.staticRenderFns,v._compiled=!0,l&&(v.functional=!0)),a&&(v._scopeId=a),u?(s=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,i(e)),e&&e._registeredComponents&&e._registeredComponents.add(u)},v._ssrRegister=s):t&&(s=r?function(e){t.call(this,c(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,o(e))}),s)if(v.functional){var d=v.render;v.render=function(e,t){return s.call(t),d(e,t)}}else{var p=v.beforeCreate;v.beforeCreate=p?[].concat(p,s):[s]}return n}const p={name:"Multiselect",emits:["open","close","select","deselect","input","search-change","tag","update:modelValue","change"],props:{value:{required:!1},modelValue:{required:!1},options:{type:[Array,Object,Function],required:!1,default:()=>[]},id:{type:[String,Number],required:!1,default:"multiselect"},name:{type:[String,Number],required:!1,default:"multiselect"},disabled:{type:Boolean,required:!1,default:!1},label:{type:String,required:!1,default:"label"},trackBy:{type:String,required:!1,default:"label"},valueProp:{type:String,required:!1,default:"value"},placeholder:{type:String,required:!1,default:null},mode:{type:String,required:!1,default:"single"},searchable:{type:Boolean,required:!1,default:!1},limit:{type:Number,required:!1,default:-1},maxHeight:{type:Number,required:!1,default:160},hideSelected:{type:Boolean,required:!1,default:!0},createTag:{type:Boolean,required:!1,default:!1},appendNewTag:{type:Boolean,required:!1,default:!0},caret:{type:Boolean,required:!1,default:!0},loading:{type:Boolean,required:!1,default:!1},noOptionsText:{type:String,required:!1,default:"The list is empty"},noResultsText:{type:String,required:!1,default:"No results found"},multipleLabel:{type:Function,required:!1},object:{type:Boolean,required:!1,default:!1},delay:{type:Number,required:!1,default:-1},minChars:{type:Number,required:!1,default:0},resolveOnLoad:{type:Boolean,required:!1,default:!0},filterResults:{type:Boolean,required:!1,default:!0},clearOnSearch:{type:Boolean,required:!1,default:!1},clearOnSelect:{type:Boolean,required:!1,default:!0},canDeselect:{type:Boolean,required:!1,default:!0},max:{type:Number,required:!1,default:-1},showOptions:{type:Boolean,required:!1,default:!0},addTagOn:{type:Array,required:!1,default:()=>["enter"]},required:{type:Boolean,required:!1,default:!1}},setup(r,o){const i=function(a,l){var u=e(a),r=u.value,o=u.modelValue,i=u.mode,c=u.valueProp,s=t("single"!==i.value?[]:{}),v=void 0!==l.expose?o:r,d=n((function(){return"single"!==i.value?s.value.map((function(e){return e[c.value]})).join(","):s.value[c.value]}));return{iv:s,ev:v,textValue:d}}(r,o),v=function(a,l,u){var r=e(a),o=r.searchable,i=(r.id,t(null)),c=n((function(){return o.value?-1:0}));return{multiselect:i,tabindex:c,focusInput:function(){i.value.querySelector(".multiselect-input").focus()},blurInput:function(){i.value.querySelector(".multiselect-input").blur()}}}(r),d={pointer:t(null)},p=function(t,n,a){var l=e(t),r=l.object,o=l.valueProp,i=l.mode,c=a.iv,s=function(e){return r.value||u(e)?e:Array.isArray(e)?e.map((function(e){return e[o.value]})):e[o.value]},v=function(e){return u(e)?"single"===i.value?{}:[]:e};return{update:function(e){c.value=v(e);var t=s(e);n.emit("change",t),n.emit("input",t),n.emit("update:modelValue",t)}}}(r,o,{iv:i.iv}),f=function(l,u,r){var o=e(l),i=o.searchable,c=o.mode,s=r.iv,v=t(null),d=t(null),p=n((function(){return v.value?"".concat(v.value.length,"ch"):"tags"===c.value&&-1===[null,void 0].indexOf(s.value)&&s.value.length?"1ch":"100%"}));return a(v,(function(e){u.emit("search-change",e)})),{search:v,input:d,tagsSearchWidth:p,clearSearch:function(){v.value=""},focusSearch:function(){d.value.focus()},blurSearch:function(){i.value&&d.value.blur()}}}(r,o,{iv:i.iv}),h=function(a,l,u){var r=e(a),o=r.maxHeight,i=r.disabled,c=r.searchable,s=u.multiselect,v=u.blurInput,d=u.blurSearch,p=u.focusInput,f=u.focusSearch,h=t(!1),y=n((function(){return"".concat(o.value,"px")}));return{isOpen:h,contentMaxHeight:y,openDropdown:function(){i.value||(h.value=!0,l.emit("open"))},closeDropdown:function(){h.value=!1,l.emit("close")},open:function(){c&&c.value?f():p()},close:function(){c&&c.value?d():v()},handleInputMousedown:function(e){h.value&&!c.value&&(s.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),s.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(r,o,{multiselect:v.multiselect,blurInput:v.blurInput,blurSearch:f.blurSearch,focusInput:v.focusInput,focusSearch:f.focusSearch}),y=c(r,o,{ev:i.ev,iv:i.iv,search:f.search,blurSearch:f.blurSearch,clearSearch:f.clearSearch,update:p.update,blurInput:v.blurInput,pointer:d.pointer}),m=function(t,u,r){var o=e(t),i=o.id,c=o.valueProp,s=r.fo,v=r.handleOptionClick,d=r.search,p=r.pointer,f=n((function(){return s.value.filter((function(e){return!0!==e.disabled}))})),h=function(e){p.value=e},y=function(){p.value=f.value[0]||null},m=function(){p.value=null},g=function(){var e=document.getElementById(i.value).querySelector(".is-pointed");if(e){var t=e.parentElement;e.offsetTop+e.offsetHeight>t.clientHeight+t.scrollTop&&(t.scrollTop=e.offsetTop+e.offsetHeight-t.clientHeight),e.offsetTop<t.scrollTop&&(t.scrollTop=e.offsetTop)}};return a(d,(function(e){y()})),{pointer:p,isPointed:function(e){return!!p.value&&p.value[c.value]==e[c.value]},setPointer:h,setPointerFirst:y,clearPointer:m,selectPointer:function(){p.value&&!0!==p.value.disabled?(v(p.value),m()):m()},forwardPointer:function(){if(null===p.value)h(f.value[0]||null);else{var e=f.value.map((function(e){return e[c.value]})).indexOf(p.value[c.value])+1;f.value.length<=e&&(e=0),h(f.value[e]||null)}l((function(){g()}))},backwardPointer:function(){if(null===p.value)h(f.value[f.value.length-1]||null);else{var e=f.value.map((function(e){return e[c.value]})).indexOf(p.value[c.value])-1;e<0&&(e=f.value.length-1),h(f.value[e]||null)}l((function(){g()}))}}}(r,0,{fo:y.fo,handleOptionClick:y.handleOptionClick,search:f.search,pointer:d.pointer}),g=function(t,n,a){var u=e(t),r=u.mode,o=u.addTagOn,i=u.createTag,c=a.iv,v=a.update,d=a.closeDropdown,p=a.clearPointer,f=a.search,h=a.selectPointer;return{handleBackspace:function(e){"single"!==r.value&&v(s(c.value).slice(0,-1))},handleEsc:function(e){d(),p(),e.target.blur()},handleSearchBackspace:function(e){""!==f.value&&e.stopPropagation()},handleSearchInput:function(e){f.value=e.target.value},handleAddTag:function(e){13!==e.keyCode||-1===o.value.indexOf("enter")&&i.value?32===e.keyCode&&-1!==o.value.indexOf("space")&&i.value&&(f.value=f.value.trim(),l((function(){h()}))):h()}}}(r,0,{iv:i.iv,update:p.update,closeDropdown:h.closeDropdown,clearPointer:m.clearPointer,search:f.search,selectPointer:m.selectPointer});return{...i,...h,...v,...d,...p,...f,...y,...m,...g}}};var f=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{ref:"multiselect",staticClass:"multiselect",class:["is-"+e.mode,{"is-open":e.isOpen,"is-searchable":e.searchable,"is-disabled":e.disabled,"no-caret":!e.caret}],attrs:{id:e.id},on:{keydown:function(t){if(!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter"))return null;t.preventDefault()}}},[n("div",{staticClass:"multiselect-input",attrs:{tabindex:e.tabindex},on:{mousedown:e.handleInputMousedown,focus:e.openDropdown,blur:e.closeDropdown,keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:e.handleEsc(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:e.selectPointer(t)}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:(t.preventDefault(),e.handleBackspace(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.preventDefault(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.preventDefault(),e.forwardPointer(t))}]}},["single"==e.mode&&e.hasSelected&&!e.search&&e.iv?[e._t("singlelabel",[n("div",{staticClass:"multiselect-single-label"},[e._v("\n "+e._s(e.iv[e.label])+"\n ")])],{value:e.iv})]:e._e(),e._v(" "),"multiple"==e.mode&&e.hasSelected&&!e.search?[e._t("multiplelabel",[n("div",{staticClass:"multiselect-multiple-label"},[e._v("\n "+e._s(e.multipleLabelText)+"\n ")])],{values:e.iv})]:e._e(),e._v(" "),"tags"!==e.mode&&e.searchable&&!e.disabled?[n("div",{staticClass:"multiselect-search"},[n("input",{ref:"input",attrs:{modelValue:e.search},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.openDropdown(t)},blur:function(t){return t.stopPropagation(),e.closeDropdown(t)},keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:(t.stopPropagation(),e.handleEsc(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:(t.stopPropagation(),e.selectPointer(t))}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:e.handleSearchBackspace(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.stopPropagation(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.stopPropagation(),e.forwardPointer(t))}],input:e.handleSearchInput}})])]:e._e(),e._v(" "),"tags"==e.mode?[n("div",{staticClass:"multiselect-tags"},[e._l(e.iv,(function(t,a,l){return n("span",{key:l},[e._t("tag",[n("div",{staticClass:"multiselect-tag"},[e._v("\n "+e._s(t[e.label])+"\n "),e.disabled?e._e():n("i",{on:{click:function(e){e.preventDefault()},mousedown:function(n){return n.preventDefault(),n.stopPropagation(),e.handleTagRemove(t,n)}}})])],{option:t,handleTagRemove:e.handleTagRemove,disabled:e.disabled})],2)})),e._v(" "),e.searchable&&!e.disabled?n("div",{staticClass:"multiselect-search",style:{width:e.tagsSearchWidth}},[n("input",{ref:"input",style:{width:e.tagsSearchWidth},attrs:{modelValue:e.search},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.openDropdown(t)},blur:function(t){return t.stopPropagation(),e.closeDropdown(t)},keyup:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"esc",27,t.key,["Esc","Escape"])?null:(t.stopPropagation(),e.handleEsc(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:(t.stopPropagation(),e.handleAddTag(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"space",32,t.key,[" ","Spacebar"])?null:(t.stopPropagation(),e.handleAddTag(t))}],keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"delete",[8,46],t.key,["Backspace","Delete","Del"])?null:e.handleSearchBackspace(t)},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?null:(t.stopPropagation(),e.backwardPointer(t))},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?null:(t.stopPropagation(),e.forwardPointer(t))}],input:e.handleSearchInput}})]):e._e()],2)]:e._e(),e._v(" "),!e.placeholder||e.hasSelected||e.search?e._e():[e._t("placeholder",[n("div",{staticClass:"multiselect-placeholder"},[e._v("\n "+e._s(e.placeholder)+"\n ")])])],e._v(" "),e.caret&&!e.busy?e._t("caret",[n("span",{staticClass:"multiselect-caret"})]):e._e(),e._v(" "),n("transition",{attrs:{name:"multiselect-loading"}},[e.busy?n("span",[e._t("spinner",[n("span",{staticClass:"multiselect-spinner"})])],2):e._e()]),e._v(" "),e.hasSelected&&!e.disabled?e._t("clear",[n("a",{staticClass:"multiselect-clear",on:{click:function(t){return t.preventDefault(),e.clear(t)}}})],{clear:e.clear}):e._e()],2),e._v(" "),e.resolving&&e.clearOnSearch?e._e():n("transition",{attrs:{name:"multiselect"},on:{"after-leave":e.clearSearch}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.isOpen&&e.showOptions,expression:"isOpen && showOptions"}],staticClass:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[e._t("beforelist"),e._v(" "),e._l(e.fo,(function(t,a,l){return n("span",{key:l,staticClass:"multiselect-option",class:{"is-pointed":e.isPointed(t),"is-selected":e.isSelected(t),"is-disabled":e.isDisabled(t)},attrs:{tabindex:-1},on:{mousedown:function(e){e.preventDefault()},mouseenter:function(n){return e.setPointer(t)},click:function(n){return n.stopPropagation(),n.preventDefault(),e.handleOptionClick(t)}}},[e._t("option",[n("span",[e._v(e._s(t[e.label]))])],{option:t,search:e.search})],2)})),e._v(" "),n("span",{directives:[{name:"show",rawName:"v-show",value:e.noOptions,expression:"noOptions"}]},[e._t("nooptions",[n("div",{staticClass:"multiselect-no-options"},[e._v(e._s(e.noOptionsText))])])],2),e._v(" "),n("span",{directives:[{name:"show",rawName:"v-show",value:e.noResults,expression:"noResults"}]},[e._t("noresults",[n("div",{staticClass:"multiselect-no-results"},[e._v(e._s(e.noResultsText))])])],2),e._v(" "),e._t("afterlist")],2)]),e._v(" "),e.required?n("input",{staticClass:"multiselect-fake-input",attrs:{tabindex:"-1",required:""},domProps:{value:e.textValue}}):e._e()],1)};f._withStripped=!0;const h=d({render:f,staticRenderFns:[]},undefined,p,undefined,false,undefined,!1,void 0,void 0,void 0);export default h; |
{ | ||
"name": "@vueform/multiselect", | ||
"version": "1.3.7", | ||
"version": "1.4.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Vue 3 multiselect component with single select, multiselect and tagging options.", |
import { toRefs } from 'composition-api' | ||
import isNullish from './../utils/isNullish' | ||
export default function useData (props, context, dependencies) | ||
export default function useData (props, context, dep) | ||
{ | ||
@@ -10,3 +10,3 @@ const { object, valueProp, mode } = toRefs(props) | ||
const internalValue = dependencies.internalValue | ||
const iv = dep.iv | ||
@@ -17,3 +17,3 @@ // =============== METHODS ============== | ||
// Setting object(s) as internal value | ||
internalValue.value = makeInternal(val) | ||
iv.value = makeInternal(val) | ||
@@ -20,0 +20,0 @@ // Setting object(s) or plain value as external |
import { ref, toRefs, computed } from 'composition-api' | ||
export default function useDropdown (props, context, dependencies) | ||
export default function useDropdown (props, context, dep) | ||
{ | ||
@@ -9,7 +9,7 @@ const { maxHeight, disabled, searchable } = toRefs(props) | ||
const multiselect = dependencies.multiselect | ||
const blurInput = dependencies.blurInput | ||
const blurSearch = dependencies.blurSearch | ||
const focusInput = dependencies.focusInput | ||
const focusSearch = dependencies.focusSearch | ||
const multiselect = dep.multiselect | ||
const blurInput = dep.blurInput | ||
const blurSearch = dep.blurSearch | ||
const focusInput = dep.focusInput | ||
const focusSearch = dep.focusSearch | ||
@@ -16,0 +16,0 @@ // ================ DATA ================ |
import { toRefs, nextTick } from 'composition-api' | ||
export default function useKeyboard (props, context, dependencies) | ||
export default function useKeyboard (props, context, dep) | ||
{ | ||
@@ -9,8 +9,8 @@ const { mode, addTagOn, createTag } = toRefs(props) | ||
const internalValue = dependencies.internalValue | ||
const update = dependencies.update | ||
const closeDropdown = dependencies.closeDropdown | ||
const clearPointer = dependencies.clearPointer | ||
const search = dependencies.search | ||
const selectPointer = dependencies.selectPointer | ||
const iv = dep.iv | ||
const update = dep.update | ||
const closeDropdown = dep.closeDropdown | ||
const clearPointer = dep.clearPointer | ||
const search = dep.search | ||
const selectPointer = dep.selectPointer | ||
@@ -24,3 +24,3 @@ // =============== METHODS ============== | ||
update([...internalValue.value].slice(0,-1)) | ||
update([...iv.value].slice(0,-1)) | ||
} | ||
@@ -27,0 +27,0 @@ |
import { ref, toRefs, computed } from 'composition-api' | ||
export default function useMultiselect (props, context, dependencies) | ||
export default function useMultiselect (props, context, dep) | ||
{ | ||
@@ -5,0 +5,0 @@ const { searchable, id } = toRefs(props) |
@@ -6,5 +6,4 @@ import { ref, toRefs, computed, watch } from 'composition-api' | ||
import arraysEqual from './../utils/arraysEqual' | ||
import arrayObjectsEqual from './../utils/arrayObjectsEqual' | ||
export default function useOptions (props, context, dependencies) | ||
export default function useOptions (props, context, dep) | ||
{ | ||
@@ -20,11 +19,10 @@ const { | ||
const internalValue = dependencies.internalValue | ||
const externalValue = dependencies.externalValue | ||
const currentValue = dependencies.currentValue | ||
const search = dependencies.search | ||
const blurSearch = dependencies.blurSearch | ||
const clearSearch = dependencies.clearSearch | ||
const update = dependencies.update | ||
const blurInput = dependencies.blurInput | ||
const pointer = dependencies.pointer | ||
const iv = dep.iv | ||
const ev = dep.ev | ||
const search = dep.search | ||
const blurSearch = dep.blurSearch | ||
const clearSearch = dep.clearSearch | ||
const update = dep.update | ||
const blurInput = dep.blurInput | ||
const pointer = dep.pointer | ||
@@ -34,6 +32,8 @@ // ================ DATA ================ | ||
// no export | ||
const appendedOptions = ref([]) | ||
// appendedOptions | ||
const ap = ref([]) | ||
// no export | ||
const resolvedOptions = ref([]) | ||
// resolvedOptions | ||
const ro = ref([]) | ||
@@ -45,9 +45,10 @@ const resolving = ref(false) | ||
// no export | ||
const extendedOptions = computed(() => { | ||
let extendedOptions = resolvedOptions.value || [] | ||
// extendedOptions | ||
const eo = computed(() => { | ||
let eo = ro.value || [] | ||
// Transforming an object to an array of objects | ||
if (isObject(extendedOptions)) { | ||
extendedOptions = Object.keys(extendedOptions).map((key) => { | ||
let val = extendedOptions[key] | ||
if (isObject(eo)) { | ||
eo = Object.keys(eo).map((key) => { | ||
let val = eo[key] | ||
@@ -59,22 +60,23 @@ return { [valueProp.value]: key, [trackBy.value]: val, [label.value]: val} | ||
// Transforming an plain arrays to an array of objects | ||
extendedOptions = extendedOptions.map((val, key) => { | ||
return typeof val === 'object' ? val : { [valueProp.value]: key, [trackBy.value]: val, [label.value]: val} | ||
eo = eo.map((val, key) => { | ||
return typeof val === 'object' ? val : { [valueProp.value]: val, [trackBy.value]: val, [label.value]: val} | ||
}) | ||
if (appendedOptions.value.length) { | ||
extendedOptions = extendedOptions.concat(appendedOptions.value) | ||
if (ap.value.length) { | ||
eo = eo.concat(ap.value) | ||
} | ||
return extendedOptions | ||
return eo | ||
}) | ||
const filteredOptions = computed(() => { | ||
let filteredOptions = extendedOptions.value | ||
// filteredOptions | ||
const fo = computed(() => { | ||
let fo = eo.value | ||
if (createdTag.value.length) { | ||
filteredOptions = createdTag.value.concat(filteredOptions) | ||
fo = createdTag.value.concat(fo) | ||
} | ||
if (search.value && filterResults.value) { | ||
filteredOptions = filteredOptions.filter((option) => { | ||
fo = fo.filter((option) => { | ||
return normalize(option[trackBy.value]).indexOf(normalize(search.value)) !== -1 | ||
@@ -85,10 +87,10 @@ }) | ||
if (hideSelected.value) { | ||
filteredOptions = filteredOptions.filter((option) => !shouldHideOption(option)) | ||
fo = fo.filter((option) => !shouldHideOption(option)) | ||
} | ||
if (limit.value > 0) { | ||
filteredOptions = filteredOptions.slice(0, limit.value) | ||
fo = fo.slice(0, limit.value) | ||
} | ||
return filteredOptions | ||
return fo | ||
}) | ||
@@ -99,7 +101,7 @@ | ||
case 'single': | ||
return !isNullish(internalValue.value[valueProp.value]) | ||
return !isNullish(iv.value[valueProp.value]) | ||
case 'multiple': | ||
case 'tags': | ||
return !isNullish(internalValue.value) && internalValue.value.length > 0 | ||
return !isNullish(iv.value) && iv.value.length > 0 | ||
} | ||
@@ -110,12 +112,12 @@ }) | ||
return multipleLabel !== undefined && multipleLabel.value !== undefined | ||
? multipleLabel.value(internalValue.value) | ||
: (internalValue.value && internalValue.value.length > 1 ? `${internalValue.value.length} options selected` : `1 option selected`) | ||
? multipleLabel.value(iv.value) | ||
: (iv.value && iv.value.length > 1 ? `${iv.value.length} options selected` : `1 option selected`) | ||
}) | ||
const noOptions = computed(() => { | ||
return !extendedOptions.value.length && !resolving.value | ||
return !eo.value.length && !resolving.value | ||
}) | ||
const noResults = computed(() => { | ||
return extendedOptions.value.length > 0 && filteredOptions.value.length == 0 | ||
return eo.value.length > 0 && fo.value.length == 0 | ||
}) | ||
@@ -166,3 +168,3 @@ | ||
case 'tags': | ||
update((internalValue.value).concat(option)) | ||
update((iv.value).concat(option)) | ||
break | ||
@@ -186,3 +188,3 @@ } | ||
case 'multiple': | ||
update(internalValue.value.filter((val) => val[valueProp.value] != option[valueProp.value])) | ||
update(iv.value.filter((val) => val[valueProp.value] != option[valueProp.value])) | ||
break | ||
@@ -219,7 +221,7 @@ } | ||
case 'single': | ||
return !isNullish(internalValue.value) && internalValue.value[valueProp.value] == option[valueProp.value] | ||
return !isNullish(iv.value) && iv.value[valueProp.value] == option[valueProp.value] | ||
case 'tags': | ||
case 'multiple': | ||
return !isNullish(internalValue.value) && internalValue.value.map(o => o[valueProp.value]).indexOf(option[valueProp.value]) !== -1 | ||
return !isNullish(iv.value) && iv.value.map(o => o[valueProp.value]).indexOf(option[valueProp.value]) !== -1 | ||
} | ||
@@ -237,3 +239,3 @@ } | ||
return internalValue.value.length >= max.value | ||
return iv.value.length >= max.value | ||
} | ||
@@ -307,3 +309,3 @@ | ||
const getOption = (val) => { | ||
return extendedOptions.value[extendedOptions.value.map(o => String(o[valueProp.value])).indexOf(String(val))] | ||
return eo.value[eo.value.map(o => String(o[valueProp.value])).indexOf(String(val))] | ||
} | ||
@@ -313,3 +315,3 @@ | ||
const getOptionByTrackBy = (val) => { | ||
return extendedOptions.value.map(o => normalize(o[trackBy.value])).indexOf(normalize(val)) | ||
return eo.value.map(o => normalize(o[trackBy.value])).indexOf(normalize(val)) | ||
} | ||
@@ -324,3 +326,3 @@ | ||
const appendOption = (option) => { | ||
appendedOptions.value.push(option) | ||
ap.value.push(option) | ||
} | ||
@@ -330,4 +332,4 @@ | ||
const initInternalValue = () => { | ||
if (!isNullish(externalValue.value)) { | ||
internalValue.value = makeInternal(externalValue.value) | ||
if (!isNullish(ev.value)) { | ||
iv.value = makeInternal(ev.value) | ||
} | ||
@@ -340,3 +342,3 @@ } | ||
options.value(search.value).then((response) => { | ||
resolvedOptions.value = response | ||
ro.value = response | ||
@@ -351,2 +353,29 @@ if (typeof callback == 'function') { | ||
// no export | ||
const refreshLabels = () => { | ||
if (!hasSelected.value) { | ||
return | ||
} | ||
if (mode.value === 'single') { | ||
let newLabel = getOption(iv.value[valueProp.value])[label.value] | ||
iv.value[label.value] = newLabel | ||
if (object.value) { | ||
ev.value[label.value] = newLabel | ||
} | ||
} else { | ||
iv.value.forEach((val, i) => { | ||
let newLabel = getOption(iv.value[i][valueProp.value])[label.value] | ||
iv.value[i][label.value] = newLabel | ||
if (object.value) { | ||
ev.value[i][label.value] = newLabel | ||
} | ||
}) | ||
} | ||
} | ||
const refreshOptions = (callback) => { | ||
@@ -373,3 +402,3 @@ resolveOptions(callback) | ||
if (mode.value !== 'single' && !isNullish(externalValue.value) && !Array.isArray(externalValue.value)) { | ||
if (mode.value !== 'single' && !isNullish(ev.value) && !Array.isArray(ev.value)) { | ||
throw new Error(`v-model must be an array when using "${mode.value}" mode`) | ||
@@ -386,3 +415,3 @@ } | ||
else { | ||
resolvedOptions.value = options.value | ||
ro.value = options.value | ||
@@ -403,3 +432,3 @@ initInternalValue() | ||
if (clearOnSearch.value) { | ||
resolvedOptions.value = [] | ||
ro.value = [] | ||
} | ||
@@ -413,4 +442,4 @@ setTimeout(() => { | ||
if (query == search.value) { | ||
resolvedOptions.value = response | ||
pointer.value = filteredOptions.value.filter(o => o.disabled !== true)[0] || null | ||
ro.value = response | ||
pointer.value = fo.value.filter(o => o.disabled !== true)[0] || null | ||
resolving.value = false | ||
@@ -424,5 +453,5 @@ } | ||
watch(externalValue, (newValue) => { | ||
watch(ev, (newValue) => { | ||
if (isNullish(newValue)) { | ||
internalValue.value = makeInternal(newValue) | ||
iv.value = makeInternal(newValue) | ||
return | ||
@@ -433,4 +462,4 @@ } | ||
case 'single': | ||
if (object.value ? newValue[valueProp.value] != internalValue.value[valueProp.value] : newValue != internalValue.value[valueProp.value]) { | ||
internalValue.value = makeInternal(newValue) | ||
if (object.value ? newValue[valueProp.value] != iv.value[valueProp.value] : newValue != iv.value[valueProp.value]) { | ||
iv.value = makeInternal(newValue) | ||
} | ||
@@ -441,4 +470,4 @@ break | ||
case 'tags': | ||
if (!arraysEqual(object.value ? newValue.map(o => o[valueProp.value]) : newValue, internalValue.value.map(o => o[valueProp.value]))) { | ||
internalValue.value = makeInternal(newValue) | ||
if (!arraysEqual(object.value ? newValue.map(o => o[valueProp.value]) : newValue, iv.value.map(o => o[valueProp.value]))) { | ||
iv.value = makeInternal(newValue) | ||
} | ||
@@ -450,51 +479,18 @@ break | ||
if (typeof props.options !== 'function') { | ||
watch(() => props.options, (n, o) => { | ||
resolvedOptions.value = props.options | ||
}) | ||
watch(options, (n, o) => { | ||
ro.value = props.options | ||
watch(extendedOptions, (n, o) => { | ||
if (!Object.keys(internalValue.value).length) { | ||
if (!Object.keys(iv.value).length) { | ||
initInternalValue() | ||
} | ||
if (!n.length || !currentValue.value || !currentValue.value.length) { | ||
return | ||
} | ||
let newValue | ||
if (mode.value === 'single') { | ||
newValue = n[n.map(v=>v[valueProp.value]).indexOf(currentValue.value)] | ||
if (JSON.stringify(newValue) === JSON.stringify(internalValue.value)) { | ||
return | ||
} | ||
} else { | ||
newValue = [] | ||
currentValue.value.forEach((val) => { | ||
newValue.push(n[n.map(v=>v[valueProp.value]).indexOf(val)]) | ||
}) | ||
if (arrayObjectsEqual(newValue, internalValue.value)) { | ||
return | ||
} | ||
} | ||
// Update both internal and external value if user is using object values | ||
if (object.value) { | ||
update(newValue) | ||
// Only update internal value if external is only valueProp | ||
} else { | ||
internalValue.value = newValue | ||
} | ||
}, { flush: 'sync', deep: true, immediate: false }) | ||
refreshLabels() | ||
}) | ||
} | ||
return { | ||
filteredOptions, | ||
fo, | ||
hasSelected, | ||
multipleLabelText, | ||
extendedOptions, | ||
eo, | ||
noOptions, | ||
@@ -501,0 +497,0 @@ noResults, |
import { ref } from 'composition-api' | ||
export default function usePointer (props, context, dependencies) | ||
export default function usePointer (props, context, dep) | ||
{ | ||
@@ -5,0 +5,0 @@ // ================ DATA ================ |
import { toRefs, watch, nextTick, computed } from 'composition-api' | ||
export default function usePointer (props, context, dependencies) | ||
export default function usePointer (props, context, dep) | ||
{ | ||
@@ -9,6 +9,6 @@ const { id, valueProp } = toRefs(props) | ||
const filteredOptions = dependencies.filteredOptions | ||
const handleOptionClick = dependencies.handleOptionClick | ||
const search = dependencies.search | ||
const pointer = dependencies.pointer | ||
const fo = dep.fo | ||
const handleOptionClick = dep.handleOptionClick | ||
const search = dep.search | ||
const pointer = dep.pointer | ||
@@ -19,3 +19,3 @@ // ============== COMPUTED ============== | ||
const options = computed(() => { | ||
return filteredOptions.value.filter(o => o.disabled !== true) | ||
return fo.value.filter(o => o.disabled !== true) | ||
}) | ||
@@ -22,0 +22,0 @@ |
import { ref, toRefs, computed, watch } from 'composition-api' | ||
export default function useSearch (props, context, dependencies) | ||
export default function useSearch (props, context, dep) | ||
{ | ||
@@ -9,3 +9,3 @@ const { searchable, mode } = toRefs(props) | ||
const internalValue = dependencies.internalValue | ||
const iv = dep.iv | ||
@@ -25,3 +25,3 @@ // ================ DATA ================ | ||
if (mode.value !== 'tags' || [null, undefined].indexOf(internalValue.value) !== -1 || !internalValue.value.length) { | ||
if (mode.value !== 'tags' || [null, undefined].indexOf(iv.value) !== -1 || !iv.value.length) { | ||
return '100%' | ||
@@ -28,0 +28,0 @@ } |
import { computed, toRefs, ref } from 'composition-api' | ||
import isNullish from './../utils/isNullish' | ||
@@ -10,3 +9,4 @@ export default function useValue (props, context) | ||
const internalValue = ref(mode.value !== 'single' ? [] : {}) | ||
// internalValue | ||
const iv = ref(mode.value !== 'single' ? [] : {}) | ||
@@ -16,22 +16,14 @@ // ============== COMPUTED ============== | ||
/* istanbul ignore next */ | ||
const externalValue = context.expose !== undefined ? modelValue : value | ||
// externalValue | ||
const ev = context.expose !== undefined ? modelValue : value | ||
const currentValue = computed(() => { | ||
if (!Object.keys(internalValue.value).length) { | ||
return internalValue.value | ||
} | ||
return mode.value !== 'single' ? internalValue.value.map(v=>v[valueProp.value]) : internalValue.value[valueProp.value] | ||
}) | ||
const textValue = computed(() => { | ||
return mode.value !== 'single' ? internalValue.value.map(v=>v[valueProp.value]).join(',') : internalValue.value[valueProp.value] | ||
return mode.value !== 'single' ? iv.value.map(v=>v[valueProp.value]).join(',') : iv.value[valueProp.value] | ||
}) | ||
return { | ||
internalValue, | ||
externalValue, | ||
currentValue, | ||
iv, | ||
ev, | ||
textValue, | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152192
28
1097