vue-single-select
Advanced tools
Comparing version 1.0.22 to 1.0.23
@@ -1,1 +0,1 @@ | ||
!function(e,t){for(var i in t)e[i]=t[i]}(window,function(e){var t={};function i(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(n,o,function(t){return e[t]}.bind(null,o));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=1)}([function(e,t,i){"use strict";var n=function(e,t,i,n,o,r,s,a){var d=typeof(e=e||{}).default;"object"!==d&&"function"!==d||(e=e.default);var c,l="function"==typeof e?e.options:e;if(t&&(l.render=t,l.staticRenderFns=i,l._compiled=!0),n&&(l.functional=!0),r&&(l._scopeId=r),s?(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__),o&&o.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(s)},l._ssrRegister=c):o&&(c=a?function(){o.call(this,this.$root.$options.shadowRoot)}:o),c)if(l.functional){l._injectStyles=c;var u=l.render;l.render=function(e,t){return c.call(t),u(e,t)}}else{var p=l.beforeCreate;l.beforeCreate=p?[].concat(p,c):[c]}return{exports:e,options:l}}({props:{value:{required:!0},name:{type:String,required:!1,default:()=>""},options:{type:Array,required:!1,default:()=>[]},optionLabel:{type:String,required:!1,default:()=>null},optionKey:{type:String,required:!1,default:()=>null},placeholder:{type:String,required:!1,default:()=>"Search Here"},maxHeight:{type:String,default:()=>"220px",required:!1},inputId:{type:String,default:()=>"single-select",required:!1},classes:{type:Object,required:!1,default:()=>({pointer:-1,wrapper:"single-select-wrapper",input:"search-input",icons:"icons",required:"required",activeClass:"active",dropdown:"dropdown"})},initial:{type:String,required:!1,default:()=>null},required:{type:Boolean,required:!1,default:()=>!1},maxResults:{type:Number,required:!1,default:()=>30},tabindex:{type:String,required:!1,default:()=>""},getOptionDescription:{type:Function,default(e){return this.optionKey&&this.optionLabel?e[this.optionKey]+" "+e[this.optionLabel]:this.optionLabel?e[this.optionLabel]:this.optionKey?e[this.optionKey]:e}},getOptionValue:{type:Function,default(e){return this.optionKey?e[this.optionKey]:this.optionLabel?e[this.optionLabel]:e}}},mixins:[{watch:{pointer(){this.maybeAdjustScroll()}},data:()=>({pointer:-1}),methods:{maybeAdjustScroll(){let e=this.pixelsToPointerTop(),t=this.pixelsToPointerBottom();return e<=this.viewport().top?this.scrollTo(e):t>=this.viewport().bottom?this.scrollTo(this.viewport().top+this.pointerHeight()):void 0},pixelsToPointerTop(){let e=0;if(!this.$refs.options)return 0;for(let t=0;t<this.pointer;t++)e+=this.$refs.options.children[t].offsetHeight;return e},pixelsToPointerBottom(){return this.pixelsToPointerTop()+this.pointerHeight()},pointerHeight(){let e=!!this.$refs.options&&this.$refs.options.children[this.pointer];return e?e.offsetHeight:0},viewport(){return{top:this.$refs.options?this.$refs.options.scrollTop:0,bottom:this.$refs.options?this.$refs.options.offsetHeight+this.$refs.options.scrollTop:0}},scrollTo(e){return this.$refs.options?this.$refs.options.scrollTop=e:null}}}],mounted(){document.addEventListener("click",this.handleClickOutside),document.addEventListener("keyup",this.handleClickOutside),this.searchText=this.initial},destroyed(){document.removeEventListener("keyup",this.handleClickOutside),document.removeEventListener("click",this.handleClickOutside)},data:()=>({searchText:null,selectedOption:null,dropdownOpen:!1,closed:!1}),watch:{value(e,t){e!==t&&(this.selectedOption=e)},searchText(e,t){e!==t&&(this.pointer=-1),e&&(this.closed=!1)},selectedOption(e,t){e!==t&&(this.$emit("input",e),this.closed||e||this.$nextTick().then(()=>{this.$refs.search.focus()}))},dropdownOpen(e,t){e!==t&&(this.selectedOption?this.searchText=this.getOptionDescription(this.selectedOption):e?(this.searchText||(this.searchText=""),this.$nextTick().then(()=>{this.$refs.search.focus()})):this.searchText=null)}},computed:{isRequired(){return this.required&&this.closed?this.selectedOption?"":"required":""},matchingOptions(){return null===this.searchText?null:this.searchText.length?this.optionLabel&&this.optionKey?this.options.filter(e=>e[this.optionLabel].toString().toLowerCase().includes(this.searchText.toString().toLowerCase())||this.searchText.toString().toLowerCase().includes(e[this.optionKey].toString().toLowerCase())).slice(0,this.maxResults):this.optionLabel?this.options.filter(e=>e[this.optionLabel].toString().toLowerCase().includes(this.searchText.toString().toLowerCase())).slice(0,this.maxResults):this.optionKey?this.options.filter(e=>this.searchText.toString().toLowerCase().includes(e[this.optionKey].toString().toLowerCase())).slice(0,this.maxResults):this.options.filter(e=>e.toString().toLowerCase().includes(this.searchText.toString().toLowerCase())).slice(0,this.maxResults):[...this.options].slice(0,this.maxResults)}},methods:{setPointerIdx(e){this.pointer=e},seedSearchText(){null===this.searchText&&(this.searchText="",this.closed&&(this.closed=!1))},resetSearch(){this.selectedOption=null,this.dropdownOpen=!1,this.searchText=null},switchToSearch(e){this.searchText=e.target.value,this.selectedOption=null,this.$nextTick().then(()=>{this.$refs.search.focus()})},toggleDropdown(){this.dropdownOpen=!this.dropdownOpen},closeOut(){this.selectedOption=null,this.dropdownOpen=!1,this.searchText=null,this.closed=!0},movePointerDown(){this.matchingOptions&&(this.pointer>=this.matchingOptions.length-1||this.pointer++)},movePointerUp(){this.pointer>0&&this.pointer--},setOption(){this.matchingOptions&&this.matchingOptions.length&&(-1===this.pointer&&this.pointer++,this.selectedOption=this.matchingOptions[this.pointer],this.searchText=null,this.dropdownOpen=!1,this.pointer=-1,this.$nextTick().then(()=>{this.$refs.match.focus()}))},handleClickOutside(e){this.$el.contains(e.target)||(this.dropdownOpen=!1,this.searchText=null,this.closed=!0)}}},function(){var e=this,t=e.$createElement,i=e._self._c||t;return i("div",{ref:"vuesingleselect"},[e.selectedOption?e._e():i("div",{class:e.classes.wrapper},[i("div",{staticClass:"relative inline-block w-full"},[i("input",{directives:[{name:"model",rawName:"v-model",value:e.searchText,expression:"searchText"}],ref:"search",class:[e.classes.input,e.isRequired],attrs:{id:e.inputId,placeholder:e.placeholder,autocomplete:"off",required:e.required},domProps:{value:e.searchText},on:{click:e.seedSearchText,focus:e.seedSearchText,keyup:[function(t){return"button"in t||!e._k(t.keyCode,"enter",13,t.key,"Enter")?e.setOption(t):null},function(t){return"button"in t||!e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?e.movePointerDown(t):null},function(t){return"button"in t||!e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?e.movePointerUp(t):null}],keydown:[function(t){return"button"in t||!e._k(t.keyCode,"tab",9,t.key,"Tab")?(t.stopPropagation(),e.closeOut(t)):null},function(t){return"button"in t||!e._k(t.keyCode,"esc",27,t.key,"Escape")?(t.stopPropagation(),e.closeOut(t)):null}],input:function(t){t.target.composing||(e.searchText=t.target.value)}}}),e._v(" "),i("div",{staticClass:"cursor-pointer absolute flex items-center",class:[e.classes.icons],on:{click:e.toggleDropdown}},[e.dropdownOpen?i("svg",{attrs:{"aria-hidden":"true",viewBox:"0 0 448 512"}},[i("path",{attrs:{d:"M240.971 130.524l194.343 194.343c9.373 9.373 9.373 24.569 0 33.941l-22.667 22.667c-9.357 9.357-24.522 9.375-33.901.04L224 227.495 69.255 381.516c-9.379 9.335-24.544 9.317-33.901-.04l-22.667-22.667c-9.373-9.373-9.373-24.569 0-33.941L207.03 130.525c9.372-9.373 24.568-9.373 33.941-.001z"}})]):i("svg",{attrs:{"aria-hidden":"true",viewBox:"0 0 448 512"}},[i("path",{attrs:{d:"M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"}})])]),e._v(" "),e.matchingOptions?i("ul",{ref:"options",staticClass:"absolute w-full overflow-auto appearance-none mt-px list-reset",class:[e.classes.dropdown],staticStyle:{"z-index":"100"},style:{"max-height":e.maxHeight},attrs:{tabindex:"-1"}},e._l(e.matchingOptions,function(t,n){return i("li",{key:n,staticClass:"cursor-pointer outline-none",class:n===e.pointer?e.classes.activeClass:"",attrs:{tabindex:"-1"},on:{blur:function(t){e.handleClickOutside(t)},mouseover:function(t){e.setPointerIdx(n)},keyup:[function(t){if(!("button"in t)&&e._k(t.keyCode,"enter",13,t.key,"Enter"))return null;e.setOption()},function(t){if(!("button"in t)&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"]))return null;e.movePointerUp()},function(t){if(!("button"in t)&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"]))return null;e.movePointerDown()}],click:function(t){t.preventDefault(),e.setOption()}}},[e._t("option",[e._v("\n "+e._s(e.getOptionDescription(t))+"\n\t\t\t")],null,{option:t,idx:n})],2)})):e._e()])]),e._v(" "),e.selectedOption?i("div",{class:e.classes.wrapper},[i("input",{ref:"match",class:[e.classes.input],attrs:{id:"inputId",required:e.required,placeholder:e.placeholder},domProps:{value:e.getOptionDescription(e.selectedOption)},on:{input:function(t){e.switchToSearch(t)},click:function(t){e.switchToSearch(t)}}}),e._v(" "),i("input",{ref:"selectValue",attrs:{type:"hidden",name:e.name},domProps:{value:e.getOptionValue(e.selectedOption)}}),e._v(" "),i("div",{staticClass:"cursor-pointer absolute flex items-center",class:e.classes.icons,on:{click:e.closeOut}},[i("svg",{attrs:{"aria-hidden":"true",viewBox:"0 0 512 512"},on:{click:e.closeOut}},[i("path",{attrs:{d:"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"}})])])]):e._e()])},[],!1,function(e){i(3)},"data-v-eed7cdb4",null);t.a=n.exports},function(e,t,i){"use strict";i.r(t),function(e){i.d(t,"install",function(){return o});var n=i(0);function o(e){o.installed||(o.installed=!0,e.component("vue-single-select",n.a))}const r={install:o};let s=null;"undefined"!=typeof window?s=window.Vue:void 0!==e&&(s=e.Vue),s&&s.use(r)}.call(this,i(2))},function(e,t){var i;i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t,i){var n=i(4);"string"==typeof n&&(n=[[e.i,n,""]]),n.locals&&(e.exports=n.locals);(0,i(6).default)("fc392c80",n,!0,{})},function(e,t,i){(e.exports=i(5)(!1)).push([e.i,".inline-block[data-v-eed7cdb4]{display:inline-block}.block[data-v-eed7cdb4]{display:block}.flex[data-v-eed7cdb4]{display:flex}.border[data-v-eed7cdb4]{border-width:thin;border-style:solid}.rounded[data-v-eed7cdb4]{border-radius:.25em}.text-black[data-v-eed7cdb4]{color:#22292f}.border-grey-lighter[data-v-eed7cdb4]{border-color:#ced4da}.bg-grey-lighter[data-v-eed7cdb4]{background-color:#606f7b}.bg-grey-light[data-v-eed7cdb4]{background-color:#dae1e7}.bg-grey-dark[data-v-eed7cdb4]{background-color:#8795a1}.bg-white[data-v-eed7cdb4]{background-color:#fff}.pin-r[data-v-eed7cdb4]{right:0}.pin-y[data-v-eed7cdb4]{top:0;bottom:0}.absolute[data-v-eed7cdb4]{position:absolute}.relative[data-v-eed7cdb4]{position:relative}.items-center[data-v-eed7cdb4]{align-items:center}.p-0[data-v-eed7cdb4]{padding:0}.p-1[data-v-eed7cdb4]{padding:.25em}.px-1[data-v-eed7cdb4]{padding-left:.25em;padding-right:.25em}.py-2[data-v-eed7cdb4]{padding-top:.5em;padding-bottom:.5em}.px-2[data-v-eed7cdb4]{padding-left:.5em;padding-right:.5em}.mt-px[data-v-eed7cdb4]{margin-top:1px}.leading-tight[data-v-eed7cdb4]{line-height:1.25}.leading-normal[data-v-eed7cdb4]{line-height:1.5}.text-left[data-v-eed7cdb4]{text-align:left}.w-full[data-v-eed7cdb4]{width:100%}.shadow[data-v-eed7cdb4]{box-shadow:0 2px 4px 0 rgba(0,0,0,.1)}.list-reset[data-v-eed7cdb4]{list-style:none;padding:0}.overflow-auto[data-v-eed7cdb4]{overflow:auto}.appearance-none[data-v-eed7cdb4]{-webkit-appearance:none;-moz-appearance:none;appearance:none}.w-1[data-v-eed7cdb4]{width:.25em}.w-2[data-v-eed7cdb4]{width:.5em}.w-3[data-v-eed7cdb4]{width:.75em}.w-4[data-v-eed7cdb4]{width:1em}.h-4[data-v-eed7cdb4]{height:1em}.h-1[data-v-eed7cdb4]{height:.25em}.h-2[data-v-eed7cdb4]{height:.5em}.h-3[data-v-eed7cdb4]{height:.75em}.fill-current[data-v-eed7cdb4]{fill:currentColor}.hover\\:no-underline[data-v-eed7cdb4]:hover,.no-underline[data-v-eed7cdb4]{text-decoration:none}.hover\\:outline-none[data-v-eed7cdb4],.outline-none[data-v-eed7cdb4]{outline:0}.hover\\:bg-grey-light[data-v-eed7cdb4]:hover{background-color:#dae1e7}.shadow-md[data-v-eed7cdb4]{box-shadow:0 4px 8px 0 rgba(0,0,0,.12),0 2px 4px 0 rgba(0,0,0,.08)}.search-input[data-v-eed7cdb4]{display:block;width:100%;padding:.375em .75em;font-size:1em;line-height:1.5;color:#495057;background-color:#fff;background-clip:padding-box;border:1px solid #ced4da;border-radius:.25em;transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out;box-sizing:border-box}.icons[data-v-eed7cdb4]{padding:0 1em;right:0;top:0;bottom:0;fill:#606f7b}.icons svg[data-v-eed7cdb4]{width:.75em;height:.75em}.single-select-wrapper[data-v-eed7cdb4]{position:relative;margin-bottom:.5em}.required[data-v-eed7cdb4]{_color:#721c24;_background-color:#f8d7da;border-color:#f5c6cb}.cursor-pointer[data-v-eed7cdb4]{cursor:pointer}.dropdown[data-v-eed7cdb4]{-webkit-box-shadow:0 4px 8px 0 rgba(0,0,0,.12),0 2px 4px 0 rgba(0,0,0,.08);box-shadow:0 4px 8px 0 rgba(0,0,0,.12),0 2px 4px 0 rgba(0,0,0,.08);background-color:#fff;color:#606f7b;border-radius:.25em;line-height:1.25;text-align:left}.dropdown>li[data-v-eed7cdb4]{padding:.5em .75em}.active[data-v-eed7cdb4]{background:#dae1e7}",""])},function(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var i=function(e,t){var i=e[1]||"",n=e[3];if(!n)return i;if(t&&"function"==typeof btoa){var o=function(e){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(e))))+" */"}(n),r=n.sources.map(function(e){return"/*# sourceURL="+n.sourceRoot+e+" */"});return[i].concat(r).concat([o]).join("\n")}return[i].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+i+"}":i}).join("")},t.i=function(e,i){"string"==typeof e&&(e=[[null,e,""]]);for(var n={},o=0;o<this.length;o++){var r=this[o][0];"number"==typeof r&&(n[r]=!0)}for(o=0;o<e.length;o++){var s=e[o];"number"==typeof s[0]&&n[s[0]]||(i&&!s[2]?s[2]=i:i&&(s[2]="("+s[2]+") and ("+i+")"),t.push(s))}},t}},function(e,t,i){"use strict";function n(e,t){for(var i=[],n={},o=0;o<t.length;o++){var r=t[o],s=r[0],a={id:e+":"+o,css:r[1],media:r[2],sourceMap:r[3]};n[s]?n[s].parts.push(a):i.push(n[s]={id:s,parts:[a]})}return i}i.r(t),i.d(t,"default",function(){return f});var o="undefined"!=typeof document;if("undefined"!=typeof DEBUG&&DEBUG&&!o)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var r={},s=o&&(document.head||document.getElementsByTagName("head")[0]),a=null,d=0,c=!1,l=function(){},u=null,p="data-vue-ssr-id",h="undefined"!=typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());function f(e,t,i,o){c=i,u=o||{};var s=n(e,t);return v(s),function(t){for(var i=[],o=0;o<s.length;o++){var a=s[o];(d=r[a.id]).refs--,i.push(d)}t?v(s=n(e,t)):s=[];for(o=0;o<i.length;o++){var d;if(0===(d=i[o]).refs){for(var c=0;c<d.parts.length;c++)d.parts[c]();delete r[d.id]}}}}function v(e){for(var t=0;t<e.length;t++){var i=e[t],n=r[i.id];if(n){n.refs++;for(var o=0;o<n.parts.length;o++)n.parts[o](i.parts[o]);for(;o<i.parts.length;o++)n.parts.push(g(i.parts[o]));n.parts.length>i.parts.length&&(n.parts.length=i.parts.length)}else{var s=[];for(o=0;o<i.parts.length;o++)s.push(g(i.parts[o]));r[i.id]={id:i.id,refs:1,parts:s}}}}function b(){var e=document.createElement("style");return e.type="text/css",s.appendChild(e),e}function g(e){var t,i,n=document.querySelector("style["+p+'~="'+e.id+'"]');if(n){if(c)return l;n.parentNode.removeChild(n)}if(h){var o=d++;n=a||(a=b()),t=x.bind(null,n,o,!1),i=x.bind(null,n,o,!0)}else n=b(),t=function(e,t){var i=t.css,n=t.media,o=t.sourceMap;n&&e.setAttribute("media",n);u.ssrId&&e.setAttribute(p,t.id);o&&(i+="\n/*# sourceURL="+o.sources[0]+" */",i+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");if(e.styleSheet)e.styleSheet.cssText=i;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(i))}}.bind(null,n),i=function(){n.parentNode.removeChild(n)};return t(e),function(n){if(n){if(n.css===e.css&&n.media===e.media&&n.sourceMap===e.sourceMap)return;t(e=n)}else i()}}var m=function(){var e=[];return function(t,i){return e[t]=i,e.filter(Boolean).join("\n")}}();function x(e,t,i,n){var o=i?"":n.css;if(e.styleSheet)e.styleSheet.cssText=m(t,o);else{var r=document.createTextNode(o),s=e.childNodes;s[t]&&e.removeChild(s[t]),s.length?e.insertBefore(r,s[t]):e.appendChild(r)}}}])); | ||
!function(e,t){for(var i in t)e[i]=t[i]}(window,function(e){var t={};function i(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(n,o,function(t){return e[t]}.bind(null,o));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=1)}([function(e,t,i){"use strict";var n=function(e,t,i,n,o,r,s,a){var l=typeof(e=e||{}).default;"object"!==l&&"function"!==l||(e=e.default);var d,c="function"==typeof e?e.options:e;if(t&&(c.render=t,c.staticRenderFns=i,c._compiled=!0),n&&(c.functional=!0),r&&(c._scopeId=r),s?(d=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__),o&&o.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(s)},c._ssrRegister=d):o&&(d=a?function(){o.call(this,this.$root.$options.shadowRoot)}:o),d)if(c.functional){c._injectStyles=d;var u=c.render;c.render=function(e,t){return d.call(t),u(e,t)}}else{var p=c.beforeCreate;c.beforeCreate=p?[].concat(p,d):[d]}return{exports:e,options:c}}({props:{value:{required:!0},name:{type:String,required:!1,default:()=>""},options:{type:Array,required:!1,default:()=>[]},optionLabel:{type:String,required:!1,default:()=>null},optionKey:{type:String,required:!1,default:()=>null},placeholder:{type:String,required:!1,default:()=>"Search Here"},maxHeight:{type:String,default:()=>"220px",required:!1},inputId:{type:String,default:()=>"single-select",required:!1},classes:{type:Object,required:!1,default:()=>({pointer:-1,wrapper:"single-select-wrapper",input:"search-input",icons:"icons",required:"required",activeClass:"active",dropdown:"dropdown"})},initial:{type:String,required:!1,default:()=>null},required:{type:Boolean,required:!1,default:()=>!1},maxResults:{type:Number,required:!1,default:()=>30},tabindex:{type:String,required:!1,default:()=>""},getOptionDescription:{type:Function,default(e){return this.optionKey&&this.optionLabel?e[this.optionKey]+" "+e[this.optionLabel]:this.optionLabel?e[this.optionLabel]:this.optionKey?e[this.optionKey]:e}},getOptionValue:{type:Function,default(e){return this.optionKey?e[this.optionKey]:this.optionLabel?e[this.optionLabel]:e}}},mixins:[{watch:{pointer(){this.maybeAdjustScroll()}},data:()=>({pointer:-1}),methods:{maybeAdjustScroll(){let e=this.pixelsToPointerTop(),t=this.pixelsToPointerBottom();return e<=this.viewport().top?this.scrollTo(e):t>=this.viewport().bottom?this.scrollTo(this.viewport().top+this.pointerHeight()):void 0},pixelsToPointerTop(){let e=0;if(!this.$refs.options)return 0;for(let t=0;t<this.pointer;t++)e+=this.$refs.options.children[t].offsetHeight;return e},pixelsToPointerBottom(){return this.pixelsToPointerTop()+this.pointerHeight()},pointerHeight(){let e=!!this.$refs.options&&this.$refs.options.children[this.pointer];return e?e.offsetHeight:0},viewport(){return{top:this.$refs.options?this.$refs.options.scrollTop:0,bottom:this.$refs.options?this.$refs.options.offsetHeight+this.$refs.options.scrollTop:0}},scrollTo(e){return this.$refs.options?this.$refs.options.scrollTop=e:null}}}],mounted(){document.addEventListener("click",this.handleClickOutside),document.addEventListener("keyup",this.handleClickOutside),this.value?this.selectedOption=this.value:this.searchText=this.initial},destroyed(){document.removeEventListener("keyup",this.handleClickOutside),document.removeEventListener("click",this.handleClickOutside)},data:()=>({searchText:null,selectedOption:null,dropdownOpen:!1,closed:!1}),watch:{value(e,t){e!==t&&(this.selectedOption=e)},searchText(e,t){e!==t&&(this.pointer=-1),e&&(this.closed=!1)},selectedOption(e,t){e!==t&&(this.$emit("input",e),this.closed||e||this.$nextTick().then(()=>{this.$refs.search.focus()}))},dropdownOpen(e,t){e!==t&&(this.selectedOption?this.searchText=this.getOptionDescription(this.selectedOption):e?(this.searchText||(this.searchText=""),this.$nextTick().then(()=>{this.$refs.search.focus()})):this.searchText=null)}},computed:{isRequired(){return this.required&&this.closed?this.selectedOption?"":"required":""},matchingOptions(){return null===this.searchText?null:this.searchText.length?this.optionLabel&&this.optionKey?this.options.filter(e=>e[this.optionLabel].toString().toLowerCase().includes(this.searchText.toString().toLowerCase())||e[this.optionKey].toString().toLowerCase().includes(this.searchText.toString().toLowerCase())).slice(0,this.maxResults):this.optionLabel?this.options.filter(e=>e[this.optionLabel].toString().toLowerCase().includes(this.searchText.toString().toLowerCase())).slice(0,this.maxResults):this.optionKey?this.options.filter(e=>e[this.optionKey].toString().toLowerCase().includes(this.searchText.toString().toLowerCase())).slice(0,this.maxResults):this.options.filter(e=>e.toString().toLowerCase().includes(this.searchText.toString().toLowerCase())).slice(0,this.maxResults):[...this.options].slice(0,this.maxResults)}},methods:{setPointerIdx(e){this.pointer=e},seedSearchText(){null===this.searchText&&(this.searchText="",this.closed&&(this.closed=!1))},resetSearch(){this.selectedOption=null,this.dropdownOpen=!1,this.searchText=null},switchToSearch(e){this.searchText=e.target.value,this.selectedOption=null,this.$nextTick().then(()=>{this.$refs.search.focus()})},toggleDropdown(){this.dropdownOpen=!this.dropdownOpen},closeOut(){this.selectedOption=null,this.dropdownOpen=!1,this.searchText=null,this.closed=!0},movePointerDown(){this.matchingOptions&&(this.pointer>=this.matchingOptions.length-1||this.pointer++)},movePointerUp(){this.pointer>0&&this.pointer--},setOption(){this.matchingOptions&&this.matchingOptions.length&&(-1===this.pointer&&this.pointer++,this.selectedOption=this.matchingOptions[this.pointer],this.searchText=null,this.dropdownOpen=!1,this.pointer=-1,this.$nextTick().then(()=>{this.$refs.match.focus()}))},handleClickOutside(e){this.$el.contains(e.target)||(this.dropdownOpen=!1,this.searchText=null,this.closed=!0)}}},function(){var e=this,t=e.$createElement,i=e._self._c||t;return i("div",{ref:"vuesingleselect"},[e.selectedOption?e._e():i("div",{class:e.classes.wrapper},[i("div",{staticClass:"relative inline-block w-full"},[i("input",{directives:[{name:"model",rawName:"v-model",value:e.searchText,expression:"searchText"}],ref:"search",class:[e.classes.input,e.isRequired],attrs:{id:e.inputId,placeholder:e.placeholder,autocomplete:"off",required:e.required},domProps:{value:e.searchText},on:{click:e.seedSearchText,focus:e.seedSearchText,keyup:[function(t){return"button"in t||!e._k(t.keyCode,"enter",13,t.key,"Enter")?e.setOption(t):null},function(t){return"button"in t||!e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"])?e.movePointerDown(t):null},function(t){return"button"in t||!e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"])?e.movePointerUp(t):null}],keydown:[function(t){return"button"in t||!e._k(t.keyCode,"tab",9,t.key,"Tab")?(t.stopPropagation(),e.closeOut(t)):null},function(t){return"button"in t||!e._k(t.keyCode,"esc",27,t.key,"Escape")?(t.stopPropagation(),e.closeOut(t)):null}],input:function(t){t.target.composing||(e.searchText=t.target.value)}}}),e._v(" "),i("div",{staticClass:"cursor-pointer absolute flex items-center",class:[e.classes.icons],on:{click:e.toggleDropdown}},[e.dropdownOpen?i("svg",{attrs:{"aria-hidden":"true",viewBox:"0 0 448 512"}},[i("path",{attrs:{d:"M240.971 130.524l194.343 194.343c9.373 9.373 9.373 24.569 0 33.941l-22.667 22.667c-9.357 9.357-24.522 9.375-33.901.04L224 227.495 69.255 381.516c-9.379 9.335-24.544 9.317-33.901-.04l-22.667-22.667c-9.373-9.373-9.373-24.569 0-33.941L207.03 130.525c9.372-9.373 24.568-9.373 33.941-.001z"}})]):i("svg",{attrs:{"aria-hidden":"true",viewBox:"0 0 448 512"}},[i("path",{attrs:{d:"M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"}})])]),e._v(" "),e.matchingOptions?i("ul",{ref:"options",staticClass:"absolute w-full overflow-auto appearance-none mt-px list-reset",class:[e.classes.dropdown],staticStyle:{"z-index":"100"},style:{"max-height":e.maxHeight},attrs:{tabindex:"-1"}},e._l(e.matchingOptions,function(t,n){return i("li",{key:n,staticClass:"cursor-pointer outline-none",class:n===e.pointer?e.classes.activeClass:"",attrs:{tabindex:"-1"},on:{blur:function(t){e.handleClickOutside(t)},mouseover:function(t){e.setPointerIdx(n)},keyup:[function(t){if(!("button"in t)&&e._k(t.keyCode,"enter",13,t.key,"Enter"))return null;e.setOption()},function(t){if(!("button"in t)&&e._k(t.keyCode,"up",38,t.key,["Up","ArrowUp"]))return null;e.movePointerUp()},function(t){if(!("button"in t)&&e._k(t.keyCode,"down",40,t.key,["Down","ArrowDown"]))return null;e.movePointerDown()}],click:function(t){t.preventDefault(),e.setOption()}}},[e._t("option",[e._v("\n "+e._s(e.getOptionDescription(t))+"\n\t\t\t")],null,{option:t,idx:n})],2)})):e._e()])]),e._v(" "),e.selectedOption?i("div",{class:e.classes.wrapper},[i("input",{ref:"match",class:[e.classes.input],attrs:{id:"inputId",required:e.required,placeholder:e.placeholder},domProps:{value:e.getOptionDescription(e.selectedOption)},on:{input:function(t){e.switchToSearch(t)},click:function(t){e.switchToSearch(t)}}}),e._v(" "),i("input",{ref:"selectValue",attrs:{type:"hidden",name:e.name},domProps:{value:e.getOptionValue(e.selectedOption)}}),e._v(" "),i("div",{staticClass:"cursor-pointer absolute flex items-center",class:e.classes.icons,on:{click:e.closeOut}},[i("svg",{attrs:{"aria-hidden":"true",viewBox:"0 0 512 512"},on:{click:e.closeOut}},[i("path",{attrs:{d:"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"}})])])]):e._e()])},[],!1,function(e){i(3)},"data-v-b54e43f6",null);t.a=n.exports},function(e,t,i){"use strict";i.r(t),function(e){i.d(t,"install",function(){return o});var n=i(0);function o(e){o.installed||(o.installed=!0,e.component("vue-single-select",n.a))}const r={install:o};let s=null;"undefined"!=typeof window?s=window.Vue:void 0!==e&&(s=e.Vue),s&&s.use(r)}.call(this,i(2))},function(e,t){var i;i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t,i){var n=i(4);"string"==typeof n&&(n=[[e.i,n,""]]),n.locals&&(e.exports=n.locals);(0,i(6).default)("04bd0f2d",n,!0,{})},function(e,t,i){(e.exports=i(5)(!1)).push([e.i,".inline-block[data-v-b54e43f6]{display:inline-block}.block[data-v-b54e43f6]{display:block}.flex[data-v-b54e43f6]{display:flex}.border[data-v-b54e43f6]{border-width:thin;border-style:solid}.rounded[data-v-b54e43f6]{border-radius:.25em}.text-black[data-v-b54e43f6]{color:#22292f}.border-grey-lighter[data-v-b54e43f6]{border-color:#ced4da}.bg-grey-lighter[data-v-b54e43f6]{background-color:#606f7b}.bg-grey-light[data-v-b54e43f6]{background-color:#dae1e7}.bg-grey-dark[data-v-b54e43f6]{background-color:#8795a1}.bg-white[data-v-b54e43f6]{background-color:#fff}.pin-r[data-v-b54e43f6]{right:0}.pin-y[data-v-b54e43f6]{top:0;bottom:0}.absolute[data-v-b54e43f6]{position:absolute}.relative[data-v-b54e43f6]{position:relative}.items-center[data-v-b54e43f6]{align-items:center}.p-0[data-v-b54e43f6]{padding:0}.p-1[data-v-b54e43f6]{padding:.25em}.px-1[data-v-b54e43f6]{padding-left:.25em;padding-right:.25em}.py-2[data-v-b54e43f6]{padding-top:.5em;padding-bottom:.5em}.px-2[data-v-b54e43f6]{padding-left:.5em;padding-right:.5em}.mt-px[data-v-b54e43f6]{margin-top:1px}.leading-tight[data-v-b54e43f6]{line-height:1.25}.leading-normal[data-v-b54e43f6]{line-height:1.5}.text-left[data-v-b54e43f6]{text-align:left}.w-full[data-v-b54e43f6]{width:100%}.shadow[data-v-b54e43f6]{box-shadow:0 2px 4px 0 rgba(0,0,0,.1)}.list-reset[data-v-b54e43f6]{list-style:none;padding:0}.overflow-auto[data-v-b54e43f6]{overflow:auto}.appearance-none[data-v-b54e43f6]{-webkit-appearance:none;-moz-appearance:none;appearance:none}.w-1[data-v-b54e43f6]{width:.25em}.w-2[data-v-b54e43f6]{width:.5em}.w-3[data-v-b54e43f6]{width:.75em}.w-4[data-v-b54e43f6]{width:1em}.h-4[data-v-b54e43f6]{height:1em}.h-1[data-v-b54e43f6]{height:.25em}.h-2[data-v-b54e43f6]{height:.5em}.h-3[data-v-b54e43f6]{height:.75em}.fill-current[data-v-b54e43f6]{fill:currentColor}.hover\\:no-underline[data-v-b54e43f6]:hover,.no-underline[data-v-b54e43f6]{text-decoration:none}.hover\\:outline-none[data-v-b54e43f6],.outline-none[data-v-b54e43f6]{outline:0}.hover\\:bg-grey-light[data-v-b54e43f6]:hover{background-color:#dae1e7}.shadow-md[data-v-b54e43f6]{box-shadow:0 4px 8px 0 rgba(0,0,0,.12),0 2px 4px 0 rgba(0,0,0,.08)}.search-input[data-v-b54e43f6]{display:block;width:100%;padding:.375em .75em;font-size:1em;line-height:1.5;color:#495057;background-color:#fff;background-clip:padding-box;border:1px solid #ced4da;border-radius:.25em;transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out;box-sizing:border-box}.icons[data-v-b54e43f6]{padding:0 1em;right:0;top:0;bottom:0;fill:#606f7b}.icons svg[data-v-b54e43f6]{width:.75em;height:.75em}.single-select-wrapper[data-v-b54e43f6]{position:relative;margin-bottom:.5em}.required[data-v-b54e43f6]{_color:#721c24;_background-color:#f8d7da;border-color:#f5c6cb}.cursor-pointer[data-v-b54e43f6]{cursor:pointer}.dropdown[data-v-b54e43f6]{-webkit-box-shadow:0 4px 8px 0 rgba(0,0,0,.12),0 2px 4px 0 rgba(0,0,0,.08);box-shadow:0 4px 8px 0 rgba(0,0,0,.12),0 2px 4px 0 rgba(0,0,0,.08);background-color:#fff;color:#606f7b;border-radius:.25em;line-height:1.25;text-align:left}.dropdown>li[data-v-b54e43f6]{padding:.5em .75em}.active[data-v-b54e43f6]{background:#dae1e7}",""])},function(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var i=function(e,t){var i=e[1]||"",n=e[3];if(!n)return i;if(t&&"function"==typeof btoa){var o=function(e){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(e))))+" */"}(n),r=n.sources.map(function(e){return"/*# sourceURL="+n.sourceRoot+e+" */"});return[i].concat(r).concat([o]).join("\n")}return[i].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+i+"}":i}).join("")},t.i=function(e,i){"string"==typeof e&&(e=[[null,e,""]]);for(var n={},o=0;o<this.length;o++){var r=this[o][0];"number"==typeof r&&(n[r]=!0)}for(o=0;o<e.length;o++){var s=e[o];"number"==typeof s[0]&&n[s[0]]||(i&&!s[2]?s[2]=i:i&&(s[2]="("+s[2]+") and ("+i+")"),t.push(s))}},t}},function(e,t,i){"use strict";function n(e,t){for(var i=[],n={},o=0;o<t.length;o++){var r=t[o],s=r[0],a={id:e+":"+o,css:r[1],media:r[2],sourceMap:r[3]};n[s]?n[s].parts.push(a):i.push(n[s]={id:s,parts:[a]})}return i}i.r(t),i.d(t,"default",function(){return f});var o="undefined"!=typeof document;if("undefined"!=typeof DEBUG&&DEBUG&&!o)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var r={},s=o&&(document.head||document.getElementsByTagName("head")[0]),a=null,l=0,d=!1,c=function(){},u=null,p="data-vue-ssr-id",h="undefined"!=typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());function f(e,t,i,o){d=i,u=o||{};var s=n(e,t);return v(s),function(t){for(var i=[],o=0;o<s.length;o++){var a=s[o];(l=r[a.id]).refs--,i.push(l)}t?v(s=n(e,t)):s=[];for(o=0;o<i.length;o++){var l;if(0===(l=i[o]).refs){for(var d=0;d<l.parts.length;d++)l.parts[d]();delete r[l.id]}}}}function v(e){for(var t=0;t<e.length;t++){var i=e[t],n=r[i.id];if(n){n.refs++;for(var o=0;o<n.parts.length;o++)n.parts[o](i.parts[o]);for(;o<i.parts.length;o++)n.parts.push(g(i.parts[o]));n.parts.length>i.parts.length&&(n.parts.length=i.parts.length)}else{var s=[];for(o=0;o<i.parts.length;o++)s.push(g(i.parts[o]));r[i.id]={id:i.id,refs:1,parts:s}}}}function b(){var e=document.createElement("style");return e.type="text/css",s.appendChild(e),e}function g(e){var t,i,n=document.querySelector("style["+p+'~="'+e.id+'"]');if(n){if(d)return c;n.parentNode.removeChild(n)}if(h){var o=l++;n=a||(a=b()),t=x.bind(null,n,o,!1),i=x.bind(null,n,o,!0)}else n=b(),t=function(e,t){var i=t.css,n=t.media,o=t.sourceMap;n&&e.setAttribute("media",n);u.ssrId&&e.setAttribute(p,t.id);o&&(i+="\n/*# sourceURL="+o.sources[0]+" */",i+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");if(e.styleSheet)e.styleSheet.cssText=i;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(i))}}.bind(null,n),i=function(){n.parentNode.removeChild(n)};return t(e),function(n){if(n){if(n.css===e.css&&n.media===e.media&&n.sourceMap===e.sourceMap)return;t(e=n)}else i()}}var m=function(){var e=[];return function(t,i){return e[t]=i,e.filter(Boolean).join("\n")}}();function x(e,t,i,n){var o=i?"":n.css;if(e.styleSheet)e.styleSheet.cssText=m(t,o);else{var r=document.createTextNode(o),s=e.childNodes;s[t]&&e.removeChild(s[t]),s.length?e.insertBefore(r,s[t]):e.appendChild(r)}}}])); |
{ | ||
"name": "vue-single-select", | ||
"version": "1.0.22", | ||
"version": "1.0.23", | ||
"description": "single select autocomplete dropdown for vue", | ||
@@ -56,2 +56,2 @@ "main": "dist/index", | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
432550