@vueform/multiselect
Advanced tools
Comparing version 1.2.5 to 1.3.0
@@ -0,1 +1,19 @@ | ||
## v1.3.0 | ||
> `2021-02-05` | ||
### 🎉 Feature | ||
- Added Typescript definitions based on [#20](https://github.com/vueform/multiselect/pull/20). | ||
- Added Clear button for `multiple` and `tags` mode. | ||
- Added `placeholder` slot. | ||
- Added proper `open` and `close` methods. | ||
- Hide options when resolving with `clearOnSearch` `true`. | ||
- Added `refreshOptions` method to refresh async options. | ||
- Added API docs. | ||
### 🐞 Bug Fixes | ||
- Added fix for #26. The value now can be set the same time that `options` change. | ||
- Added fix for #28. Right mouse click no longer removes tag. | ||
- Added fix for #29. Focus is no longer trapped to option list when using search. | ||
## v1.2.5 | ||
@@ -2,0 +20,0 @@ |
@@ -1,1 +0,1 @@ | ||
var VueformMultiselect=function(e,t){"use strict";function l(e){return String(e).toLowerCase().trim()}function n(e){return-1!==[null,void 0,!1].indexOf(e)}function a(e){return(a="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 r(e,t,l){return t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l,e}function u(e){return function(e){if(Array.isArray(e))return i(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 i(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 i(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 i(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(t,u,i){var o=e.toRefs(t),c=o.options,s=o.mode,d=o.trackBy,v=o.limit,p=o.hideSelected,f=o.createTag,h=o.label,m=o.appendNewTag,y=o.multipleLabel,b=o.object,g=o.loading,w=o.delay,S=o.resolveOnLoad,V=o.minChars,k=o.filterResults,B=o.clearOnSearch,O=o.clearOnSelect,x=o.valueProp,M=o.canDeselect,N=o.max,P=i.internalValue,q=i.externalValue,T=i.search,C=i.blurSearch,K=i.clearSearch,D=i.update,j=i.blurInput,A=i.pointer,E=e.ref([]),R=e.ref([]),I=e.ref(!1),L=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 r(l={},x.value,e),r(l,d.value,n),r(l,h.value,n),l}))),t=t.map((function(e,t){var l;return"object"===a(e)?e:(r(l={},x.value,t),r(l,d.value,e),r(l,h.value,e),l)})),E.value.length&&(t=t.concat(E.value)),t})),$=e.computed((function(){var e=L.value;return W.value.length&&(e=W.value.concat(e)),T.value&&k.value&&(e=e.filter((function(e){return-1!==l(e[d.value]).indexOf(l(T.value))}))),p.value&&(e=e.filter((function(e){return!ae(e)}))),v.value>0&&(e=e.slice(0,v.value)),e})),H=e.computed((function(){switch(s.value){case"single":return!n(P.value[x.value]);case"multiple":case"tags":return!n(P.value)&&P.value.length>0}})),F=e.computed((function(){return void 0!==y&&void 0!==y.value?y.value(P.value):P.value&&P.value.length>1?"".concat(P.value.length," options selected"):"1 option selected"})),_=e.computed((function(){return!L.value.length})),U=e.computed((function(){return L.value.length>0&&0==$.value.length})),W=e.computed((function(){var e;return!1!==f.value&&T.value?-1!==ne(T.value)?[]:[(e={},r(e,x.value,T.value),r(e,h.value,T.value),r(e,d.value,T.value),e)]:[]})),z=e.computed((function(){switch(s.value){case"single":return null;case"multiple":case"tags":return[]}})),G=e.computed((function(){return g.value||I.value})),J=function(e){switch("object"!==a(e)&&(e=le(e)),s.value){case"single":D(e);break;case"multiple":case"tags":D(P.value.concat(e))}u.emit("select",X(e))},Q=function(e){switch("object"!==a(e)&&(e=le(e)),s.value){case"single":Y();break;case"tags":case"multiple":D(P.value.filter((function(t){return t[x.value]!=e[x.value]})))}u.emit("deselect",X(e))},X=function(e){return b.value?e:e[x.value]},Y=function(){D(z.value)},Z=function(e){switch(s.value){case"single":return!n(P.value)&&P.value[x.value]==e[x.value];case"tags":case"multiple":return!n(P.value)&&-1!==P.value.map((function(e){return e[x.value]})).indexOf(e[x.value])}},ee=function(e){return!0===e.disabled},te=function(){return!(void 0===N||-1===N.value||!H.value&&N.value>0)&&P.value.length>=N.value},le=function(e){return L.value[L.value.map((function(e){return String(e[x.value])})).indexOf(String(e))]},ne=function(e){return L.value.map((function(e){return l(e[d.value])})).indexOf(l(e))},ae=function(e){return"tags"===s.value&&p.value&&Z(e)},re=function(e){E.value.push(e)},ue=function(){n(q.value)||(P.value=oe(q.value))},ie=function(e){I.value=!0,c.value(T.value).then((function(t){R.value=t,I.value=!1,"function"==typeof e&&e(t)}))},oe=function(e){return n(e)?"single"===s.value?{}:[]:b.value?e:"single"===s.value?le(e)||{}:e.filter((function(e){return!!le(e)})).map((function(e){return le(e)}))};if("single"!==s.value&&!n(q.value)&&!Array.isArray(q.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(ue):1==b.value&&ue():(R.value=c&&c.value?c.value:[],ue()),w.value>-1&&e.watch(T,(function(e){e.length<V.value||(B.value&&(R.value=[]),setTimeout((function(){e==T.value&&(I.value=!0,c.value(T.value).then((function(t){e==T.value&&(R.value=t,A.value=$.value.filter((function(e){return!0!==e.disabled}))[0]||null),I.value=!1})))}),w.value))}),{flush:"sync"}),e.watch(q,(function(e){var t,l,a;if(n(e))P.value=oe(e);else switch(s.value){case"single":(b.value?e[x.value]!=P.value[x.value]:e!=P.value[x.value])&&(P.value=oe(e));break;case"multiple":case"tags":t=b.value?e.map((function(e){return e[x.value]})):e,l=P.value.map((function(e){return e[x.value]})),a=l.slice().sort(),t.length===l.length&&t.slice().sort().every((function(e,t){return e===a[t]}))||(P.value=oe(e))}}),{deep:!0}),e.watch((function(){return t.options}),(function(e){"function"!=typeof t.options&&(R.value=t.options)})),{filteredOptions:$,hasSelected:H,multipleLabelText:F,extendedOptions:L,noOptions:_,noResults:U,busy:G,select:J,deselect:Q,remove:function(e){Q(e)},clear:Y,isSelected:Z,isDisabled:ee,isMax:te,getOption:le,handleOptionClick:function(e){if(!ee(e))switch(s.value){case"single":if(Z(e))return void(M.value&&Q(e));J(e),C(),j();break;case"multiple":if(Z(e))return void Q(e);if(te())return;J(e),O.value&&K();break;case"tags":if(Z(e))return void Q(e);if(te())return;void 0===le(e[x.value])&&f.value&&(u.emit("tag",e[x.value]),m.value&&re(e),K()),O.value&&K(),J(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},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}},setup(t,l){const a=function(t,l){var n=e.toRefs(t),a=n.value,r=n.modelValue,u=n.mode;return{internalValue:e.ref("single"!==u.value?[]:{}),externalValue:void 0!==l.expose?r:a}}(t,l),r=function(t,l,n){var a=e.toRefs(t),r=a.searchable,u=a.id;return{multiselect:e.ref(null),tabindex:e.computed((function(){return r.value?-1:0})),blurInput:function(){document.getElementById(u.value).querySelector(".multiselect-input").blur()}}}(t),i={pointer:e.ref(null)},c=function(t,l,n){var a=e.toRefs(t),r=a.maxHeight,u=a.disabled,i=a.searchable,o=n.multiselect,c=e.ref(!1),s=e.computed((function(){return"".concat(r.value,"px")}));return{isOpen:c,contentMaxHeight:s,open:function(e){u.value||(c.value=!0,l.emit("open"))},close:function(){c.value=!1,l.emit("close")},handleInputMousedown:function(e){c.value&&!i.value&&(o.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),o.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(t,l,{multiselect:r.multiselect}),s=function(t,l,a){var r=e.toRefs(t),u=r.object,i=r.valueProp,o=r.mode,c=a.internalValue,s=function(e){return u.value||n(e)?e:Array.isArray(e)?e.map((function(e){return e[i.value]})):e[i.value]},d=function(e){return n(e)?"single"===o.value?{}:[]:e};return{update:function(e){c.value=d(e);var t=s(e);l.emit("change",t),l.emit("input",t),l.emit("update:modelValue",t)}}}(t,l,{internalValue:a.internalValue}),d=function(t,l,n){var a=e.toRefs(t),r=a.searchable,u=a.mode,i=n.internalValue,o=e.ref(null),c=e.ref(null),s=e.computed((function(){return o.value?"".concat(o.value.length,"ch"):"tags"===u.value&&-1===[null,void 0].indexOf(i.value)&&i.value.length?"1ch":"100%"}));return e.watch(o,(function(e){l.emit("search-change",e)})),{search:o,input:c,tagsSearchWidth:s,clearSearch:function(){o.value=""},blurSearch:function(){r.value&&c.value.blur()}}}(t,l,{internalValue:a.internalValue}),v=o(t,l,{externalValue:a.externalValue,internalValue:a.internalValue,search:d.search,blurSearch:d.blurSearch,clearSearch:d.clearSearch,update:s.update,blurInput:r.blurInput,pointer:i.pointer}),p=function(t,l,n){var a=e.toRefs(t),r=a.id,u=a.valueProp,i=n.filteredOptions,o=n.handleOptionClick,c=n.search,s=n.pointer,d=e.computed((function(){return i.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?(o(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:d.search,pointer:i.pointer}),f=function(t,l,n){var a=e.toRefs(t).mode,r=n.internalValue,i=n.update,o=n.close,c=n.clearPointer,s=n.search;return{handleBackspace:function(e){"single"!==a.value&&i(u(r.value).slice(0,-1))},handleEsc:function(e){o(),c(),e.target.blur()},handleSearchBackspace:function(e){""!==s.value&&e.stopPropagation()}}}(t,0,{internalValue:a.internalValue,update:s.update,close:c.close,clearPointer:p.clearPointer,search:d.search});return{...a,...c,...r,...i,...s,...d,...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-spinner"},m={class:"multiselect-no-options"},y={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[27]||(l[27]=t.withKeys(t.withModifiers((()=>{}),["prevent"]),["enter"])),ref:"multiselect"},[t.createVNode("div",{class:"multiselect-input",tabindex:e.tabindex,onMousedown:l[18]||(l[18]=(...t)=>e.handleInputMousedown&&e.handleInputMousedown(...t)),onFocus:l[19]||(l[19]=(...t)=>e.open&&e.open(...t)),onBlur:l[20]||(l[20]=(...t)=>e.close&&e.close(...t)),onKeyup:[l[21]||(l[21]=t.withKeys(((...t)=>e.handleEsc&&e.handleEsc(...t)),["esc"])),l[22]||(l[22]=t.withKeys(((...t)=>e.selectPointer&&e.selectPointer(...t)),["enter"]))],onKeydown:[l[23]||(l[23]=t.withKeys(t.withModifiers(((...t)=>e.handleBackspace&&e.handleBackspace(...t)),["prevent"]),["delete"])),l[24]||(l[24]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["prevent"]),["up"])),l[25]||(l[25]=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",s,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",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.withDirectives(t.createVNode("input",{"onUpdate:modelValue":l[1]||(l[1]=t=>e.search=t),onFocus:l[2]||(l[2]=t.withModifiers(((...t)=>e.open&&e.open(...t)),["stop"])),onBlur:l[3]||(l[3]=t.withModifiers(((...t)=>e.close&&e.close(...t)),["stop"])),onKeyup:[l[4]||(l[4]=t.withKeys(t.withModifiers(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),l[5]||(l[5]=t.withKeys(t.withModifiers(((...t)=>e.selectPointer&&e.selectPointer(...t)),["stop"]),["enter"]))],onKeydown:[l[6]||(l[6]=t.withKeys(((...t)=>e.handleSearchBackspace&&e.handleSearchBackspace(...t)),["delete"])),l[7]||(l[7]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["stop"]),["up"])),l[8]||(l[8]=t.withKeys(t.withModifiers(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["stop"]),["down"]))],ref:"input"},null,544),[[t.vModelText,e.search]])])):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.internalValue,((a,r,u)=>(t.openBlock(),t.createBlock("span",{key:u},[t.renderSlot(e.$slots,"tag",{option:a,remove:e.remove,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.remove(a)),["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.withDirectives(t.createVNode("input",{"onUpdate:modelValue":l[10]||(l[10]=t=>e.search=t),onFocus:l[11]||(l[11]=t.withModifiers(((...t)=>e.open&&e.open(...t)),["stop"])),onBlur:l[12]||(l[12]=t.withModifiers(((...t)=>e.close&&e.close(...t)),["stop"])),onKeyup:[l[13]||(l[13]=t.withKeys(t.withModifiers(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),l[14]||(l[14]=t.withKeys(t.withModifiers(((...t)=>e.selectPointer&&e.selectPointer(...t)),["stop"]),["enter"]))],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"]))],style:{width:e.tagsSearchWidth},ref:"input"},null,36),[[t.vModelText,e.search]])],4)):t.createCommentVNode("v-if",!0)])):t.createCommentVNode("v-if",!0),t.createCommentVNode(" Placeholder "),t.withDirectives(t.createVNode("div",{class:"multiselect-placeholder"},t.toDisplayString(n.placeholder),513),[[t.vShow,n.placeholder&&!e.hasSelected&&!e.search]]),t.createVNode(t.Transition,{name:"multiselect-loading"},{default:t.withCtx((()=>[t.withDirectives(t.createVNode("div",h,null,512),[[t.vShow,e.busy]])])),_:1})],40,["tabindex"]),t.createCommentVNode(" Options "),t.createVNode(t.Transition,{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("a",{href:"",class:["multiselect-option",{"is-pointed":e.isPointed(a),"is-selected":e.isSelected(a),"is-disabled":e.isDisabled(a)}],key:u,onMousedown:l[26]||(l[26]=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",m,t.toDisplayString(n.noOptionsText),1)]))],512),[[t.vShow,e.noOptions]]),t.withDirectives(t.createVNode("span",null,[t.renderSlot(e.$slots,"noresults",{},(()=>[t.createVNode("div",y,t.toDisplayString(n.noResultsText),1)]))],512),[[t.vShow,e.noResults]]),t.renderSlot(e.$slots,"afterlist")],4),[[t.vShow,e.isOpen]])])),_:3},8,["onAfterLeave"])],42,["id"])},c.__file="src/Multiselect.vue",c}(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,b=i.object,w=i.loading,g=i.delay,S=i.resolveOnLoad,k=i.minChars,V=i.filterResults,B=i.clearOnSearch,O=i.clearOnSelect,x=i.valueProp,N=i.canDeselect,M=i.max,P=u.internalValue,q=u.externalValue,D=u.search,T=u.blurSearch,C=u.clearSearch,K=u.update,I=u.blurInput,j=u.pointer,R=e.ref([]),A=e.ref([]),E=e.ref(!1),L=e.computed((function(){var e,t=A.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,d.value,n),a(l,h.value,n),l}))),t=t.map((function(e,t){var l;return"object"===n(e)?e:(a(l={},x.value,t),a(l,d.value,e),a(l,h.value,e),l)})),R.value.length&&(t=t.concat(R.value)),t})),$=e.computed((function(){var e=L.value;return W.value.length&&(e=W.value.concat(e)),D.value&&V.value&&(e=e.filter((function(e){return-1!==o(e[d.value]).indexOf(o(D.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(P.value[x.value]);case"multiple":case"tags":return!l(P.value)&&P.value.length>0}})),F=e.computed((function(){return void 0!==y&&void 0!==y.value?y.value(P.value):P.value&&P.value.length>1?"".concat(P.value.length," options selected"):"1 option selected"})),_=e.computed((function(){return!L.value.length&&!E.value})),U=e.computed((function(){return L.value.length>0&&0==$.value.length})),W=e.computed((function(){var e;return!1!==f.value&&D.value?-1!==ae(D.value)?[]:[(e={},a(e,x.value,D.value),a(e,h.value,D.value),a(e,d.value,D.value),e)]:[]})),z=e.computed((function(){switch(s.value){case"single":return null;case"multiple":case"tags":return[]}})),G=e.computed((function(){return w.value||E.value})),J=function(e){switch("object"!==n(e)&&(e=ne(e)),s.value){case"single":K(e);break;case"multiple":case"tags":K(P.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":K(P.value.filter((function(t){return t[x.value]!=e[x.value]})))}r.emit("deselect",X(e))},X=function(e){return b.value?e:e[x.value]},Y=function(e){Q(e)},Z=function(){K(z.value)},ee=function(e){switch(s.value){case"single":return!l(P.value)&&P.value[x.value]==e[x.value];case"tags":case"multiple":return!l(P.value)&&-1!==P.value.map((function(e){return e[x.value]})).indexOf(e[x.value])}},te=function(e){return!0===e.disabled},le=function(){return!(void 0===M||-1===M.value||!H.value&&M.value>0)&&P.value.length>=M.value},ne=function(e){return L.value[L.value.map((function(e){return String(e[x.value])})).indexOf(String(e))]},ae=function(e){return L.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){R.value.push(e)},oe=function(){l(q.value)||(P.value=ce(q.value))},ie=function(e){E.value=!0,c.value(D.value).then((function(t){A.value=t,"function"==typeof e&&e(t),E.value=!1}))},ce=function(e){return l(e)?"single"===s.value?{}:[]:b.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(q.value)&&!Array.isArray(q.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==b.value&&oe():(A.value=c&&c.value?c.value:[],oe()),g.value>-1&&e.watch(D,(function(e){e.length<k.value||(E.value=!0,B.value&&(A.value=[]),setTimeout((function(){e==D.value&&c.value(D.value).then((function(t){e==D.value&&(A.value=t,j.value=$.value.filter((function(e){return!0!==e.disabled}))[0]||null,E.value=!1)}))}),g.value))}),{flush:"sync"}),e.watch(q,(function(e){var t,n,a;if(l(e))P.value=ce(e);else switch(s.value){case"single":(b.value?e[x.value]!=P.value[x.value]:e!=P.value[x.value])&&(P.value=ce(e));break;case"multiple":case"tags":t=b.value?e.map((function(e){return e[x.value]})):e,n=P.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]}))||(P.value=ce(e))}}),{deep:!0}),e.watch((function(){return t.options}),(function(e){"function"!=typeof t.options&&(A.value=t.options)}),{flush:"sync"}),{filteredOptions:$,hasSelected:H,multipleLabelText:F,extendedOptions:L,noOptions:_,noResults:U,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(N.value&&Q(e));J(e),T(),I();break;case"multiple":if(ee(e))return void Q(e);if(le())return;J(e),O.value&&C();break;case"tags":if(ee(e))return void Q(e);if(le())return;void 0===ne(e[x.value])&&f.value&&(r.emit("tag",e[x.value]),m.value&&ue(e),C()),O.value&&C(),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},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}},setup(t,n){const a=function(t,l){var n=e.toRefs(t),a=n.value,r=n.modelValue,u=n.mode;return{internalValue:e.ref("single"!==u.value?[]:{}),externalValue:void 0!==l.expose?r:a}}(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.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=i(t,n,{externalValue:a.externalValue,internalValue:a.internalValue,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.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).mode,u=n.internalValue,o=n.update,i=n.closeDropdown,c=n.clearPointer,s=n.search;return{handleBackspace:function(e){"single"!==a.value&&o(r(u.value).slice(0,-1))},handleEsc:function(e){i(),c(),e.target.blur()},handleSearchBackspace:function(e){""!==s.value&&e.stopPropagation()}}}(t,0,{internalValue:a.internalValue,update:c.update,closeDropdown:d.closeDropdown,clearPointer:p.clearPointer,search:s.search});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={class:"multiselect-spinner"},y={class:"multiselect-no-options"},b={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[28]||(l[28]=t.withKeys(t.withModifiers((()=>{}),["prevent"]),["enter"])),ref:"multiselect"},[t.createVNode("div",{class:"multiselect-input",tabindex:e.tabindex,onMousedown:l[19]||(l[19]=(...t)=>e.handleInputMousedown&&e.handleInputMousedown(...t)),onFocus:l[20]||(l[20]=(...t)=>e.openDropdown&&e.openDropdown(...t)),onBlur:l[21]||(l[21]=(...t)=>e.closeDropdown&&e.closeDropdown(...t)),onKeyup:[l[22]||(l[22]=t.withKeys(((...t)=>e.handleEsc&&e.handleEsc(...t)),["esc"])),l[23]||(l[23]=t.withKeys(((...t)=>e.selectPointer&&e.selectPointer(...t)),["enter"]))],onKeydown:[l[24]||(l[24]=t.withKeys(t.withModifiers(((...t)=>e.handleBackspace&&e.handleBackspace(...t)),["prevent"]),["delete"])),l[25]||(l[25]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["prevent"]),["up"])),l[26]||(l[26]=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",s,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",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.withDirectives(t.createVNode("input",{"onUpdate:modelValue":l[1]||(l[1]=t=>e.search=t),onFocus:l[2]||(l[2]=t.withModifiers(((...t)=>e.openDropdown&&e.openDropdown(...t)),["stop"])),onBlur:l[3]||(l[3]=t.withModifiers(((...t)=>e.closeDropdown&&e.closeDropdown(...t)),["stop"])),onKeyup:[l[4]||(l[4]=t.withKeys(t.withModifiers(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),l[5]||(l[5]=t.withKeys(t.withModifiers(((...t)=>e.selectPointer&&e.selectPointer(...t)),["stop"]),["enter"]))],onKeydown:[l[6]||(l[6]=t.withKeys(((...t)=>e.handleSearchBackspace&&e.handleSearchBackspace(...t)),["delete"])),l[7]||(l[7]=t.withKeys(t.withModifiers(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["stop"]),["up"])),l[8]||(l[8]=t.withKeys(t.withModifiers(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["stop"]),["down"]))],ref:"input"},null,544),[[t.vModelText,e.search]])])):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.internalValue,((a,r,u)=>(t.openBlock(),t.createBlock("span",{key:u},[t.renderSlot(e.$slots,"tag",{option:a,remove:e.remove,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.withDirectives(t.createVNode("input",{"onUpdate:modelValue":l[10]||(l[10]=t=>e.search=t),onFocus:l[11]||(l[11]=t.withModifiers(((...t)=>e.openDropdown&&e.openDropdown(...t)),["stop"])),onBlur:l[12]||(l[12]=t.withModifiers(((...t)=>e.closeDropdown&&e.closeDropdown(...t)),["stop"])),onKeyup:[l[13]||(l[13]=t.withKeys(t.withModifiers(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),l[14]||(l[14]=t.withKeys(t.withModifiers(((...t)=>e.selectPointer&&e.selectPointer(...t)),["stop"]),["enter"]))],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"]))],style:{width:e.tagsSearchWidth},ref:"input"},null,36),[[t.vModelText,e.search]])],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)])),t.createVNode(t.Transition,{name:"multiselect-loading"},{default:t.withCtx((()=>[t.withDirectives(t.createVNode("div",m,null,512),[[t.vShow,e.busy]])])),_:1}),"single"!==n.mode&&e.hasSelected&&!n.disabled?(t.openBlock(),t.createBlock("a",{key:5,class:"multiselect-clear",onClick:l[18]||(l[18]=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("a",{tabindex:-1,href:"",class:["multiselect-option",{"is-pointed":e.isPointed(a),"is-selected":e.isSelected(a),"is-disabled":e.isDisabled(a)}],key:u,onMousedown:l[27]||(l[27]=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",y,t.toDisplayString(n.noOptionsText),1)]))],512),[[t.vShow,e.noOptions]]),t.withDirectives(t.createVNode("span",null,[t.renderSlot(e.$slots,"noresults",{},(()=>[t.createVNode("div",b,t.toDisplayString(n.noResultsText),1)]))],512),[[t.vShow,e.noResults]]),t.renderSlot(e.$slots,"afterlist")],4),[[t.vShow,e.isOpen]])])),_:3},8,["onAfterLeave"]))],42,["id"])},c.__file="src/Multiselect.vue",c}(Vue,Vue); |
@@ -1,1 +0,1 @@ | ||
import{toRefs as e,ref as t,computed as l,watch as n,nextTick as a,openBlock as u,createBlock as r,withKeys as i,withModifiers as o,createVNode as c,createCommentVNode as s,renderSlot as d,toDisplayString as v,withDirectives as p,vModelText as f,Fragment as h,renderList as m,createTextVNode as b,vShow as y,Transition as g,withCtx as S}from"vue";function w(e){return String(e).toLowerCase().trim()}function O(e){return-1!==[null,void 0,!1].indexOf(e)}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 P(e,t,l){return t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l,e}function q(a,u,r){var i=e(a),o=i.options,c=i.mode,s=i.trackBy,d=i.limit,v=i.hideSelected,p=i.createTag,f=i.label,h=i.appendNewTag,m=i.multipleLabel,b=i.object,y=i.loading,g=i.delay,S=i.resolveOnLoad,q=i.minChars,x=i.filterResults,B=i.clearOnSearch,V=i.clearOnSelect,T=i.valueProp,j=i.canDeselect,M=i.max,A=r.internalValue,E=r.externalValue,C=r.search,I=r.blurSearch,N=r.clearSearch,$=r.update,H=r.blurInput,L=r.pointer,K=t([]),F=t([]),R=t(!1),D=l((function(){var e,t=F.value||[];return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(t=Object.keys(t).map((function(e){var l,n=t[e];return P(l={},T.value,e),P(l,s.value,n),P(l,f.value,n),l}))),t=t.map((function(e,t){var l;return"object"===k(e)?e:(P(l={},T.value,t),P(l,s.value,e),P(l,f.value,e),l)})),K.value.length&&(t=t.concat(K.value)),t})),_=l((function(){var e=D.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))}))),v.value&&(e=e.filter((function(e){return!ie(e)}))),d.value>0&&(e=e.slice(0,d.value)),e})),U=l((function(){switch(c.value){case"single":return!O(A.value[T.value]);case"multiple":case"tags":return!O(A.value)&&A.value.length>0}})),W=l((function(){return void 0!==m&&void 0!==m.value?m.value(A.value):A.value&&A.value.length>1?"".concat(A.value.length," options selected"):"1 option selected"})),z=l((function(){return!D.value.length})),G=l((function(){return D.value.length>0&&0==_.value.length})),J=l((function(){var e;return!1!==p.value&&C.value?-1!==re(C.value)?[]:[(e={},P(e,T.value,C.value),P(e,f.value,C.value),P(e,s.value,C.value),e)]:[]})),Q=l((function(){switch(c.value){case"single":return null;case"multiple":case"tags":return[]}})),X=l((function(){return y.value||R.value})),Y=function(e){switch("object"!==k(e)&&(e=ue(e)),c.value){case"single":$(e);break;case"multiple":case"tags":$(A.value.concat(e))}u.emit("select",ee(e))},Z=function(e){switch("object"!==k(e)&&(e=ue(e)),c.value){case"single":te();break;case"tags":case"multiple":$(A.value.filter((function(t){return t[T.value]!=e[T.value]})))}u.emit("deselect",ee(e))},ee=function(e){return b.value?e:e[T.value]},te=function(){$(Q.value)},le=function(e){switch(c.value){case"single":return!O(A.value)&&A.value[T.value]==e[T.value];case"tags":case"multiple":return!O(A.value)&&-1!==A.value.map((function(e){return e[T.value]})).indexOf(e[T.value])}},ne=function(e){return!0===e.disabled},ae=function(){return!(void 0===M||-1===M.value||!U.value&&M.value>0)&&A.value.length>=M.value},ue=function(e){return D.value[D.value.map((function(e){return String(e[T.value])})).indexOf(String(e))]},re=function(e){return D.value.map((function(e){return w(e[s.value])})).indexOf(w(e))},ie=function(e){return"tags"===c.value&&v.value&&le(e)},oe=function(e){K.value.push(e)},ce=function(){O(E.value)||(A.value=de(E.value))},se=function(e){R.value=!0,o.value(C.value).then((function(t){F.value=t,R.value=!1,"function"==typeof e&&e(t)}))},de=function(e){return O(e)?"single"===c.value?{}:[]:b.value?e:"single"===c.value?ue(e)||{}:e.filter((function(e){return!!ue(e)})).map((function(e){return ue(e)}))};if("single"!==c.value&&!O(E.value)&&!Array.isArray(E.value))throw new Error('v-model must be an array when using "'.concat(c.value,'" mode'));return o&&"function"==typeof o.value?S.value?se(ce):1==b.value&&ce():(F.value=o&&o.value?o.value:[],ce()),g.value>-1&&n(C,(function(e){e.length<q.value||(B.value&&(F.value=[]),setTimeout((function(){e==C.value&&(R.value=!0,o.value(C.value).then((function(t){e==C.value&&(F.value=t,L.value=_.value.filter((function(e){return!0!==e.disabled}))[0]||null),R.value=!1})))}),g.value))}),{flush:"sync"}),n(E,(function(e){var t,l,n;if(O(e))A.value=de(e);else switch(c.value){case"single":(b.value?e[T.value]!=A.value[T.value]:e!=A.value[T.value])&&(A.value=de(e));break;case"multiple":case"tags":t=b.value?e.map((function(e){return e[T.value]})):e,l=A.value.map((function(e){return e[T.value]})),n=l.slice().sort(),t.length===l.length&&t.slice().sort().every((function(e,t){return e===n[t]}))||(A.value=de(e))}}),{deep:!0}),n((function(){return a.options}),(function(e){"function"!=typeof a.options&&(F.value=a.options)})),{filteredOptions:_,hasSelected:U,multipleLabelText:W,extendedOptions:D,noOptions:z,noResults:G,busy:X,select:Y,deselect:Z,remove:function(e){Z(e)},clear:te,isSelected:le,isDisabled:ne,isMax:ae,getOption:ue,handleOptionClick:function(e){if(!ne(e))switch(c.value){case"single":if(le(e))return void(j.value&&Z(e));Y(e),I(),H();break;case"multiple":if(le(e))return void Z(e);if(ae())return;Y(e),V.value&&N();break;case"tags":if(le(e))return void Z(e);if(ae())return;void 0===ue(e[T.value])&&p.value&&(u.emit("tag",e[T.value]),h.value&&oe(e),N()),V.value&&N(),Y(e)}},resolveOptions:se}}function x(e){return function(e){if(Array.isArray(e))return B(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 B(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 B(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 B(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}var V={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},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}},setup(u,r){const i=function(l,n){var a=e(l),u=a.value,r=a.modelValue,i=a.mode;return{internalValue:t("single"!==i.value?[]:{}),externalValue:void 0!==n.expose?r:u}}(u,r),o=function(n,a,u){var r=e(n),i=r.searchable,o=r.id;return{multiselect:t(null),tabindex:l((function(){return i.value?-1:0})),blurInput:function(){document.getElementById(o.value).querySelector(".multiselect-input").blur()}}}(u),c={pointer:t(null)},s=function(n,a,u){var r=e(n),i=r.maxHeight,o=r.disabled,c=r.searchable,s=u.multiselect,d=t(!1),v=l((function(){return"".concat(i.value,"px")}));return{isOpen:d,contentMaxHeight:v,open:function(e){o.value||(d.value=!0,a.emit("open"))},close:function(){d.value=!1,a.emit("close")},handleInputMousedown:function(e){d.value&&!c.value&&(s.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),s.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(u,r,{multiselect:o.multiselect}),d=function(t,l,n){var a=e(t),u=a.object,r=a.valueProp,i=a.mode,o=n.internalValue,c=function(e){return u.value||O(e)?e:Array.isArray(e)?e.map((function(e){return e[r.value]})):e[r.value]},s=function(e){return O(e)?"single"===i.value?{}:[]:e};return{update:function(e){o.value=s(e);var t=c(e);l.emit("change",t),l.emit("input",t),l.emit("update:modelValue",t)}}}(u,r,{internalValue:i.internalValue}),v=function(a,u,r){var i=e(a),o=i.searchable,c=i.mode,s=r.internalValue,d=t(null),v=t(null),p=l((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=""},blurSearch:function(){o.value&&v.value.blur()}}}(u,r,{internalValue:i.internalValue}),p=q(u,r,{externalValue:i.externalValue,internalValue:i.internalValue,search:v.search,blurSearch:v.blurSearch,clearSearch:v.clearSearch,update:d.update,blurInput:o.blurInput,pointer:c.pointer}),f=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=l((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},y=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 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:b,selectPointer:function(){p.value&&!0!==p.value.disabled?(d(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(){y()}))},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(){y()}))}}}(u,0,{filteredOptions:p.filteredOptions,handleOptionClick:p.handleOptionClick,search:v.search,pointer:c.pointer}),h=function(t,l,n){var a=e(t).mode,u=n.internalValue,r=n.update,i=n.close,o=n.clearPointer,c=n.search;return{handleBackspace:function(e){"single"!==a.value&&r(x(u.value).slice(0,-1))},handleEsc:function(e){i(),o(),e.target.blur()},handleSearchBackspace:function(e){""!==c.value&&e.stopPropagation()}}}(u,0,{internalValue:i.internalValue,update:d.update,close:s.close,clearPointer:f.clearPointer,search:v.search});return{...i,...s,...o,...c,...d,...v,...p,...f,...h}}};const T={class:"multiselect-single-label"},j={class:"multiselect-multiple-label"},M={key:2,class:"multiselect-search"},A={key:3,class:"multiselect-tags"},E={class:"multiselect-tag"},C={class:"multiselect-spinner"},I={class:"multiselect-no-options"},N={class:"multiselect-no-results"};V.render=function(e,t,l,n,a,w){return u(),r("div",{class:["multiselect",[`is-${l.mode}`,{"is-open":e.isOpen,"is-searchable":l.searchable,"is-disabled":l.disabled,"no-caret":!l.caret}]],id:l.id,onKeydown:t[27]||(t[27]=i(o((()=>{}),["prevent"]),["enter"])),ref:"multiselect"},[c("div",{class:"multiselect-input",tabindex:e.tabindex,onMousedown:t[18]||(t[18]=(...t)=>e.handleInputMousedown&&e.handleInputMousedown(...t)),onFocus:t[19]||(t[19]=(...t)=>e.open&&e.open(...t)),onBlur:t[20]||(t[20]=(...t)=>e.close&&e.close(...t)),onKeyup:[t[21]||(t[21]=i(((...t)=>e.handleEsc&&e.handleEsc(...t)),["esc"])),t[22]||(t[22]=i(((...t)=>e.selectPointer&&e.selectPointer(...t)),["enter"]))],onKeydown:[t[23]||(t[23]=i(o(((...t)=>e.handleBackspace&&e.handleBackspace(...t)),["prevent"]),["delete"])),t[24]||(t[24]=i(o(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["prevent"]),["up"])),t[25]||(t[25]=i(o(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["prevent"]),["down"]))]},[s(" Single label "),"single"==l.mode&&e.hasSelected&&!e.search&&e.internalValue?d(e.$slots,"singlelabel",{key:0,value:e.internalValue},(()=>[c("div",T,v(e.internalValue[l.label]),1)])):s("v-if",!0),s(" Multiple label "),"multiple"==l.mode&&e.hasSelected&&!e.search?d(e.$slots,"multiplelabel",{key:1,values:e.internalValue},(()=>[c("div",j,v(e.multipleLabelText),1)])):s("v-if",!0),s(" Search "),"tags"!==l.mode&&l.searchable&&!l.disabled?(u(),r("div",M,[p(c("input",{"onUpdate:modelValue":t[1]||(t[1]=t=>e.search=t),onFocus:t[2]||(t[2]=o(((...t)=>e.open&&e.open(...t)),["stop"])),onBlur:t[3]||(t[3]=o(((...t)=>e.close&&e.close(...t)),["stop"])),onKeyup:[t[4]||(t[4]=i(o(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),t[5]||(t[5]=i(o(((...t)=>e.selectPointer&&e.selectPointer(...t)),["stop"]),["enter"]))],onKeydown:[t[6]||(t[6]=i(((...t)=>e.handleSearchBackspace&&e.handleSearchBackspace(...t)),["delete"])),t[7]||(t[7]=i(o(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["stop"]),["up"])),t[8]||(t[8]=i(o(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["stop"]),["down"]))],ref:"input"},null,544),[[f,e.search]])])):s("v-if",!0),s(" Tags (with search) "),"tags"==l.mode?(u(),r("div",A,[(u(!0),r(h,null,m(e.internalValue,((n,a,i)=>(u(),r("span",{key:i},[d(e.$slots,"tag",{option:n,remove:e.remove,disabled:l.disabled},(()=>[c("div",E,[b(v(n[l.label])+" ",1),l.disabled?s("v-if",!0):(u(),r("i",{key:0,onClick:t[9]||(t[9]=o((()=>{}),["prevent"])),onMousedown:o((t=>e.remove(n)),["prevent","stop"])},null,40,["onMousedown"]))])]))])))),128)),l.searchable&&!l.disabled?(u(),r("div",{key:0,class:"multiselect-search",style:{width:e.tagsSearchWidth}},[p(c("input",{"onUpdate:modelValue":t[10]||(t[10]=t=>e.search=t),onFocus:t[11]||(t[11]=o(((...t)=>e.open&&e.open(...t)),["stop"])),onBlur:t[12]||(t[12]=o(((...t)=>e.close&&e.close(...t)),["stop"])),onKeyup:[t[13]||(t[13]=i(o(((...t)=>e.handleEsc&&e.handleEsc(...t)),["stop"]),["esc"])),t[14]||(t[14]=i(o(((...t)=>e.selectPointer&&e.selectPointer(...t)),["stop"]),["enter"]))],onKeydown:[t[15]||(t[15]=i(((...t)=>e.handleSearchBackspace&&e.handleSearchBackspace(...t)),["delete"])),t[16]||(t[16]=i(o(((...t)=>e.backwardPointer&&e.backwardPointer(...t)),["stop"]),["up"])),t[17]||(t[17]=i(o(((...t)=>e.forwardPointer&&e.forwardPointer(...t)),["stop"]),["down"]))],style:{width:e.tagsSearchWidth},ref:"input"},null,36),[[f,e.search]])],4)):s("v-if",!0)])):s("v-if",!0),s(" Placeholder "),p(c("div",{class:"multiselect-placeholder"},v(l.placeholder),513),[[y,l.placeholder&&!e.hasSelected&&!e.search]]),c(g,{name:"multiselect-loading"},{default:S((()=>[p(c("div",C,null,512),[[y,e.busy]])])),_:1})],40,["tabindex"]),s(" Options "),c(g,{name:"multiselect",onAfterLeave:e.clearSearch},{default:S((()=>[p(c("div",{class:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[d(e.$slots,"beforelist"),(u(!0),r(h,null,m(e.filteredOptions,((n,a,i)=>(u(),r("a",{href:"",class:["multiselect-option",{"is-pointed":e.isPointed(n),"is-selected":e.isSelected(n),"is-disabled":e.isDisabled(n)}],key:i,onMousedown:t[26]||(t[26]=o((()=>{}),["prevent"])),onMouseenter:t=>e.setPointer(n),onClick:o((t=>e.handleOptionClick(n)),["stop","prevent"])},[d(e.$slots,"option",{option:n,search:e.search},(()=>[c("span",null,v(n[l.label]),1)]))],42,["onMouseenter","onClick"])))),128)),p(c("span",null,[d(e.$slots,"nooptions",{},(()=>[c("div",I,v(l.noOptionsText),1)]))],512),[[y,e.noOptions]]),p(c("span",null,[d(e.$slots,"noresults",{},(()=>[c("div",N,v(l.noResultsText),1)]))],512),[[y,e.noResults]]),d(e.$slots,"afterlist")],4),[[y,e.isOpen]])])),_:3},8,["onAfterLeave"])],42,["id"])},V.__file="src/Multiselect.vue";export default V; | ||
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,withDirectives as p,vModelText as f,Fragment as h,renderList as m,createTextVNode as b,Transition as y,withCtx as g,vShow as S}from"vue";function w(e){return-1!==[null,void 0,!1].indexOf(e)}function O(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 P(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,d=o.limit,v=o.hideSelected,p=o.createTag,f=o.label,h=o.appendNewTag,m=o.multipleLabel,b=o.object,y=o.loading,g=o.delay,S=o.resolveOnLoad,q=o.minChars,x=o.filterResults,V=o.clearOnSearch,B=o.clearOnSelect,T=o.valueProp,D=o.canDeselect,I=o.max,j=r.internalValue,M=r.externalValue,A=r.search,C=r.blurSearch,E=r.clearSearch,$=r.update,N=r.blurInput,H=r.pointer,L=l([]),R=l([]),K=l(!1),F=t((function(){var e,l=R.value||[];return e=l,"[object Object]"===Object.prototype.toString.call(e)&&(l=Object.keys(l).map((function(e){var t,n=l[e];return P(t={},T.value,e),P(t,s.value,n),P(t,f.value,n),t}))),l=l.map((function(e,l){var t;return"object"===k(e)?e:(P(t={},T.value,l),P(t,s.value,e),P(t,f.value,e),t)})),L.value.length&&(l=l.concat(L.value)),l})),_=t((function(){var e=F.value;return J.value.length&&(e=J.value.concat(e)),A.value&&x.value&&(e=e.filter((function(e){return-1!==O(e[s.value]).indexOf(O(A.value))}))),v.value&&(e=e.filter((function(e){return!ie(e)}))),d.value>0&&(e=e.slice(0,d.value)),e})),U=t((function(){switch(c.value){case"single":return!w(j.value[T.value]);case"multiple":case"tags":return!w(j.value)&&j.value.length>0}})),W=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&&A.value?-1!==oe(A.value)?[]:[(e={},P(e,T.value,A.value),P(e,f.value,A.value),P(e,s.value,A.value),e)]:[]})),Q=t((function(){switch(c.value){case"single":return null;case"multiple":case"tags":return[]}})),X=t((function(){return y.value||K.value})),Y=function(e){switch("object"!==k(e)&&(e=re(e)),c.value){case"single":$(e);break;case"multiple":case"tags":$(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":$(j.value.filter((function(l){return l[T.value]!=e[T.value]})))}u.emit("deselect",ee(e))},ee=function(e){return b.value?e:e[T.value]},le=function(e){Z(e)},te=function(){$(Q.value)},ne=function(e){switch(c.value){case"single":return!w(j.value)&&j.value[T.value]==e[T.value];case"tags":case"multiple":return!w(j.value)&&-1!==j.value.map((function(e){return e[T.value]})).indexOf(e[T.value])}},ae=function(e){return!0===e.disabled},ue=function(){return!(void 0===I||-1===I.value||!U.value&&I.value>0)&&j.value.length>=I.value},re=function(e){return F.value[F.value.map((function(e){return String(e[T.value])})).indexOf(String(e))]},oe=function(e){return F.value.map((function(e){return O(e[s.value])})).indexOf(O(e))},ie=function(e){return"tags"===c.value&&v.value&&ne(e)},ce=function(e){L.value.push(e)},se=function(){w(M.value)||(j.value=ve(M.value))},de=function(e){K.value=!0,i.value(A.value).then((function(l){R.value=l,"function"==typeof e&&e(l),K.value=!1}))},ve=function(e){return w(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&&!w(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?S.value?de(se):1==b.value&&se():(R.value=i&&i.value?i.value:[],se()),g.value>-1&&n(A,(function(e){e.length<q.value||(K.value=!0,V.value&&(R.value=[]),setTimeout((function(){e==A.value&&i.value(A.value).then((function(l){e==A.value&&(R.value=l,H.value=_.value.filter((function(e){return!0!==e.disabled}))[0]||null,K.value=!1)}))}),g.value))}),{flush:"sync"}),n(M,(function(e){var l,t,n;if(w(e))j.value=ve(e);else switch(c.value){case"single":(b.value?e[T.value]!=j.value[T.value]:e!=j.value[T.value])&&(j.value=ve(e));break;case"multiple":case"tags":l=b.value?e.map((function(e){return e[T.value]})):e,t=j.value.map((function(e){return e[T.value]})),n=t.slice().sort(),l.length===t.length&&l.slice().sort().every((function(e,l){return e===n[l]}))||(j.value=ve(e))}}),{deep:!0}),n((function(){return a.options}),(function(e){"function"!=typeof a.options&&(R.value=a.options)}),{flush:"sync"}),{filteredOptions:_,hasSelected:U,multipleLabelText:W,extendedOptions: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),C(),N();break;case"multiple":if(ne(e))return void Z(e);if(ue())return;Y(e),B.value&&E();break;case"tags":if(ne(e))return void Z(e);if(ue())return;void 0===re(e[T.value])&&p.value&&(u.emit("tag",e[T.value]),h.value&&ce(e),E()),B.value&&E(),Y(e)}},handleTagRemove:function(e,l){0===l.button?le(e):l.preventDefault()},refreshOptions:function(e){de(e)},resolveOptions:de}}function x(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 B={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},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}},setup(u,r){const o=function(t,n){var a=e(t),u=a.value,r=a.modelValue,o=a.mode;return{internalValue:l("single"!==o.value?[]:{}),externalValue:void 0!==n.expose?r:u}}(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||w(e)?e:Array.isArray(e)?e.map((function(e){return e[r.value]})):e[r.value]},s=function(e){return w(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=q(u,r,{externalValue:o.externalValue,internalValue:o.internalValue,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},b=function(){p.value=null},y=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:b,selectPointer:function(){p.value&&!0!==p.value.disabled?(d(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(){y()}))},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(){y()}))}}}(u,0,{filteredOptions:p.filteredOptions,handleOptionClick:p.handleOptionClick,search:d.search,pointer:c.pointer}),h=function(l,t,n){var a=e(l).mode,u=n.internalValue,r=n.update,o=n.closeDropdown,i=n.clearPointer,c=n.search;return{handleBackspace:function(e){"single"!==a.value&&r(x(u.value).slice(0,-1))},handleEsc:function(e){o(),i(),e.target.blur()},handleSearchBackspace:function(e){""!==c.value&&e.stopPropagation()}}}(u,0,{internalValue:o.internalValue,update:s.update,closeDropdown:v.closeDropdown,clearPointer:f.clearPointer,search:d.search});return{...o,...v,...i,...c,...s,...d,...p,...f,...h}}};const T={class:"multiselect-single-label"},D={class:"multiselect-multiple-label"},I={key:2,class:"multiselect-search"},j={key:3,class:"multiselect-tags"},M={class:"multiselect-tag"},A={class:"multiselect-placeholder"},C={class:"multiselect-spinner"},E={class:"multiselect-no-options"},$={class:"multiselect-no-results"};B.render=function(e,l,t,n,a,w){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[28]||(l[28]=o(i((()=>{}),["prevent"]),["enter"])),ref:"multiselect"},[c("div",{class:"multiselect-input",tabindex:e.tabindex,onMousedown:l[19]||(l[19]=(...l)=>e.handleInputMousedown&&e.handleInputMousedown(...l)),onFocus:l[20]||(l[20]=(...l)=>e.openDropdown&&e.openDropdown(...l)),onBlur:l[21]||(l[21]=(...l)=>e.closeDropdown&&e.closeDropdown(...l)),onKeyup:[l[22]||(l[22]=o(((...l)=>e.handleEsc&&e.handleEsc(...l)),["esc"])),l[23]||(l[23]=o(((...l)=>e.selectPointer&&e.selectPointer(...l)),["enter"]))],onKeydown:[l[24]||(l[24]=o(i(((...l)=>e.handleBackspace&&e.handleBackspace(...l)),["prevent"]),["delete"])),l[25]||(l[25]=o(i(((...l)=>e.backwardPointer&&e.backwardPointer(...l)),["prevent"]),["up"])),l[26]||(l[26]=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",T,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",D,v(e.multipleLabelText),1)])):s("v-if",!0),s(" Search "),"tags"!==t.mode&&t.searchable&&!t.disabled?(u(),r("div",I,[p(c("input",{"onUpdate:modelValue":l[1]||(l[1]=l=>e.search=l),onFocus:l[2]||(l[2]=i(((...l)=>e.openDropdown&&e.openDropdown(...l)),["stop"])),onBlur:l[3]||(l[3]=i(((...l)=>e.closeDropdown&&e.closeDropdown(...l)),["stop"])),onKeyup:[l[4]||(l[4]=o(i(((...l)=>e.handleEsc&&e.handleEsc(...l)),["stop"]),["esc"])),l[5]||(l[5]=o(i(((...l)=>e.selectPointer&&e.selectPointer(...l)),["stop"]),["enter"]))],onKeydown:[l[6]||(l[6]=o(((...l)=>e.handleSearchBackspace&&e.handleSearchBackspace(...l)),["delete"])),l[7]||(l[7]=o(i(((...l)=>e.backwardPointer&&e.backwardPointer(...l)),["stop"]),["up"])),l[8]||(l[8]=o(i(((...l)=>e.forwardPointer&&e.forwardPointer(...l)),["stop"]),["down"]))],ref:"input"},null,544),[[f,e.search]])])):s("v-if",!0),s(" Tags (with search) "),"tags"==t.mode?(u(),r("div",j,[(u(!0),r(h,null,m(e.internalValue,((n,a,o)=>(u(),r("span",{key:o},[d(e.$slots,"tag",{option:n,remove:e.remove,disabled:t.disabled},(()=>[c("div",M,[b(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}},[p(c("input",{"onUpdate:modelValue":l[10]||(l[10]=l=>e.search=l),onFocus:l[11]||(l[11]=i(((...l)=>e.openDropdown&&e.openDropdown(...l)),["stop"])),onBlur:l[12]||(l[12]=i(((...l)=>e.closeDropdown&&e.closeDropdown(...l)),["stop"])),onKeyup:[l[13]||(l[13]=o(i(((...l)=>e.handleEsc&&e.handleEsc(...l)),["stop"]),["esc"])),l[14]||(l[14]=o(i(((...l)=>e.selectPointer&&e.selectPointer(...l)),["stop"]),["enter"]))],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"]))],style:{width:e.tagsSearchWidth},ref:"input"},null,36),[[f,e.search]])],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",A,v(t.placeholder),1)])),c(y,{name:"multiselect-loading"},{default:g((()=>[p(c("div",C,null,512),[[S,e.busy]])])),_:1}),"single"!==t.mode&&e.hasSelected&&!t.disabled?(u(),r("a",{key:5,class:"multiselect-clear",onClick:l[18]||(l[18]=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(y,{key:0,name:"multiselect",onAfterLeave:e.clearSearch},{default:g((()=>[p(c("div",{class:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[d(e.$slots,"beforelist"),(u(!0),r(h,null,m(e.filteredOptions,((n,a,o)=>(u(),r("a",{tabindex:-1,href:"",class:["multiselect-option",{"is-pointed":e.isPointed(n),"is-selected":e.isSelected(n),"is-disabled":e.isDisabled(n)}],key:o,onMousedown:l[27]||(l[27]=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)),p(c("span",null,[d(e.$slots,"nooptions",{},(()=>[c("div",E,v(t.noOptionsText),1)]))],512),[[S,e.noOptions]]),p(c("span",null,[d(e.$slots,"noresults",{},(()=>[c("div",$,v(t.noResultsText),1)]))],512),[[S,e.noResults]]),d(e.$slots,"afterlist")],4),[[S,e.isOpen]])])),_:3},8,["onAfterLeave"]))],42,["id"])},B.__file="src/Multiselect.vue";export default B; |
@@ -1,1 +0,1 @@ | ||
var VueformMultiselect=function(e){"use strict";function t(e){return String(e).toLowerCase().trim()}function n(e){return-1!==[null,void 0,!1].indexOf(e)}function l(e){return(l="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 r(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 r(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 r(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 r(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 i(u,r,i){var o=e.toRefs(u),c=o.options,s=o.mode,d=o.trackBy,v=o.limit,p=o.hideSelected,f=o.createTag,m=o.label,h=o.appendNewTag,y=o.multipleLabel,g=o.object,b=o.loading,k=o.delay,_=o.resolveOnLoad,w=o.minChars,O=o.filterResults,S=o.clearOnSearch,x=o.clearOnSelect,C=o.valueProp,P=o.canDeselect,q=o.max,V=i.internalValue,T=i.externalValue,E=i.search,B=i.blurSearch,D=i.clearSearch,R=i.update,A=i.blurInput,N=i.pointer,j=e.ref([]),I=e.ref([]),H=e.ref(!1),U=e.computed((function(){var e,t=I.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={},C.value,e),a(n,d.value,l),a(n,m.value,l),n}))),t=t.map((function(e,t){var n;return"object"===l(e)?e:(a(n={},C.value,t),a(n,d.value,e),a(n,m.value,e),n)})),j.value.length&&(t=t.concat(j.value)),t})),M=e.computed((function(){var e=U.value;return X.value.length&&(e=X.value.concat(e)),E.value&&O.value&&(e=e.filter((function(e){return-1!==t(e[d.value]).indexOf(t(E.value))}))),p.value&&(e=e.filter((function(e){return!ae(e)}))),v.value>0&&(e=e.slice(0,v.value)),e})),$=e.computed((function(){switch(s.value){case"single":return!n(V.value[C.value]);case"multiple":case"tags":return!n(V.value)&&V.value.length>0}})),L=e.computed((function(){return void 0!==y&&void 0!==y.value?y.value(V.value):V.value&&V.value.length>1?"".concat(V.value.length," options selected"):"1 option selected"})),F=e.computed((function(){return!U.value.length})),W=e.computed((function(){return U.value.length>0&&0==M.value.length})),X=e.computed((function(){var e;return!1!==f.value&&E.value?-1!==le(E.value)?[]:[(e={},a(e,C.value,E.value),a(e,m.value,E.value),a(e,d.value,E.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"!==l(e)&&(e=ne(e)),s.value){case"single":R(e);break;case"multiple":case"tags":R(V.value.concat(e))}r.emit("select",Q(e))},K=function(e){switch("object"!==l(e)&&(e=ne(e)),s.value){case"single":Y();break;case"tags":case"multiple":R(V.value.filter((function(t){return t[C.value]!=e[C.value]})))}r.emit("deselect",Q(e))},Q=function(e){return g.value?e:e[C.value]},Y=function(){R(z.value)},Z=function(e){switch(s.value){case"single":return!n(V.value)&&V.value[C.value]==e[C.value];case"tags":case"multiple":return!n(V.value)&&-1!==V.value.map((function(e){return e[C.value]})).indexOf(e[C.value])}},ee=function(e){return!0===e.disabled},te=function(){return!(void 0===q||-1===q.value||!$.value&&q.value>0)&&V.value.length>=q.value},ne=function(e){return U.value[U.value.map((function(e){return String(e[C.value])})).indexOf(String(e))]},le=function(e){return U.value.map((function(e){return t(e[d.value])})).indexOf(t(e))},ae=function(e){return"tags"===s.value&&p.value&&Z(e)},ue=function(e){j.value.push(e)},re=function(){n(T.value)||(V.value=oe(T.value))},ie=function(e){H.value=!0,c.value(E.value).then((function(t){I.value=t,H.value=!1,"function"==typeof e&&e(t)}))},oe=function(e){return n(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&&!n(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(re):1==g.value&&re():(I.value=c&&c.value?c.value:[],re()),k.value>-1&&e.watch(E,(function(e){e.length<w.value||(S.value&&(I.value=[]),setTimeout((function(){e==E.value&&(H.value=!0,c.value(E.value).then((function(t){e==E.value&&(I.value=t,N.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 t,l,a;if(n(e))V.value=oe(e);else switch(s.value){case"single":(g.value?e[C.value]!=V.value[C.value]:e!=V.value[C.value])&&(V.value=oe(e));break;case"multiple":case"tags":t=g.value?e.map((function(e){return e[C.value]})):e,l=V.value.map((function(e){return e[C.value]})),a=l.slice().sort(),t.length===l.length&&t.slice().sort().every((function(e,t){return e===a[t]}))||(V.value=oe(e))}}),{deep:!0}),e.watch((function(){return u.options}),(function(e){"function"!=typeof u.options&&(I.value=u.options)})),{filteredOptions:M,hasSelected:$,multipleLabelText:L,extendedOptions:U,noOptions:F,noResults:W,busy:G,select:J,deselect:K,remove:function(e){K(e)},clear:Y,isSelected:Z,isDisabled:ee,isMax:te,getOption:ne,handleOptionClick:function(e){if(!ee(e))switch(s.value){case"single":if(Z(e))return void(P.value&&K(e));J(e),B(),A();break;case"multiple":if(Z(e))return void K(e);if(te())return;J(e),x.value&&D();break;case"tags":if(Z(e))return void K(e);if(te())return;void 0===ne(e[C.value])&&f.value&&(r.emit("tag",e[C.value]),h.value&&ue(e),D()),x.value&&D(),J(e)}},resolveOptions:ie}}function o(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 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},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}},setup(t,l){const a=function(t,n){var l=e.toRefs(t),a=l.value,u=l.modelValue,r=l.mode;return{internalValue:e.ref("single"!==r.value?[]:{}),externalValue:void 0!==n.expose?u:a}}(t,l),r=function(t,n,l){var a=e.toRefs(t),u=a.searchable,r=a.id;return{multiselect:e.ref(null),tabindex:e.computed((function(){return u.value?-1:0})),blurInput:function(){document.getElementById(r.value).querySelector(".multiselect-input").blur()}}}(t),o={pointer:e.ref(null)},c=function(t,n,l){var a=e.toRefs(t),u=a.maxHeight,r=a.disabled,i=a.searchable,o=l.multiselect,c=e.ref(!1),s=e.computed((function(){return"".concat(u.value,"px")}));return{isOpen:c,contentMaxHeight:s,open:function(e){r.value||(c.value=!0,n.emit("open"))},close:function(){c.value=!1,n.emit("close")},handleInputMousedown:function(e){c.value&&!i.value&&(o.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),o.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(t,l,{multiselect:r.multiselect}),s=function(t,l,a){var u=e.toRefs(t),r=u.object,i=u.valueProp,o=u.mode,c=a.internalValue,s=function(e){return r.value||n(e)?e:Array.isArray(e)?e.map((function(e){return e[i.value]})):e[i.value]},d=function(e){return n(e)?"single"===o.value?{}:[]:e};return{update:function(e){c.value=d(e);var t=s(e);l.emit("change",t),l.emit("input",t),l.emit("update:modelValue",t)}}}(t,l,{internalValue:a.internalValue}),d=function(t,n,l){var a=e.toRefs(t),u=a.searchable,r=a.mode,i=l.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=""},blurSearch:function(){u.value&&c.value.blur()}}}(t,l,{internalValue:a.internalValue}),v=i(t,l,{externalValue:a.externalValue,internalValue:a.internalValue,search:d.search,blurSearch:d.blurSearch,clearSearch:d.clearSearch,update:s.update,blurInput:r.blurInput,pointer:o.pointer}),p=function(t,n,l){var a=e.toRefs(t),u=a.id,r=a.valueProp,i=l.filteredOptions,o=l.handleOptionClick,c=l.search,s=l.pointer,d=e.computed((function(){return i.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},m=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:v,setPointerFirst:p,clearPointer:f,selectPointer:function(){s.value&&!0!==s.value.disabled?(o(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(){m()}))},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(){m()}))}}}(t,0,{filteredOptions:v.filteredOptions,handleOptionClick:v.handleOptionClick,search:d.search,pointer:o.pointer}),f=function(t,n,l){var a=e.toRefs(t).mode,r=l.internalValue,i=l.update,o=l.close,c=l.clearPointer,s=l.search;return{handleBackspace:function(e){"single"!==a.value&&i(u(r.value).slice(0,-1))},handleEsc:function(e){o(),c(),e.target.blur()},handleSearchBackspace:function(e){""!==s.value&&e.stopPropagation()}}}(t,0,{internalValue:a.internalValue,update:s.update,close:c.close,clearPointer:p.clearPointer,search:d.search});return{...a,...c,...r,...o,...s,...d,...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.open,blur:e.close,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",{directives:[{name:"model",rawName:"v-model",value:e.search,expression:"search"}],ref:"input",domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.open(t)},blur:function(t){return t.stopPropagation(),e.close(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:function(t){t.target.composing||(e.search=t.target.value)}}})])]: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.remove(t)}}})])],{option:t,remove:e.remove,disabled:e.disabled})],2)})),e._v(" "),e.searchable&&!e.disabled?n("div",{staticClass:"multiselect-search",style:{width:e.tagsSearchWidth}},[n("input",{directives:[{name:"model",rawName:"v-model",value:e.search,expression:"search"}],ref:"input",style:{width:e.tagsSearchWidth},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.open(t)},blur:function(t){return t.stopPropagation(),e.close(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:function(t){t.target.composing||(e.search=t.target.value)}}})]):e._e()],2)]:e._e(),e._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:e.placeholder&&!e.hasSelected&&!e.search,expression:"placeholder && !hasSelected && !search"}],staticClass:"multiselect-placeholder"},[e._v("\n "+e._s(e.placeholder)+"\n ")]),e._v(" "),n("transition",{attrs:{name:"multiselect-loading"}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.busy,expression:"busy"}],staticClass:"multiselect-spinner"})])],2),e._v(" "),n("transition",{attrs:{name:"multiselect"},on:{"after-leave":e.clearSearch}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.isOpen,expression:"isOpen"}],staticClass:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[e._t("beforelist"),e._v(" "),e._l(e.filteredOptions,(function(t,l,a){return n("a",{key:a,staticClass:"multiselect-option",class:{"is-pointed":e.isPointed(t),"is-selected":e.isSelected(t),"is-disabled":e.isDisabled(t)},attrs:{href:""},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)])],1)};s._withStripped=!0;return o({render:s,staticRenderFns:[]},undefined,c,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 l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(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,l=new Array(t);n<t;n++)l[n]=e[n];return l}function r(e){return String(e).toLowerCase().trim()}function o(a,u,o){var i=e.toRefs(a),c=i.options,s=i.mode,d=i.trackBy,p=i.limit,v=i.hideSelected,f=i.createTag,h=i.label,m=i.appendNewTag,y=i.multipleLabel,g=i.object,b=i.loading,k=i.delay,w=i.resolveOnLoad,_=i.minChars,S=i.filterResults,O=i.clearOnSearch,x=i.clearOnSelect,C=i.valueProp,P=i.canDeselect,D=i.max,q=o.internalValue,V=o.externalValue,T=o.search,E=o.blurSearch,B=o.clearSearch,R=o.update,A=o.blurInput,I=o.pointer,N=e.ref([]),j=e.ref([]),H=e.ref(!1),U=e.computed((function(){var e,t=j.value||[];return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(t=Object.keys(t).map((function(e){var n,a=t[e];return l(n={},C.value,e),l(n,d.value,a),l(n,h.value,a),n}))),t=t.map((function(e,t){var a;return"object"===n(e)?e:(l(a={},C.value,t),l(a,d.value,e),l(a,h.value,e),a)})),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)),T.value&&S.value&&(e=e.filter((function(e){return-1!==r(e[d.value]).indexOf(r(T.value))}))),v.value&&(e=e.filter((function(e){return!ue(e)}))),p.value>0&&(e=e.slice(0,p.value)),e})),$=e.computed((function(){switch(s.value){case"single":return!t(q.value[C.value]);case"multiple":case"tags":return!t(q.value)&&q.value.length>0}})),L=e.computed((function(){return void 0!==y&&void 0!==y.value?y.value(q.value):q.value&&q.value.length>1?"".concat(q.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&&T.value?-1!==ae(T.value)?[]:[(e={},l(e,C.value,T.value),l(e,h.value,T.value),l(e,d.value,T.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=le(e)),s.value){case"single":R(e);break;case"multiple":case"tags":R(q.value.concat(e))}u.emit("select",Q(e))},K=function(e){switch("object"!==n(e)&&(e=le(e)),s.value){case"single":Z();break;case"tags":case"multiple":R(q.value.filter((function(t){return t[C.value]!=e[C.value]})))}u.emit("deselect",Q(e))},Q=function(e){return g.value?e:e[C.value]},Y=function(e){K(e)},Z=function(){R(z.value)},ee=function(e){switch(s.value){case"single":return!t(q.value)&&q.value[C.value]==e[C.value];case"tags":case"multiple":return!t(q.value)&&-1!==q.value.map((function(e){return e[C.value]})).indexOf(e[C.value])}},te=function(e){return!0===e.disabled},ne=function(){return!(void 0===D||-1===D.value||!$.value&&D.value>0)&&q.value.length>=D.value},le=function(e){return U.value[U.value.map((function(e){return String(e[C.value])})).indexOf(String(e))]},ae=function(e){return U.value.map((function(e){return r(e[d.value])})).indexOf(r(e))},ue=function(e){return"tags"===s.value&&v.value&&ee(e)},re=function(e){N.value.push(e)},oe=function(){t(V.value)||(q.value=ce(V.value))},ie=function(e){H.value=!0,c.value(T.value).then((function(t){j.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?le(e)||{}:e.filter((function(e){return!!le(e)})).map((function(e){return le(e)}))};if("single"!==s.value&&!t(V.value)&&!Array.isArray(V.value))throw new Error('v-model must be an array when using "'.concat(s.value,'" mode'));return c&&"function"==typeof c.value?w.value?ie(oe):1==g.value&&oe():(j.value=c&&c.value?c.value:[],oe()),k.value>-1&&e.watch(T,(function(e){e.length<_.value||(H.value=!0,O.value&&(j.value=[]),setTimeout((function(){e==T.value&&c.value(T.value).then((function(t){e==T.value&&(j.value=t,I.value=M.value.filter((function(e){return!0!==e.disabled}))[0]||null,H.value=!1)}))}),k.value))}),{flush:"sync"}),e.watch(V,(function(e){var n,l,a;if(t(e))q.value=ce(e);else switch(s.value){case"single":(g.value?e[C.value]!=q.value[C.value]:e!=q.value[C.value])&&(q.value=ce(e));break;case"multiple":case"tags":n=g.value?e.map((function(e){return e[C.value]})):e,l=q.value.map((function(e){return e[C.value]})),a=l.slice().sort(),n.length===l.length&&n.slice().sort().every((function(e,t){return e===a[t]}))||(q.value=ce(e))}}),{deep:!0}),e.watch((function(){return a.options}),(function(e){"function"!=typeof a.options&&(j.value=a.options)}),{flush:"sync"}),{filteredOptions:M,hasSelected:$,multipleLabelText:L,extendedOptions:U,noOptions:F,noResults:W,resolving:H,busy:G,select:J,deselect:K,remove:Y,clear:Z,isSelected:ee,isDisabled:te,isMax:ne,getOption:le,handleOptionClick:function(e){if(!te(e))switch(s.value){case"single":if(ee(e))return void(P.value&&K(e));J(e),E(),A();break;case"multiple":if(ee(e))return void K(e);if(ne())return;J(e),x.value&&B();break;case"tags":if(ee(e))return void K(e);if(ne())return;void 0===le(e[C.value])&&f.value&&(u.emit("tag",e[C.value]),m.value&&re(e),B()),x.value&&B(),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,l,a,u,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,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,i(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,o(e))}),s)if(d.functional){var p=d.render;d.render=function(e,t){return s.call(t),p(e,t)}}else{var v=d.beforeCreate;d.beforeCreate=v?[].concat(v,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},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}},setup(n,l){const u=function(t,n){var l=e.toRefs(t),a=l.value,u=l.modelValue,r=l.mode;return{internalValue:e.ref("single"!==r.value?[]:{}),externalValue:void 0!==n.expose?u:a}}(n,l),r=function(t,n,l){var a=e.toRefs(t),u=a.searchable,r=(a.id,e.ref(null)),o=e.computed((function(){return u.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,l,a){var u=e.toRefs(n),r=u.object,o=u.valueProp,i=u.mode,c=a.internalValue,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);l.emit("change",t),l.emit("input",t),l.emit("update:modelValue",t)}}}(n,l,{internalValue:u.internalValue}),s=function(t,n,l){var a=e.toRefs(t),u=a.searchable,r=a.mode,o=l.internalValue,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(){u.value&&c.value.blur()}}}(n,l,{internalValue:u.internalValue}),d=function(t,n,l){var a=e.toRefs(t),u=a.maxHeight,r=a.disabled,o=a.searchable,i=l.multiselect,c=l.blurInput,s=l.blurSearch,d=l.focusInput,p=l.focusSearch,v=e.ref(!1),f=e.computed((function(){return"".concat(u.value,"px")}));return{isOpen:v,contentMaxHeight:f,openDropdown:function(){r.value||(v.value=!0,n.emit("open"))},closeDropdown:function(){v.value=!1,n.emit("close")},open:function(){o&&o.value?p():d()},close:function(){o&&o.value?s():c()},handleInputMousedown:function(e){v.value&&!o.value&&(i.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),i.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(n,l,{multiselect:r.multiselect,blurInput:r.blurInput,blurSearch:s.blurSearch,focusInput:r.focusInput,focusSearch:s.focusSearch}),p=o(n,l,{externalValue:u.externalValue,internalValue:u.internalValue,search:s.search,blurSearch:s.blurSearch,clearSearch:s.clearSearch,update:c.update,blurInput:r.blurInput,pointer:i.pointer}),v=function(t,n,l){var a=e.toRefs(t),u=a.id,r=a.valueProp,o=l.filteredOptions,i=l.handleOptionClick,c=l.search,s=l.pointer,d=e.computed((function(){return o.value.filter((function(e){return!0!==e.disabled}))})),p=function(e){s.value=e},v=function(){s.value=d.value[0]||null},f=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){v()})),{pointer:s,isPointed:function(e){return!!s.value&&s.value[r.value]==e[r.value]},setPointer:p,setPointerFirst:v,clearPointer:f,selectPointer:function(){s.value&&!0!==s.value.disabled?(i(s.value),f()):f()},forwardPointer:function(){if(null===s.value)p(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),p(d.value[t]||null)}e.nextTick((function(){h()}))},backwardPointer:function(){if(null===s.value)p(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),p(d.value[t]||null)}e.nextTick((function(){h()}))}}}(n,0,{filteredOptions:p.filteredOptions,handleOptionClick:p.handleOptionClick,search:s.search,pointer:i.pointer}),f=function(t,n,l){var u=e.toRefs(t).mode,r=l.internalValue,o=l.update,i=l.closeDropdown,c=l.clearPointer,s=l.search;return{handleBackspace:function(e){"single"!==u.value&&o(a(r.value).slice(0,-1))},handleEsc:function(e){i(),c(),e.target.blur()},handleSearchBackspace:function(e){""!==s.value&&e.stopPropagation()}}}(n,0,{internalValue:u.internalValue,update:c.update,closeDropdown:d.closeDropdown,clearPointer:v.clearPointer,search:s.search});return{...u,...d,...r,...i,...c,...s,...p,...v,...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.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",{directives:[{name:"model",rawName:"v-model",value:e.search,expression:"search"}],ref:"input",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:function(t){t.target.composing||(e.search=t.target.value)}}})])]: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,remove:e.remove,disabled:e.disabled})],2)})),e._v(" "),e.searchable&&!e.disabled?n("div",{staticClass:"multiselect-search",style:{width:e.tagsSearchWidth}},[n("input",{directives:[{name:"model",rawName:"v-model",value:e.search,expression:"search"}],ref:"input",style:{width:e.tagsSearchWidth},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:function(t){t.target.composing||(e.search=t.target.value)}}})]):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(" "),n("transition",{attrs:{name:"multiselect-loading"}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.busy,expression:"busy"}],staticClass:"multiselect-spinner"})]),e._v(" "),"single"!==e.mode&&e.hasSelected&&!e.disabled?n("a",{staticClass:"multiselect-clear",on:{click:function(t){return t.preventDefault(),e.clear(t)}}}):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,expression:"isOpen"}],staticClass:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[e._t("beforelist"),e._v(" "),e._l(e.filteredOptions,(function(t,l,a){return n("a",{key:a,staticClass:"multiselect-option",class:{"is-pointed":e.isPointed(t),"is-selected":e.isSelected(t),"is-disabled":e.isDisabled(t)},attrs:{tabindex:-1,href:""},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)])],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 String(e).toLowerCase().trim()}function r(e){return-1!==[null,void 0,!1].indexOf(e)}function i(e){return(i="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,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,c){var d=e(a),v=d.options,p=d.mode,f=d.trackBy,h=d.limit,m=d.hideSelected,y=d.createTag,g=d.label,b=d.appendNewTag,k=d.multipleLabel,_=d.object,w=d.loading,O=d.delay,S=d.resolveOnLoad,x=d.minChars,C=d.filterResults,P=d.clearOnSearch,q=d.clearOnSelect,V=d.valueProp,E=d.canDeselect,B=d.max,D=c.internalValue,T=c.externalValue,N=c.search,A=c.blurSearch,j=c.clearSearch,R=c.update,I=c.blurInput,H=c.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,l=t[e];return o(n={},V.value,e),o(n,f.value,l),o(n,g.value,l),n}))),t=t.map((function(e,t){var n;return"object"===i(e)?e:(o(n={},V.value,t),o(n,f.value,e),o(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)),N.value&&C.value&&(e=e.filter((function(e){return-1!==u(e[f.value]).indexOf(u(N.value))}))),m.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!r(D.value[V.value]);case"multiple":case"tags":return!r(D.value)&&D.value.length>0}})),X=n((function(){return void 0!==k&&void 0!==k.value?k.value(D.value):D.value&&D.value.length>1?"".concat(D.value.length," options selected"):"1 option selected"})),z=n((function(){return!M.value.length})),G=n((function(){return M.value.length>0&&0==F.value.length})),J=n((function(){var e;return!1!==y.value&&N.value?-1!==re(N.value)?[]:[(e={},o(e,V.value,N.value),o(e,g.value,N.value),o(e,f.value,N.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"!==i(e)&&(e=ue(e)),p.value){case"single":R(e);break;case"multiple":case"tags":R(D.value.concat(e))}s.emit("select",ee(e))},Z=function(e){switch("object"!==i(e)&&(e=ue(e)),p.value){case"single":te();break;case"tags":case"multiple":R(D.value.filter((function(t){return t[V.value]!=e[V.value]})))}s.emit("deselect",ee(e))},ee=function(e){return _.value?e:e[V.value]},te=function(){R(K.value)},ne=function(e){switch(p.value){case"single":return!r(D.value)&&D.value[V.value]==e[V.value];case"tags":case"multiple":return!r(D.value)&&-1!==D.value.map((function(e){return e[V.value]})).indexOf(e[V.value])}},le=function(e){return!0===e.disabled},ae=function(){return!(void 0===B||-1===B.value||!W.value&&B.value>0)&&D.value.length>=B.value},ue=function(e){return M.value[M.value.map((function(e){return String(e[V.value])})).indexOf(String(e))]},re=function(e){return M.value.map((function(e){return u(e[f.value])})).indexOf(u(e))},ie=function(e){return"tags"===p.value&&m.value&&ne(e)},oe=function(e){U.value.push(e)},se=function(){r(T.value)||(D.value=de(T.value))},ce=function(e){L.value=!0,v.value(N.value).then((function(t){$.value=t,L.value=!1,"function"==typeof e&&e(t)}))},de=function(e){return r(e)?"single"===p.value?{}:[]:_.value?e:"single"===p.value?ue(e)||{}:e.filter((function(e){return!!ue(e)})).map((function(e){return ue(e)}))};if("single"!==p.value&&!r(T.value)&&!Array.isArray(T.value))throw new Error('v-model must be an array when using "'.concat(p.value,'" mode'));return v&&"function"==typeof v.value?S.value?ce(se):1==_.value&&se():($.value=v&&v.value?v.value:[],se()),O.value>-1&&l(N,(function(e){e.length<x.value||(P.value&&($.value=[]),setTimeout((function(){e==N.value&&(L.value=!0,v.value(N.value).then((function(t){e==N.value&&($.value=t,H.value=F.value.filter((function(e){return!0!==e.disabled}))[0]||null),L.value=!1})))}),O.value))}),{flush:"sync"}),l(T,(function(e){var t,n,l;if(r(e))D.value=de(e);else switch(p.value){case"single":(_.value?e[V.value]!=D.value[V.value]:e!=D.value[V.value])&&(D.value=de(e));break;case"multiple":case"tags":t=_.value?e.map((function(e){return e[V.value]})):e,n=D.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]}))||(D.value=de(e))}}),{deep:!0}),l((function(){return a.options}),(function(e){"function"!=typeof a.options&&($.value=a.options)})),{filteredOptions:F,hasSelected:W,multipleLabelText:X,extendedOptions:M,noOptions:z,noResults:G,busy:Q,select:Y,deselect:Z,remove:function(e){Z(e)},clear:te,isSelected:ne,isDisabled:le,isMax:ae,getOption:ue,handleOptionClick:function(e){if(!le(e))switch(p.value){case"single":if(ne(e))return void(E.value&&Z(e));Y(e),A(),I();break;case"multiple":if(ne(e))return void Z(e);if(ae())return;Y(e),q.value&&j();break;case"tags":if(ne(e))return void Z(e);if(ae())return;void 0===ue(e[V.value])&&y.value&&(s.emit("tag",e[V.value]),b.value&&oe(e),j()),q.value&&j(),Y(e)}},resolveOptions:ce}}function c(e){return function(e){if(Array.isArray(e))return d(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 d(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 d(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 d(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 v(e,t,n,l,a,u,r,i,o,s){"boolean"!=typeof r&&(o=i,i=r,r=!1);var c,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?(c=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=c):t&&(c=r?function(e){t.call(this,s(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,i(e))}),c)if(d.functional){var v=d.render;d.render=function(e,t){return c.call(t),v(e,t)}}else{var p=d.beforeCreate;d.beforeCreate=p?[].concat(p,c):[c]}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},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}},setup(u,i){const o=function(n,l){var a=e(n),u=a.value,r=a.modelValue,i=a.mode;return{internalValue:t("single"!==i.value?[]:{}),externalValue:void 0!==l.expose?r:u}}(u,i),d=function(l,a,u){var r=e(l),i=r.searchable,o=r.id;return{multiselect:t(null),tabindex:n((function(){return i.value?-1:0})),blurInput:function(){document.getElementById(o.value).querySelector(".multiselect-input").blur()}}}(u),v={pointer:t(null)},p=function(l,a,u){var r=e(l),i=r.maxHeight,o=r.disabled,s=r.searchable,c=u.multiselect,d=t(!1),v=n((function(){return"".concat(i.value,"px")}));return{isOpen:d,contentMaxHeight:v,open:function(e){o.value||(d.value=!0,a.emit("open"))},close:function(){d.value=!1,a.emit("close")},handleInputMousedown:function(e){d.value&&!s.value&&(c.value.querySelector(".multiselect-input").dispatchEvent(new Event("blur")),c.value.querySelector(".multiselect-input").blur(),e.preventDefault())}}}(u,i,{multiselect:d.multiselect}),f=function(t,n,l){var a=e(t),u=a.object,i=a.valueProp,o=a.mode,s=l.internalValue,c=function(e){return u.value||r(e)?e:Array.isArray(e)?e.map((function(e){return e[i.value]})):e[i.value]},d=function(e){return r(e)?"single"===o.value?{}:[]:e};return{update:function(e){s.value=d(e);var t=c(e);n.emit("change",t),n.emit("input",t),n.emit("update:modelValue",t)}}}(u,i,{internalValue:o.internalValue}),h=function(a,u,r){var i=e(a),o=i.searchable,s=i.mode,c=r.internalValue,d=t(null),v=t(null),p=n((function(){return d.value?"".concat(d.value.length,"ch"):"tags"===s.value&&-1===[null,void 0].indexOf(c.value)&&c.value.length?"1ch":"100%"}));return l(d,(function(e){u.emit("search-change",e)})),{search:d,input:v,tagsSearchWidth:p,clearSearch:function(){d.value=""},blurSearch:function(){o.value&&v.value.blur()}}}(u,i,{internalValue:o.internalValue}),m=s(u,i,{externalValue:o.externalValue,internalValue:o.internalValue,search:h.search,blurSearch:h.blurSearch,clearSearch:h.clearSearch,update:f.update,blurInput:d.blurInput,pointer:v.pointer}),y=function(t,u,r){var i=e(t),o=i.id,s=i.valueProp,c=r.filteredOptions,d=r.handleOptionClick,v=r.search,p=r.pointer,f=n((function(){return c.value.filter((function(e){return!0!==e.disabled}))})),h=function(e){p.value=e},m=function(){p.value=f.value[0]||null},y=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){m()})),{pointer:p,isPointed:function(e){return!!p.value&&p.value[s.value]==e[s.value]},setPointer:h,setPointerFirst:m,clearPointer:y,selectPointer:function(){p.value&&!0!==p.value.disabled?(d(p.value),y()):y()},forwardPointer:function(){if(null===p.value)h(f.value[0]||null);else{var e=f.value.map((function(e){return e[s.value]})).indexOf(p.value[s.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[s.value]})).indexOf(p.value[s.value])-1;e<0&&(e=f.value.length-1),h(f.value[e]||null)}a((function(){g()}))}}}(u,0,{filteredOptions:m.filteredOptions,handleOptionClick:m.handleOptionClick,search:h.search,pointer:v.pointer}),g=function(t,n,l){var a=e(t).mode,u=l.internalValue,r=l.update,i=l.close,o=l.clearPointer,s=l.search;return{handleBackspace:function(e){"single"!==a.value&&r(c(u.value).slice(0,-1))},handleEsc:function(e){i(),o(),e.target.blur()},handleSearchBackspace:function(e){""!==s.value&&e.stopPropagation()}}}(u,0,{internalValue:o.internalValue,update:f.update,close:p.close,clearPointer:y.clearPointer,search:h.search});return{...o,...p,...d,...v,...f,...h,...m,...y,...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.open,blur:e.close,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",{directives:[{name:"model",rawName:"v-model",value:e.search,expression:"search"}],ref:"input",domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.open(t)},blur:function(t){return t.stopPropagation(),e.close(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:function(t){t.target.composing||(e.search=t.target.value)}}})])]: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.remove(t)}}})])],{option:t,remove:e.remove,disabled:e.disabled})],2)})),e._v(" "),e.searchable&&!e.disabled?n("div",{staticClass:"multiselect-search",style:{width:e.tagsSearchWidth}},[n("input",{directives:[{name:"model",rawName:"v-model",value:e.search,expression:"search"}],ref:"input",style:{width:e.tagsSearchWidth},domProps:{value:e.search},on:{focus:function(t){return t.stopPropagation(),e.open(t)},blur:function(t){return t.stopPropagation(),e.close(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:function(t){t.target.composing||(e.search=t.target.value)}}})]):e._e()],2)]:e._e(),e._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:e.placeholder&&!e.hasSelected&&!e.search,expression:"placeholder && !hasSelected && !search"}],staticClass:"multiselect-placeholder"},[e._v("\n "+e._s(e.placeholder)+"\n ")]),e._v(" "),n("transition",{attrs:{name:"multiselect-loading"}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.busy,expression:"busy"}],staticClass:"multiselect-spinner"})])],2),e._v(" "),n("transition",{attrs:{name:"multiselect"},on:{"after-leave":e.clearSearch}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.isOpen,expression:"isOpen"}],staticClass:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[e._t("beforelist"),e._v(" "),e._l(e.filteredOptions,(function(t,l,a){return n("a",{key:a,staticClass:"multiselect-option",class:{"is-pointed":e.isPointed(t),"is-selected":e.isSelected(t),"is-disabled":e.isDisabled(t)},attrs:{href:""},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)])],1)};f._withStripped=!0;const h=v({render:f,staticRenderFns:[]},undefined,p,undefined,false,undefined,!1,void 0,void 0,void 0);export default h; | ||
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()}function i(e){return(i="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,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(a,c,s){var d=e(a),v=d.options,p=d.mode,f=d.trackBy,h=d.limit,y=d.hideSelected,m=d.createTag,g=d.label,b=d.appendNewTag,k=d.multipleLabel,_=d.object,w=d.loading,S=d.delay,O=d.resolveOnLoad,x=d.minChars,C=d.filterResults,P=d.clearOnSearch,D=d.clearOnSelect,q=d.valueProp,V=d.canDeselect,T=d.max,E=s.internalValue,B=s.externalValue,A=s.search,I=s.blurSearch,N=s.clearSearch,j=s.update,R=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,l=t[e];return o(n={},q.value,e),o(n,f.value,l),o(n,g.value,l),n}))),t=t.map((function(e,t){var n;return"object"===i(e)?e:(o(n={},q.value,t),o(n,f.value,e),o(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)),A.value&&C.value&&(e=e.filter((function(e){return-1!==r(e[f.value]).indexOf(r(A.value))}))),y.value&&(e=e.filter((function(e){return!oe(e)}))),h.value>0&&(e=e.slice(0,h.value)),e})),W=n((function(){switch(p.value){case"single":return!u(E.value[q.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&&A.value?-1!==ie(A.value)?[]:[(e={},o(e,q.value,A.value),o(e,g.value,A.value),o(e,f.value,A.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"!==i(e)&&(e=re(e)),p.value){case"single":j(e);break;case"multiple":case"tags":j(E.value.concat(e))}c.emit("select",ee(e))},Z=function(e){switch("object"!==i(e)&&(e=re(e)),p.value){case"single":ne();break;case"tags":case"multiple":j(E.value.filter((function(t){return t[q.value]!=e[q.value]})))}c.emit("deselect",ee(e))},ee=function(e){return _.value?e:e[q.value]},te=function(e){Z(e)},ne=function(){j(K.value)},le=function(e){switch(p.value){case"single":return!u(E.value)&&E.value[q.value]==e[q.value];case"tags":case"multiple":return!u(E.value)&&-1!==E.value.map((function(e){return e[q.value]})).indexOf(e[q.value])}},ae=function(e){return!0===e.disabled},ue=function(){return!(void 0===T||-1===T.value||!W.value&&T.value>0)&&E.value.length>=T.value},re=function(e){return M.value[M.value.map((function(e){return String(e[q.value])})).indexOf(String(e))]},ie=function(e){return M.value.map((function(e){return r(e[f.value])})).indexOf(r(e))},oe=function(e){return"tags"===p.value&&y.value&&le(e)},ce=function(e){U.value.push(e)},se=function(){u(B.value)||(E.value=ve(B.value))},de=function(e){L.value=!0,v.value(A.value).then((function(t){$.value=t,"function"==typeof e&&e(t),L.value=!1}))},ve=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(B.value)&&!Array.isArray(B.value))throw new Error('v-model must be an array when using "'.concat(p.value,'" mode'));return v&&"function"==typeof v.value?O.value?de(se):1==_.value&&se():($.value=v&&v.value?v.value:[],se()),S.value>-1&&l(A,(function(e){e.length<x.value||(L.value=!0,P.value&&($.value=[]),setTimeout((function(){e==A.value&&v.value(A.value).then((function(t){e==A.value&&($.value=t,H.value=F.value.filter((function(e){return!0!==e.disabled}))[0]||null,L.value=!1)}))}),S.value))}),{flush:"sync"}),l(B,(function(e){var t,n,l;if(u(e))E.value=ve(e);else switch(p.value){case"single":(_.value?e[q.value]!=E.value[q.value]:e!=E.value[q.value])&&(E.value=ve(e));break;case"multiple":case"tags":t=_.value?e.map((function(e){return e[q.value]})):e,n=E.value.map((function(e){return e[q.value]})),l=n.slice().sort(),t.length===n.length&&t.slice().sort().every((function(e,t){return e===l[t]}))||(E.value=ve(e))}}),{deep:!0}),l((function(){return a.options}),(function(e){"function"!=typeof a.options&&($.value=a.options)}),{flush:"sync"}),{filteredOptions:F,hasSelected:W,multipleLabelText:X,extendedOptions:M,noOptions:z,noResults:G,resolving:L,busy:Q,select:Y,deselect:Z,remove:te,clear:ne,isSelected:le,isDisabled:ae,isMax:ue,getOption:re,handleOptionClick:function(e){if(!ae(e))switch(p.value){case"single":if(le(e))return void(V.value&&Z(e));Y(e),I(),R();break;case"multiple":if(le(e))return void Z(e);if(ue())return;Y(e),D.value&&N();break;case"tags":if(le(e))return void Z(e);if(ue())return;void 0===re(e[q.value])&&m.value&&(c.emit("tag",e[q.value]),b.value&&ce(e),N()),D.value&&N(),Y(e)}},handleTagRemove:function(e,t){0===t.button?te(e):t.preventDefault()},refreshOptions:function(e){de(e)},resolveOptions:de}}function s(e){return function(e){if(Array.isArray(e))return d(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 d(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 d(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 d(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 v(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 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},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}},setup(r,i){const o=function(n,l){var a=e(n),u=a.value,r=a.modelValue,i=a.mode;return{internalValue:t("single"!==i.value?[]:{}),externalValue:void 0!==l.expose?r:u}}(r,i),d=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:d.multiselect,blurInput:d.blurInput,blurSearch:f.blurSearch,focusInput:d.focusInput,focusSearch:f.focusSearch}),y=c(r,i,{externalValue:o.externalValue,internalValue:o.internalValue,search:f.search,blurSearch:f.blurSearch,clearSearch:f.clearSearch,update:p.update,blurInput:d.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 a=e(t).mode,u=l.internalValue,r=l.update,i=l.closeDropdown,o=l.clearPointer,c=l.search;return{handleBackspace:function(e){"single"!==a.value&&r(s(u.value).slice(0,-1))},handleEsc:function(e){i(),o(),e.target.blur()},handleSearchBackspace:function(e){""!==c.value&&e.stopPropagation()}}}(r,0,{internalValue:o.internalValue,update:p.update,closeDropdown:h.closeDropdown,clearPointer:m.clearPointer,search:f.search});return{...o,...h,...d,...v,...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.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",{directives:[{name:"model",rawName:"v-model",value:e.search,expression:"search"}],ref:"input",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:function(t){t.target.composing||(e.search=t.target.value)}}})])]: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,remove:e.remove,disabled:e.disabled})],2)})),e._v(" "),e.searchable&&!e.disabled?n("div",{staticClass:"multiselect-search",style:{width:e.tagsSearchWidth}},[n("input",{directives:[{name:"model",rawName:"v-model",value:e.search,expression:"search"}],ref:"input",style:{width:e.tagsSearchWidth},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:function(t){t.target.composing||(e.search=t.target.value)}}})]):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(" "),n("transition",{attrs:{name:"multiselect-loading"}},[n("div",{directives:[{name:"show",rawName:"v-show",value:e.busy,expression:"busy"}],staticClass:"multiselect-spinner"})]),e._v(" "),"single"!==e.mode&&e.hasSelected&&!e.disabled?n("a",{staticClass:"multiselect-clear",on:{click:function(t){return t.preventDefault(),e.clear(t)}}}):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,expression:"isOpen"}],staticClass:"multiselect-options",style:{maxHeight:e.contentMaxHeight}},[e._t("beforelist"),e._v(" "),e._l(e.filteredOptions,(function(t,l,a){return n("a",{key:a,staticClass:"multiselect-option",class:{"is-pointed":e.isPointed(t),"is-selected":e.isSelected(t),"is-disabled":e.isDisabled(t)},attrs:{tabindex:-1,href:""},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)])],1)};f._withStripped=!0;const h=v({render:f,staticRenderFns:[]},undefined,p,undefined,false,undefined,!1,void 0,void 0,void 0);export default h; |
{ | ||
"name": "@vueform/multiselect", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"private": false, | ||
@@ -9,2 +9,3 @@ "description": "Vue 3 multiselect component with single select, multiselect and tagging options.", | ||
"main": "./dist/multiselect.js", | ||
"types": "./src/index.d.ts", | ||
"module": "./dist/multiselect.js", | ||
@@ -11,0 +12,0 @@ "unpkg": "./dist/multiselect.global.js", |
@@ -57,4 +57,5 @@ <div align="center"> | ||
* No dependencies | ||
* Lightweight (~5 kB gzipped) | ||
* Lightweight (<6 kB gzipped) | ||
* 100% coverage | ||
* TypeScript support | ||
* ESM support | ||
@@ -72,3 +73,3 @@ * Single select options | ||
Check out our <a href="https://jsfiddle.net/5qsugfxt/" target="_blank">demo</a>. | ||
Check out our <a href="https://jsfiddle.net/armbfy51/" target="_blank">demo</a>. | ||
@@ -141,3 +142,3 @@ ## Installation | ||
| **disabled** | `boolean` | `false` | Whether the input should be disabled for the user (API can still be used programmatically). | | ||
| **max** | `number` | `-1` | The maximum number of options that **can be be selected** when using `multiple` or `tags` mode. If `-1` the number of options won't be limited. | | ||
| **max** | `number` | `-1` | The maximum number of options that **can be selected** when using `multiple` or `tags` mode. If `-1` the number of options won't be limited. | | ||
| **limit** | `number` | `-1` | The maximum number of options that **should be displayed**. If `-1` the number of options won't be limited. | | ||
@@ -167,2 +168,32 @@ | **loading** | `boolean` | `false` | Whether a loading spinner should be shown. | | ||
## API | ||
| Name | Params | Description | | ||
| --- | --- | --- | --- | | ||
| **open** | | Opens the options list and focuses the multiselect. | | ||
| **close** | | Closes the options list and blurs the multiselect. | | ||
| **select** | `value` | Selects an option based on its value. | | ||
| **deselect** | `value` | Deselects an option based on its value. | | ||
| **remove** | `value` | Alias for `deselect`. | | ||
| **clear** | | Deselects all selected options. | | ||
| **refreshOptions** | `callback` | Refreshes async options list. | | ||
To access API use `ref` on `Multiselect` component: | ||
``` html | ||
<Multiselect | ||
v-model="value" | ||
:options="options" | ||
ref="multiselect" | ||
/> | ||
``` | ||
``` js | ||
// eg: | ||
mounted() { | ||
this.$refs.multiselect.open() | ||
} | ||
``` | ||
## Events | ||
@@ -184,2 +215,3 @@ | ||
| --- | --- | --- | | ||
| **placeholder** | | Rendered as placeholder when the multiselect does not have value and `placeholder` prop is defined. | | ||
| **afterlist** | | Rendered after the options list. | | ||
@@ -217,3 +249,3 @@ | **beforelist** | | Rendered before the options list. | | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #1</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #1</a> | ||
@@ -234,3 +266,3 @@ ### Multiselect with object options | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #2</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #2</a> | ||
@@ -251,3 +283,3 @@ ### Multiselect with disabled options | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #3</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #3</a> | ||
@@ -270,3 +302,3 @@ ### Tags with search, create and array of objects options | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #4</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #4</a> | ||
@@ -290,3 +322,3 @@ ### Autocomplete with async options | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #5</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #5</a> | ||
@@ -311,3 +343,3 @@ ### Tags with async options | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #6</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #6</a> | ||
@@ -340,3 +372,3 @@ ### Select with custom options slot | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #7</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #7</a> | ||
@@ -365,3 +397,3 @@ ### Multiselect with custom label slot | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #8</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #8</a> | ||
@@ -393,3 +425,3 @@ ### Tags with custom tags slot | ||
@click.prevent | ||
@mousedown.prevent.stop="remove(option)" | ||
@mousedown.prevent.stop="handleTagRemove(option, $event)" | ||
/> | ||
@@ -430,3 +462,3 @@ </div> | ||
<a href="https://jsfiddle.net/5qsugfxt/" target="_blank">JSFiddle - Example #9</a> | ||
<a href="https://jsfiddle.net/armbfy51/" target="_blank">JSFiddle - Example #9</a> | ||
@@ -433,0 +465,0 @@ ## About Vueform |
@@ -10,2 +10,6 @@ import { ref, toRefs, computed } from 'composition-api' | ||
const multiselect = dependencies.multiselect | ||
const blurInput = dependencies.blurInput | ||
const blurSearch = dependencies.blurSearch | ||
const focusInput = dependencies.focusInput | ||
const focusSearch = dependencies.focusSearch | ||
@@ -24,3 +28,3 @@ // ================ DATA ================ | ||
const open = (e) => { | ||
const openDropdown = () => { | ||
if (disabled.value) { | ||
@@ -34,3 +38,3 @@ return | ||
const close = () => { | ||
const closeDropdown = () => { | ||
isOpen.value = false | ||
@@ -40,2 +44,18 @@ context.emit('close') | ||
const open = () => { | ||
if (searchable && searchable.value) { | ||
focusSearch() | ||
} else { | ||
focusInput() | ||
} | ||
} | ||
const close = () => { | ||
if (searchable && searchable.value) { | ||
blurSearch() | ||
} else { | ||
blurInput() | ||
} | ||
} | ||
const handleInputMousedown = (e) => { | ||
@@ -52,2 +72,4 @@ if (isOpen.value && !searchable.value) { | ||
contentMaxHeight, | ||
openDropdown, | ||
closeDropdown, | ||
open, | ||
@@ -54,0 +76,0 @@ close, |
@@ -11,3 +11,3 @@ import { toRefs } from 'composition-api' | ||
const update = dependencies.update | ||
const close = dependencies.close | ||
const closeDropdown = dependencies.closeDropdown | ||
const clearPointer = dependencies.clearPointer | ||
@@ -27,3 +27,3 @@ const search = dependencies.search | ||
const handleEsc = (e) => { | ||
close() | ||
closeDropdown() | ||
clearPointer() | ||
@@ -30,0 +30,0 @@ e.target.blur() |
@@ -19,4 +19,8 @@ import { ref, toRefs, computed } from 'composition-api' | ||
const focusInput = () => { | ||
multiselect.value.querySelector('.multiselect-input').focus() | ||
} | ||
const blurInput = () => { | ||
document.getElementById(id.value).querySelector('.multiselect-input').blur() | ||
multiselect.value.querySelector('.multiselect-input').blur() | ||
} | ||
@@ -27,4 +31,5 @@ | ||
tabindex, | ||
focusInput, | ||
blurInput, | ||
} | ||
} |
@@ -33,3 +33,2 @@ import { ref, toRefs, computed, watch } from 'composition-api' | ||
// no export | ||
const resolving = ref(false) | ||
@@ -106,3 +105,3 @@ | ||
const noOptions = computed(() => { | ||
return !extendedOptions.value.length | ||
return !extendedOptions.value.length && !resolving.value | ||
}) | ||
@@ -192,2 +191,11 @@ | ||
const handleTagRemove = (option, e) => { | ||
if (e.button !== 0) { | ||
e.preventDefault() | ||
return | ||
} | ||
remove(option) | ||
} | ||
const clear = () => { | ||
@@ -316,3 +324,2 @@ update(nullValue.value) | ||
resolvedOptions.value = response | ||
resolving.value = false | ||
@@ -322,5 +329,11 @@ if (typeof callback == 'function') { | ||
} | ||
resolving.value = false | ||
}) | ||
} | ||
const refreshOptions = (callback) => { | ||
resolveOptions(callback) | ||
} | ||
// no export | ||
@@ -368,2 +381,4 @@ const makeInternal = (val) => { | ||
resolving.value = true | ||
if (clearOnSearch.value) { | ||
@@ -377,4 +392,2 @@ resolvedOptions.value = [] | ||
resolving.value = true | ||
options.value(search.value).then((response) => { | ||
@@ -384,5 +397,4 @@ if (query == search.value) { | ||
pointer.value = filteredOptions.value.filter(o => o.disabled !== true)[0] || null | ||
resolving.value = false | ||
} | ||
resolving.value = false | ||
}) | ||
@@ -420,3 +432,3 @@ }, delay.value) | ||
} | ||
}) | ||
}, { flush: 'sync' }) | ||
@@ -430,2 +442,3 @@ return { | ||
noResults, | ||
resolving, | ||
busy, | ||
@@ -441,4 +454,6 @@ select, | ||
handleOptionClick, | ||
handleTagRemove, | ||
refreshOptions, | ||
resolveOptions, | ||
} | ||
} |
@@ -38,2 +38,6 @@ import { ref, toRefs, computed, watch } from 'composition-api' | ||
const focusSearch = () => { | ||
input.value.focus() | ||
} | ||
const blurSearch = () => { | ||
@@ -58,4 +62,5 @@ if (!searchable.value) { | ||
clearSearch, | ||
focusSearch, | ||
blurSearch, | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
143241
28
1024
457