1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
this.VueNextSelect=function(e){"use strict";var l={inheritAttrs:!1,name:"vue-input",props:{modelValue:{required:!0,type:String},placeholder:{required:!0,type:String},disabled:{required:!0,type:Boolean},tabindex:{required:!0,type:Number},autofocus:{required:!0,type:Boolean}},emits:["update:modelValue","input","change","focus","blur","escape"],setup(l,a){const t=e.ref(null);return e.onMounted((()=>{l.autofocus&&t.value.focus()})),e.onUpdated((()=>{l.autofocus&&t.value.focus()})),{handleInput:e=>{a.emit("input",e),a.emit("update:modelValue",e.target.value)},handleChange:e=>{a.emit("change",e),a.emit("update:modelValue",e.target.value)},handleFocus:e=>{a.emit("focus",e)},handleBlur:e=>{a.emit("blur",e)},input:t,handleEscape:e=>{t.value.blur(),a.emit("escape",e)}}}};const a={class:"vue-input"};l.render=function(l,t,o,n,u,i){return e.openBlock(),e.createBlock("div",a,[e.renderSlot(l.$slots,"prepend"),e.createVNode("input",{ref:"input",modelValue:o.modelValue,placeholder:o.placeholder,disabled:o.disabled,onInput:t[1]||(t[1]=(...e)=>n.handleInput&&n.handleInput(...e)),onChange:t[2]||(t[2]=(...e)=>n.handleChange&&n.handleChange(...e)),onFocus:t[3]||(t[3]=(...e)=>n.handleFocus&&n.handleFocus(...e)),onBlur:t[4]||(t[4]=(...e)=>n.handleBlur&&n.handleBlur(...e)),onKeyup:t[5]||(t[5]=e.withKeys(e.withModifiers(((...e)=>n.handleEscape&&n.handleEscape(...e)),["exact"]),["esc"])),tabindex:o.tabindex,autofocus:o.autofocus},null,40,["modelValue","placeholder","disabled","tabindex","autofocus"]),e.renderSlot(l.$slots,"append")])},l.__file="src/components/input.vue";var t={inheritAttrs:!1,name:"vue-tags",props:{modelValue:{required:!0,type:Array,validator:e=>e.every((e=>void 0!==typeof e.key&&void 0!==e.label&&"boolean"==typeof e.selected))},collapseTags:{type:Boolean}},emits:["click"],setup:(l,a)=>({dataAttrs:e.inject("dataAttrs"),handleClick:e=>{a.emit("click",e)}})};t.render=function(l,a,t,o,n,u){return e.openBlock(),e.createBlock("ul",e.mergeProps({class:["vue-tags",{collapsed:t.collapseTags}],onMousedown:a[1]||(a[1]=e.withModifiers((()=>{}),["prevent"])),tabindex:"-1",onClick:a[2]||(a[2]=(...e)=>o.handleClick&&o.handleClick(...e))},o.dataAttrs),[(e.openBlock(!0),e.createBlock(e.Fragment,null,e.renderList(t.modelValue,(a=>(e.openBlock(),e.createBlock("li",{key:a.key,class:["vue-tag",{selected:a.selected}]},[e.renderSlot(l.$slots,"default",{option:a},(()=>[e.createVNode("span",null,e.toDisplayString(a.label),1)]))],2)))),128))],16)},t.__file="src/components/tags.vue";var o={inheritAttrs:!1,name:"vue-dropdown",props:{modelValue:{required:!0,type:Array,validator:e=>e.every((e=>void 0!==typeof e.key&&void 0!==e.label&&"boolean"==typeof e.selected))},headerHeight:{required:!0,type:String}},emits:["click"],setup:(l,a)=>({dataAttrs:e.inject("dataAttrs"),handleClick:(e,l)=>{a.emit("click",e,l)}})};o.render=function(l,a,t,o,n,u){return e.openBlock(),e.createBlock("ul",e.mergeProps({class:"vue-dropdown",onMousedown:a[1]||(a[1]=e.withModifiers((()=>{}),["prevent"])),style:{top:t.headerHeight}},o.dataAttrs),[(e.openBlock(!0),e.createBlock(e.Fragment,null,e.renderList(t.modelValue,(a=>(e.openBlock(),e.createBlock(e.Fragment,{key:a.key},[a.visible&&!1===a.hidden?(e.openBlock(),e.createBlock("li",{key:0,onClick:e=>o.handleClick(e,a),class:["vue-dropdown-item",{selected:a.selected}]},[e.renderSlot(l.$slots,"default",{option:a},(()=>[e.createVNode("span",null,e.toDisplayString(a.label),1)]))],10,["onClick"])):e.createCommentVNode("v-if",!0)],64)))),128))],16)},o.__file="src/components/dropdown.vue";const n=(e,l,{valueBy:a})=>a(e)===a(l),u=(e,l,{valueBy:a})=>e.some((e=>n(e,l,{valueBy:a}))),i=(e,l,{valueBy:a})=>e.find((e=>a(e)===l)),d=(e,l,{max:a,valueBy:t})=>u(e,l,{valueBy:t})||e.length>=a?e:e.concat(l),r=(e,l,{min:a,valueBy:t})=>!1===u(e,l,{valueBy:t})||e.length<=a?e:e.filter((e=>!1===n(e,l,{valueBy:t}))),s=l=>e.computed((()=>"function"==typeof l.value?l.value:"string"==typeof l.value?e=>l.value.split(".").reduce(((e,l)=>e[l]),e):e=>e));const c={name:"vue-select",inheritAttrs:!1,props:{modelValue:{required:!0},emptyModelValue:{default:null},options:{required:!0,type:Array},visibleOptions:{type:[Array,null],default:null},multiple:{default:!1,type:Boolean},min:{default:0,type:Number},max:{default:1/0,type:Number},closeOnSelect:{default:!1,type:Boolean},clearOnSelect:{default:!1,type:Boolean},trackBy:{type:[String,Function]},hideSelected:{default:!1,type:Boolean},labelBy:{type:[String,Function]},valueBy:{type:[String,Function]},disabled:{default:!1,type:Boolean},loading:{default:!1,type:Boolean},placeholder:{default:"Select option",type:String},searchPlaceholder:{default:"Type to search",type:String},searchable:{default:!1,type:Boolean},clearOnClose:{default:!1,type:Boolean},taggable:{default:!1,type:Boolean},collapseTags:{default:!1,type:Boolean},tabindex:{default:0,type:Number},autofocus:{default:!1,type:Boolean}},emits:["update:modelValue","selected","removed","opened","closed","search:input","search:change","search:focus","search:blur"],setup(l,a){const{trackBy:t,labelBy:o,valueBy:n,min:c,max:p,options:v}=(l=>({trackBy:s(e.toRef(l,"trackBy")),labelBy:s(e.toRef(l,"labelBy")),valueBy:s(e.toRef(l,"valueBy")),min:e.computed((()=>l.multiple?l.min:Math.min(1,l.min))),max:e.computed((()=>l.multiple?l.max:1)),options:e.isRef(l.options)||e.isReactive(l.options)?e.toRef(l,"options"):e.ref(l.options)}))(l),h=e.ref(),m=e.ref(),g=e.ref(!1);e.watch((()=>g.value),(()=>{g.value?(a.emit("opened"),l.searchable?(m.value&&m.value._.refs.input!==document.activeElement&&m.value._.refs.input.focus(),a.emit("search:focus")):h.value.focus()):(l.searchable?(m.value&&m.value._.refs.input===document.activeElement&&m.value._.refs.input.blur(),l.clearOnClose&&F(),a.emit("search:blur")):h.value.blur(),a.emit("closed"))}));const f=()=>{l.disabled||(g.value=!0)},y=()=>{g.value=!1};e.watch((()=>l.disabled),(()=>y()));const b=e.ref(),B=(V=b,I=()=>l.modelValue,w=e.ref("0"),k=function(){e.nextTick((function(){V.value&&(w.value=window.getComputedStyle(V.value).height)}))},e.watch(I,k),e.onMounted(k),w);var V,I,w,k;const M=e.computed((()=>l.searchable&&l.multiple&&l.taggable?"22px":"0px")),N=e.computed((()=>parseFloat(B.value)+parseFloat(M.value)+"px")),C=e.ref(""),S=e.ref([]),x=()=>{if(l.multiple){if(!1===Array.isArray(l.modelValue))return!1;if(S.value.length!==l.modelValue.length)return!1;if(Object.keys(S.value).some((e=>S.value[e]!==i(v.value,l.modelValue[e],{valueBy:n.value}))))return!1}else{if(0===S.value.length&&l.modelValue!==l.emptyModelValue)return!1;if(1===S.value.length&&l.modelValue===l.emptyModelValue)return!1;if(S.value[0]!==i(v.value,l.modelValue,{valueBy:n.value}))return!1}return!0},D=()=>{if(x())return;S.value=[];const e=l.multiple?l.modelValue:l.modelValue===l.emptyModelValue?[]:[l.modelValue];for(const l of e){const e=i(v.value,l,{valueBy:n.value});!1!==u(v.value,e,{valueBy:n.value})&&(S.value=d(S.value,e,{max:1/0,valueBy:n.value}))}};D(),e.watch((()=>l.modelValue),(()=>D()),{deep:!0});e.watch((()=>S),(()=>(()=>{if(x())return;const e=S.value.map((e=>n.value(e)));l.multiple?a.emit("update:modelValue",e):e.length?a.emit("update:modelValue",e[0]):a.emit("update:modelValue",l.emptyModelValue)})()),{deep:!0}),e.watch((()=>v.value),(()=>{const e=new Set(S.value.map((e=>n.value(e))));S.value=v.value.filter((l=>e.has(n.value(l))))}),{deep:!0});const F=()=>{m.value._.refs.input.value="",m.value._.refs.input.dispatchEvent(new Event("input")),m.value._.refs.input.dispatchEvent(new Event("change"))},O=e.computed((()=>{const e=new Set(S.value.map((e=>n.value(e)))),a=null!==l.visibleOptions?new Set(l.visibleOptions.map((e=>n.value(e)))):new Set(v.value.map((e=>n.value(e))));return v.value.map((u=>({key:t.value(u),label:o.value(u),selected:e.has(n.value(u)),visible:a.has(n.value(u)),hidden:!!l.hideSelected&&e.has(n.value(u)),originalOption:u})))})),A=e.computed((()=>({"data-is-focusing":g.value,"data-visible-length":O.value.filter((e=>e.visible&&!1===e.hidden)).length,"data-not-selected-length":v.value.length-O.value.filter((e=>e.selected)).length,"data-selected-length":O.value.filter((e=>e.selected)).length,"data-addable":O.value.filter((e=>e.selected)).length<p.value,"data-removable":O.value.filter((e=>e.selected)).length>c.value,"data-total-length":v.value.length,"data-multiple":l.multiple})));e.provide("dataAttrs",A);const T=e.computed((()=>{const e=O.value.filter((e=>e.selected));return l.multiple?0===e.length?l.placeholder:1===e.length?"1 option selected":e.length+" options selected":0===e.length?l.placeholder:e[0].label+""}));return{isFocusing:g,wrapper:h,input:m,focus:f,blur:y,toggle:()=>{g.value?y():f()},header:b,headerAndInputHeight:N,searchingInputValue:C,handleInputForInput:e=>{a.emit("search:input",e)},handleChangeForInput:e=>{a.emit("search:change",e)},handleFocusForInput:e=>{f()},handleBlurForInput:e=>{y()},optionsWithInfo:O,addOrRemoveOption:(e,t)=>{if(!l.disabled){if(t=t.originalOption,u(S.value,t,{valueBy:n.value}))S.value=r(S.value,t,{min:c.value,valueBy:n.value}),a.emit("removed",t);else{if(!l.multiple){const e=S.value[0];S.value=r(S.value,S.value[0],{min:0,valueBy:n.value}),a.emit("removed",e)}S.value=d(S.value,t,{max:p.value,valueBy:n.value}),a.emit("selected",t)}!0===l.closeOnSelect&&(g.value=!1),!0===l.clearOnSelect&&C.value&&F()}},dataAttrs:A,innerPlaceholder:T}},components:{VInput:l,VTags:t,VDropdown:o},__VERSION__:"1.2.1"};const p={ref:"header",class:"vue-select-header"},v={key:0,class:"vue-input"},h={class:"icon loading"},m=e.createVNode("div",null,null,-1),g=e.createVNode("div",null,null,-1),f=e.createVNode("div",null,null,-1),y={class:"icon loading"},b=e.createVNode("div",null,null,-1),B=e.createVNode("div",null,null,-1),V=e.createVNode("div",null,null,-1);return c.render=function(l,a,t,o,n,u){const i=e.resolveComponent("v-tags"),d=e.resolveComponent("v-input"),r=e.resolveComponent("v-dropdown");return e.openBlock(),e.createBlock("div",e.mergeProps({ref:"wrapper",class:["vue-select",{disabled:l.disabled}],tabindex:l.isFocusing?-1:l.tabindex,onFocus:a[9]||(a[9]=(...e)=>l.focus&&l.focus(...e)),onBlur:a[10]||(a[10]=()=>!l.searchable&&l.blur())},l.dataAttrs),[e.createVNode("div",p,[l.multiple&&l.taggable&&0===l.modelValue.length||!1===l.searchable&&!1===l.taggable?(e.openBlock(),e.createBlock("div",v,[e.createVNode("input",{placeholder:l.innerPlaceholder,readonly:"",onClick:a[1]||(a[1]=(...e)=>l.focus&&l.focus(...e))},null,8,["placeholder"])])):e.createCommentVNode("v-if",!0),l.multiple&&l.taggable?(e.openBlock(),e.createBlock(e.Fragment,{key:1},[e.createVNode(i,{modelValue:l.optionsWithInfo,"collapse-tags":l.collapseTags,tabindex:"-1",onClick:l.focus},{default:e.withCtx((({option:a})=>[e.renderSlot(l.$slots,"tag",{option:a.originalOption},(()=>[e.createVNode("span",null,e.toDisplayString(a.label),1),e.createVNode("img",{src:"data:image/svg+xml;base64,PHN2ZyBpZD0iZGVsZXRlIiBkYXRhLW5hbWU9ImRlbGV0ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiI+PHRpdGxlPmRlbGV0ZTwvdGl0bGU+PHBhdGggZD0iTTI1NiwyNEMzODMuOSwyNCw0ODgsMTI4LjEsNDg4LDI1NlMzODMuOSw0ODgsMjU2LDQ4OCwyNC4wNiwzODMuOSwyNC4wNiwyNTYsMTI4LjEsMjQsMjU2LDI0Wk0wLDI1NkMwLDM5Ny4xNiwxMTQuODQsNTEyLDI1Niw1MTJTNTEyLDM5Ny4xNiw1MTIsMjU2LDM5Ny4xNiwwLDI1NiwwLDAsMTE0Ljg0LDAsMjU2WiIgZmlsbD0iIzViNWI1ZiIvPjxwb2x5Z29uIHBvaW50cz0iMzgyIDE3Mi43MiAzMzkuMjkgMTMwLjAxIDI1NiAyMTMuMjkgMTcyLjcyIDEzMC4wMSAxMzAuMDEgMTcyLjcyIDIxMy4yOSAyNTYgMTMwLjAxIDMzOS4yOCAxNzIuNzIgMzgyIDI1NiAyOTguNzEgMzM5LjI5IDM4MS45OSAzODIgMzM5LjI4IDI5OC43MSAyNTYgMzgyIDE3Mi43MiIgZmlsbD0iIzViNWI1ZiIvPjwvc3ZnPg==",alt:"delete tag",class:"icon delete",onClick:e.withModifiers((()=>l.addOrRemoveOption(l.$event,a)),["prevent","stop"])},null,8,["onClick"])]))])),_:1},8,["modelValue","collapse-tags","onClick"]),e.createVNode("span",{class:["icon arrow-downward",{active:l.isFocusing}],onClick:a[2]||(a[2]=(...e)=>l.toggle&&l.toggle(...e)),onMousedown:a[3]||(a[3]=e.withModifiers((()=>{}),["prevent","stop"]))},null,34)],64)):(e.openBlock(),e.createBlock(e.Fragment,{key:2},[l.searchable?(e.openBlock(),e.createBlock(d,{key:0,ref:"input",modelValue:l.searchingInputValue,"onUpdate:modelValue":a[4]||(a[4]=e=>l.searchingInputValue=e),disabled:l.disabled,placeholder:l.isFocusing?l.searchPlaceholder:l.innerPlaceholder,onInput:l.handleInputForInput,onChange:l.handleChangeForInput,onFocus:l.handleFocusForInput,onBlur:l.handleBlurForInput,onEscape:l.blur,autofocus:l.autofocus||l.taggable&&l.searchable,tabindex:l.tabindex},null,8,["modelValue","disabled","placeholder","onInput","onChange","onFocus","onBlur","onEscape","autofocus","tabindex"])):e.createCommentVNode("v-if",!0),e.withDirectives(e.createVNode("span",h,[m,g,f],512),[[e.vShow,l.loading]]),e.withDirectives(e.createVNode("span",{class:["icon arrow-downward",{active:l.isFocusing}],onClick:a[5]||(a[5]=(...e)=>l.toggle&&l.toggle(...e)),onMousedown:a[6]||(a[6]=e.withModifiers((()=>{}),["prevent","stop"]))},null,34),[[e.vShow,!1===l.loading]])],64))],512),l.multiple&&l.taggable&&l.searchable?e.withDirectives((e.openBlock(),e.createBlock(d,{key:0,ref:"input",modelValue:l.searchingInputValue,"onUpdate:modelValue":a[7]||(a[7]=e=>l.searchingInputValue=e),disabled:l.disabled,placeholder:l.searchPlaceholder,onInput:l.handleInputForInput,onChange:l.handleChangeForInput,onFocus:l.handleFocusForInput,onBlur:l.handleBlurForInput,onEscape:l.blur,tabindex:l.tabindex,autofocus:l.autofocus||l.taggable&&l.searchable},{append:e.withCtx((()=>[e.withDirectives(e.createVNode("span",y,[b,B,V],512),[[e.vShow,l.loading]])])),_:1},8,["modelValue","disabled","placeholder","onInput","onChange","onFocus","onBlur","onEscape","tabindex","autofocus"])),[[e.vShow,l.isFocusing]]):e.createCommentVNode("v-if",!0),e.withDirectives(e.createVNode(r,{modelValue:l.optionsWithInfo,"onUpdate:modelValue":a[8]||(a[8]=e=>l.optionsWithInfo=e),onClick:l.addOrRemoveOption,"header-height":l.headerAndInputHeight},{default:e.withCtx((({option:a})=>[e.renderSlot(l.$slots,"dropdown-item",{option:a.originalOption},(()=>[e.createVNode("span",null,e.toDisplayString(a.label),1)]))])),_:1},8,["modelValue","onClick","header-height"]),[[e.vShow,l.isFocusing]])],16,["tabindex"])},c.__file="src/index.vue",c}(Vue);
|