vue-simple-suggest
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -255,2 +255,5 @@ 'use strict'; | ||
}); | ||
}, | ||
textLength: function textLength() { | ||
return this.text && this.text.length || this.inputElement.value.length || 0; | ||
} | ||
@@ -276,2 +279,3 @@ }, | ||
var keyEventsList = { | ||
click: this.showSuggestions, | ||
keydown: function keydown($event) { | ||
@@ -285,4 +289,3 @@ return _this2.moveSelection($event), _this2.onAutocomplete($event); | ||
focus: this.onFocus, | ||
input: this.onInput, | ||
click: this.showSuggestions | ||
input: this.onInput | ||
}, keyEventsList); | ||
@@ -367,4 +370,3 @@ | ||
if (!this.listShown) { | ||
var textLength = this.text && this.text.length || 0; | ||
if (textLength >= this.minLength && (this.suggestions.length > 0 || !this.miscSlotsAreEmpty())) { | ||
if (this.textLength >= this.minLength && (this.suggestions.length > 0 || !this.miscSlotsAreEmpty())) { | ||
this.listShown = true; | ||
@@ -379,3 +381,3 @@ this.$emit('show-list'); | ||
return _invoke(function () { | ||
if (_this4.suggestions.length === 0 && _this4.minLength === 0 && !_this4.text) { | ||
if (_this4.suggestions.length === 0 && _this4.minLength === _this4.textLength) { | ||
return _awaitIgnored(_this4.research()); | ||
@@ -474,3 +476,3 @@ } | ||
if (!this.isClicking) { | ||
this.showList(); | ||
this.showSuggestions(); | ||
} | ||
@@ -511,3 +513,2 @@ }, | ||
_$set.call(_this5, _this5, 'suggestions', _this5$getSuggestions); | ||
_this5.canSend = true; | ||
}); | ||
@@ -521,2 +522,4 @@ } | ||
}, function () { | ||
_this5.canSend = true; | ||
if (_this5.suggestions.length === 0 && _this5.miscSlotsAreEmpty()) { | ||
@@ -531,13 +534,13 @@ _this5.hideList(); | ||
}), | ||
getSuggestions: _async(function () { | ||
getSuggestions: _async(function (value) { | ||
var _this6 = this; | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
value = value || ''; | ||
if (_this6.listShown && !value && _this6.minLength > 0) { | ||
_this6.hideList(); | ||
return []; | ||
} | ||
if (value.length < _this6.minLength) { | ||
if (_this6.listShown) { | ||
_this6.hideList(); | ||
return []; | ||
} | ||
if (value.length < _this6.minLength) { | ||
return _this6.suggestions; | ||
@@ -544,0 +547,0 @@ } |
@@ -226,2 +226,5 @@ const defaultControls = { | ||
return this.suggestions.findIndex(el => this.hovered && this.valueProperty(this.hovered) == this.valueProperty(el)); | ||
}, | ||
textLength() { | ||
return this.text && this.text.length || this.inputElement.value.length || 0; | ||
} | ||
@@ -244,2 +247,3 @@ }, | ||
const keyEventsList = { | ||
click: this.showSuggestions, | ||
keydown: $event => (this.moveSelection($event), this.onAutocomplete($event)), | ||
@@ -251,4 +255,3 @@ keyup: this.onListKeyUp | ||
focus: this.onFocus, | ||
input: this.onInput, | ||
click: this.showSuggestions | ||
input: this.onInput | ||
}, keyEventsList); | ||
@@ -325,4 +328,3 @@ | ||
if (!this.listShown) { | ||
const textLength = this.text && this.text.length || 0; | ||
if (textLength >= this.minLength && (this.suggestions.length > 0 || !this.miscSlotsAreEmpty())) { | ||
if (this.textLength >= this.minLength && (this.suggestions.length > 0 || !this.miscSlotsAreEmpty())) { | ||
this.listShown = true; | ||
@@ -337,3 +339,3 @@ this.$emit('show-list'); | ||
return _invoke(function () { | ||
if (_this.suggestions.length === 0 && _this.minLength === 0 && !_this.text) { | ||
if (_this.suggestions.length === 0 && _this.minLength === _this.textLength) { | ||
return _awaitIgnored(_this.research()); | ||
@@ -434,3 +436,3 @@ } | ||
if (!this.isClicking) { | ||
this.showList(); | ||
this.showSuggestions(); | ||
} | ||
@@ -471,3 +473,2 @@ }, | ||
_$set.call(_this2, _this2, 'suggestions', _this2$getSuggestions); | ||
_this2.canSend = true; | ||
}); | ||
@@ -481,2 +482,4 @@ } | ||
}, function () { | ||
_this2.canSend = true; | ||
if (_this2.suggestions.length === 0 && _this2.miscSlotsAreEmpty()) { | ||
@@ -491,11 +494,13 @@ _this2.hideList(); | ||
}), | ||
getSuggestions: _async(function (value = '') { | ||
getSuggestions: _async(function (value) { | ||
var _this3 = this; | ||
if (_this3.listShown && !value && _this3.minLength > 0) { | ||
_this3.hideList(); | ||
return []; | ||
} | ||
value = value || ''; | ||
if (value.length < _this3.minLength) { | ||
if (_this3.listShown) { | ||
_this3.hideList(); | ||
return []; | ||
} | ||
return _this3.suggestions; | ||
@@ -502,0 +507,0 @@ } |
@@ -170,2 +170,5 @@ const defaultControls = { | ||
return this.suggestions.findIndex(el => this.hovered && this.valueProperty(this.hovered) == this.valueProperty(el)); | ||
}, | ||
textLength() { | ||
return this.text && this.text.length || this.inputElement.value.length || 0; | ||
} | ||
@@ -188,2 +191,3 @@ }, | ||
const keyEventsList = { | ||
click: this.showSuggestions, | ||
keydown: $event => (this.moveSelection($event), this.onAutocomplete($event)), | ||
@@ -195,4 +199,3 @@ keyup: this.onListKeyUp | ||
focus: this.onFocus, | ||
input: this.onInput, | ||
click: this.showSuggestions | ||
input: this.onInput | ||
}, keyEventsList); | ||
@@ -269,4 +272,3 @@ | ||
if (!this.listShown) { | ||
const textLength = this.text && this.text.length || 0; | ||
if (textLength >= this.minLength && (this.suggestions.length > 0 || !this.miscSlotsAreEmpty())) { | ||
if (this.textLength >= this.minLength && (this.suggestions.length > 0 || !this.miscSlotsAreEmpty())) { | ||
this.listShown = true; | ||
@@ -278,3 +280,3 @@ this.$emit('show-list'); | ||
async showSuggestions() { | ||
if (this.suggestions.length === 0 && this.minLength === 0 && !this.text) { | ||
if (this.suggestions.length === 0 && this.minLength === this.textLength) { | ||
await this.research(); | ||
@@ -373,3 +375,3 @@ } | ||
if (!this.isClicking) { | ||
this.showList(); | ||
this.showSuggestions(); | ||
} | ||
@@ -404,3 +406,2 @@ }, | ||
this.$set(this, 'suggestions', (await this.getSuggestions(this.text))); | ||
this.canSend = true; | ||
} | ||
@@ -411,2 +412,4 @@ } catch (e) { | ||
} finally { | ||
this.canSend = true; | ||
if (this.suggestions.length === 0 && this.miscSlotsAreEmpty()) { | ||
@@ -421,9 +424,11 @@ this.hideList(); | ||
}, | ||
async getSuggestions(value = '') { | ||
if (this.listShown && !value && this.minLength > 0) { | ||
this.hideList(); | ||
return []; | ||
} | ||
async getSuggestions(value) { | ||
value = value || ''; | ||
if (value.length < this.minLength) { | ||
if (this.listShown) { | ||
this.hideList(); | ||
return []; | ||
} | ||
return this.suggestions; | ||
@@ -430,0 +435,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var VueSimpleSuggest=function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],autocomplete:[32,13]},e={input:String,select:Object};function i(t,e){if(t.length<=0)return!1;var i=function(t){return t.some(function(t){return t===e.keyCode})};return Array.isArray(t[0])?t.some(function(t){return i(t)}):i(t)}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t};function o(t,e){try{var i=t()}catch(t){return e()}return i&&i.then?i.then(e,e):e()}function r(t,e){try{var i=t()}catch(t){return e(t)}return i&&i.then?i.then(void 0,e):i}function u(t,e,i){return i?e?e(t):t:(t=Promise.resolve(t),e?t.then(e):t)}var l=function(){try{if(isNaN.apply(null,{}))return function(t){return function(){try{return Promise.resolve(t.apply(this,arguments))}catch(t){return Promise.reject(t)}}}}catch(t){}return function(t){return function(){try{return Promise.resolve(t.apply(this,Array.prototype.slice.call(arguments)))}catch(t){return Promise.reject(t)}}}}();function c(t,e){var i=t();return i&&i.then?i.then(e):e(i)}function h(){}var a="input",f={render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("div",{staticClass:"vue-simple-suggest",class:{designed:!t.destyled,focus:t.isInFocus},on:{keydown:function(e){if(!("button"in e)&&t._k(e.keyCode,"tab",9,e.key,"Tab"))return null;t.isTabbed=!0}}},[i("div",{ref:"inputSlot",staticClass:"input-wrapper"},[t._t("default",[i("input",t._b({staticClass:"default-input",domProps:{value:t.text||""}},"input",t.$attrs,!1))])],2),t._v(" "),t.listShown&&!t.removeList?i("div",{staticClass:"suggestions",on:{mouseenter:function(e){t.hoverList(!0)},mouseleave:function(e){t.hoverList(!1)}}},[t._t("misc-item-above",null,{suggestions:t.suggestions,query:t.text}),t._v(" "),t._l(t.suggestions,function(e,n){return i("div",{key:t.isPlainSuggestion?"suggestion-"+n:t.valueProperty(e),staticClass:"suggest-item",class:{selected:t.selected&&t.valueProperty(e)==t.valueProperty(t.selected),hover:t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)},on:{mouseenter:function(i){t.hover(e,i.target)},mouseleave:function(e){t.hover(null,e.target)},click:function(i){t.suggestionClick(e,i)}}},[t._t("suggestion-item",[i("span",[t._v(t._s(t.displayProperty(e)))])],{autocomplete:function(){return t.autocompleteText(t.displayProperty(e))},suggestion:e,query:t.text})],2)}),t._v(" "),t._t("misc-item-below",null,{suggestions:t.suggestions,query:t.text})],2):t._e()])},staticRenderFns:[],name:"vue-simple-suggest",model:{prop:"value",get event(){return a}},props:{controls:{type:Object,default:function(){return t}},minLength:{type:Number,default:1},maxSuggestions:{type:Number,default:10},displayAttribute:{type:String,default:"title"},valueAttribute:{type:String,default:"id"},list:{type:[Function,Array],default:function(){return[]}},removeList:{type:Boolean,default:!1},destyled:{type:Boolean,default:!1},filterByQuery:{type:Boolean,default:!1},filter:{type:Function,default:function(t,e){return!e||~this.displayProperty(t).toLowerCase().indexOf(e.toLowerCase())}},debounce:{type:Number,default:0},value:{},mode:{type:String,default:a,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t,e){a=t},immediate:!0},value:{handler:function(t){this.text=t},immediate:!0}},data:function(){return{selected:null,hovered:null,suggestions:[],listShown:!1,inputElement:null,canSend:!0,timeoutInstance:null,text:this.value,isPlainSuggestion:!1,isClicking:!1,isOverList:!1,isInFocus:!1,isTabbed:!1,controlScheme:{}}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&this.$slots.default.length>0&&!!this.$slots.default[0].componentInstance},input:function(){return this.inputIsComponent?this.$slots.default[0].componentInstance:this.inputElement},on:function(){return this.inputIsComponent?"$on":"addEventListener"},off:function(){return this.inputIsComponent?"$off":"removeEventListener"},hoveredIndex:function(){var t=this;return this.suggestions.findIndex(function(e){return t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)})}},created:function(){this.controlScheme=s({},t,this.controls)},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.prepareEventHandlers(!0)},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{prepareEventHandlers:function(t){var e=this,i=this[t?"on":"off"],n={keydown:function(t){return e.moveSelection(t),e.onAutocomplete(t)},keyup:this.onListKeyUp},o=s({blur:this.onBlur,focus:this.onFocus,input:this.onInput,click:this.showSuggestions},n);for(var r in o)this.input[i](r,o[r]);var u=t?"addEventListener":"removeEventListener";for(var l in n)this.inputElement[u](l,n[l])},isScopedSlotEmpty:function(t){if(t){var e=t(this);return!(Array.isArray(e)||e&&(e.tag||e.context||e.text||e.children))}return!0},miscSlotsAreEmpty:function(){var t=this,e=["misc-item-above","misc-item-below"].map(function(e){return t.$scopedSlots[e]});if(e.every(function(t){return!!t}))return e.every(this.isScopedSlotEmpty.bind(this));var i=e.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,i)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":n(t))?function(t,e){return e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},t)}(t,e):t},displayProperty:function(t){return String(this.getPropertyByAttribute(t,this.displayAttribute))},valueProperty:function(t){return this.getPropertyByAttribute(t,this.valueAttribute)},autocompleteText:function(t){this.$emit("input",t),this.inputElement.value=t,this.text=t},select:function(t){this.hovered=null,this.selected=t,this.$emit("select",t),this.autocompleteText(this.displayProperty(t))},hover:function(t,e){this.hovered=t,null!=this.hovered&&this.$emit("hover",t,e)},hoverList:function(t){this.isOverList=t},hideList:function(){this.listShown&&(this.listShown=!1,this.$emit("hide-list"))},showList:function(){this.listShown||(this.text&&this.text.length||0)>=this.minLength&&(this.suggestions.length>0||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:l(function(){var t=this;return c(function(){if(0===t.suggestions.length&&0===t.minLength&&!t.text)return function(t,e){if(!e)return Promise.resolve(t).then(h)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(i([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=i(this.controlScheme.selectionDown,t),n=2*e-1,s=e?0:this.suggestions.length-1,o=e?this.hoveredIndex<this.suggestions.length-1:this.hoveredIndex>0,r=null;r=this.hovered?o?this.suggestions[this.hoveredIndex+n]:this.suggestions[s]:this.selected||this.suggestions[s],this.hover(r)}},onListKeyUp:function(t){var e=this.controlScheme.select;i([e,this.controlScheme.hideList],t)&&(t.preventDefault(),this.listShown?(i(e,t)&&this.hovered&&this.select(this.hovered),this.hideList()):i(e,t)&&this.research())},onAutocomplete:function(t){i(this.controlScheme.autocomplete,t)&&(t.ctrlKey||t.shiftKey)&&this.suggestions.length>0&&this.suggestions[0]&&this.listShown&&(t.preventDefault(),this.hover(this.suggestions[0]),this.autocompleteText(this.displayProperty(this.suggestions[0])))},suggestionClick:function(t,e){this.$emit("suggestion-click",t,e),this.select(t),this.hideList(),this.isClicking=this.isOverList=!1},onBlur:function(t){this.isInFocus?(this.isClicking=this.isOverList&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&this.inputElement.focus():(this.isInFocus=!1,this.hideList(),this.$emit("blur",t))):(this.inputElement.blur(),console.error("This should never happen!\n If you encouneterd this error, please report at https://github.com/KazanExpress/vue-simple-suggest/issues")),this.isTabbed=!1},onFocus:function(t){this.isInFocus=!0,t&&t.sourceCapabilities&&this.$emit("focus",t),this.isClicking||this.showList()},onInput:function(t){var e=t.target?t.target.value:t;this.text!==e&&(this.text=e,this.$emit("input",this.text),this.selected&&(this.selected=null,this.$emit("select",null)),this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:l(function(){var t=this;return o(function(){return r(function(){return function(t){var e=t();if(e&&e.then)return e.then(h)}(function(){if(t.canSend){t.canSend=!1;var e=t.$set;return u(t.getSuggestions(t.text),function(i){e.call(t,t,"suggestions",i),t.canSend=!0})}})},function(e){throw t.clearSuggestions(),e})},function(){return 0===t.suggestions.length&&t.miscSlotsAreEmpty()?t.hideList():t.showList(),t.suggestions})}),getSuggestions:l(function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(t.listShown&&!e&&t.minLength>0)return t.hideList(),[];if(e.length<t.minLength)return t.suggestions;t.selected=null,t.listIsRequest&&(t.$emit("request-start",e),(t.suggestions.length>0||!t.miscSlotsAreEmpty())&&t.showList());var i=[];return o(function(){return r(function(){return c(function(){if(t.listIsRequest)return u(t.list(e),function(t){i=t||[]});i=t.list},function(){Array.isArray(i)||(i=[i]),t.isPlainSuggestion="object"!==n(i[0])||Array.isArray(i[0]),t.filterByQuery&&(i=i.filter(function(i){return t.filter(i,e)})),t.listIsRequest&&t.$emit("request-done",i)})},function(e){if(!t.listIsRequest)throw e;t.$emit("request-failed",e)})},function(){return t.maxSuggestions&&i.splice(t.maxSuggestions),i})}),clearSuggestions:function(){this.suggestions.splice(0)}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",f),f}(); | ||
var VueSimpleSuggest=function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],autocomplete:[32,13]},e={input:String,select:Object};function n(t,e){if(t.length<=0)return!1;var n=function(t){return t.some(function(t){return t===e.keyCode})};return Array.isArray(t[0])?t.some(function(t){return n(t)}):n(t)}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t};function o(t,e){try{var n=t()}catch(t){return e()}return n&&n.then?n.then(e,e):e()}function r(t,e){try{var n=t()}catch(t){return e(t)}return n&&n.then?n.then(void 0,e):n}function u(t,e,n){return n?e?e(t):t:(t=Promise.resolve(t),e?t.then(e):t)}var l=function(){try{if(isNaN.apply(null,{}))return function(t){return function(){try{return Promise.resolve(t.apply(this,arguments))}catch(t){return Promise.reject(t)}}}}catch(t){}return function(t){return function(){try{return Promise.resolve(t.apply(this,Array.prototype.slice.call(arguments)))}catch(t){return Promise.reject(t)}}}}();function c(t,e){var n=t();return n&&n.then?n.then(e):e(n)}function h(){}var a="input",f={render:function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"vue-simple-suggest",class:{designed:!t.destyled,focus:t.isInFocus},on:{keydown:function(e){if(!("button"in e)&&t._k(e.keyCode,"tab",9,e.key,"Tab"))return null;t.isTabbed=!0}}},[n("div",{ref:"inputSlot",staticClass:"input-wrapper"},[t._t("default",[n("input",t._b({staticClass:"default-input",domProps:{value:t.text||""}},"input",t.$attrs,!1))])],2),t._v(" "),t.listShown&&!t.removeList?n("div",{staticClass:"suggestions",on:{mouseenter:function(e){t.hoverList(!0)},mouseleave:function(e){t.hoverList(!1)}}},[t._t("misc-item-above",null,{suggestions:t.suggestions,query:t.text}),t._v(" "),t._l(t.suggestions,function(e,i){return n("div",{key:t.isPlainSuggestion?"suggestion-"+i:t.valueProperty(e),staticClass:"suggest-item",class:{selected:t.selected&&t.valueProperty(e)==t.valueProperty(t.selected),hover:t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)},on:{mouseenter:function(n){t.hover(e,n.target)},mouseleave:function(e){t.hover(null,e.target)},click:function(n){t.suggestionClick(e,n)}}},[t._t("suggestion-item",[n("span",[t._v(t._s(t.displayProperty(e)))])],{autocomplete:function(){return t.autocompleteText(t.displayProperty(e))},suggestion:e,query:t.text})],2)}),t._v(" "),t._t("misc-item-below",null,{suggestions:t.suggestions,query:t.text})],2):t._e()])},staticRenderFns:[],name:"vue-simple-suggest",model:{prop:"value",get event(){return a}},props:{controls:{type:Object,default:function(){return t}},minLength:{type:Number,default:1},maxSuggestions:{type:Number,default:10},displayAttribute:{type:String,default:"title"},valueAttribute:{type:String,default:"id"},list:{type:[Function,Array],default:function(){return[]}},removeList:{type:Boolean,default:!1},destyled:{type:Boolean,default:!1},filterByQuery:{type:Boolean,default:!1},filter:{type:Function,default:function(t,e){return!e||~this.displayProperty(t).toLowerCase().indexOf(e.toLowerCase())}},debounce:{type:Number,default:0},value:{},mode:{type:String,default:a,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t,e){a=t},immediate:!0},value:{handler:function(t){this.text=t},immediate:!0}},data:function(){return{selected:null,hovered:null,suggestions:[],listShown:!1,inputElement:null,canSend:!0,timeoutInstance:null,text:this.value,isPlainSuggestion:!1,isClicking:!1,isOverList:!1,isInFocus:!1,isTabbed:!1,controlScheme:{}}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&this.$slots.default.length>0&&!!this.$slots.default[0].componentInstance},input:function(){return this.inputIsComponent?this.$slots.default[0].componentInstance:this.inputElement},on:function(){return this.inputIsComponent?"$on":"addEventListener"},off:function(){return this.inputIsComponent?"$off":"removeEventListener"},hoveredIndex:function(){var t=this;return this.suggestions.findIndex(function(e){return t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)})},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0}},created:function(){this.controlScheme=s({},t,this.controls)},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.prepareEventHandlers(!0)},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{prepareEventHandlers:function(t){var e=this,n=this[t?"on":"off"],i={click:this.showSuggestions,keydown:function(t){return e.moveSelection(t),e.onAutocomplete(t)},keyup:this.onListKeyUp},o=s({blur:this.onBlur,focus:this.onFocus,input:this.onInput},i);for(var r in o)this.input[n](r,o[r]);var u=t?"addEventListener":"removeEventListener";for(var l in i)this.inputElement[u](l,i[l])},isScopedSlotEmpty:function(t){if(t){var e=t(this);return!(Array.isArray(e)||e&&(e.tag||e.context||e.text||e.children))}return!0},miscSlotsAreEmpty:function(){var t=this,e=["misc-item-above","misc-item-below"].map(function(e){return t.$scopedSlots[e]});if(e.every(function(t){return!!t}))return e.every(this.isScopedSlotEmpty.bind(this));var n=e.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,n)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":i(t))?function(t,e){return e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},t)}(t,e):t},displayProperty:function(t){return String(this.getPropertyByAttribute(t,this.displayAttribute))},valueProperty:function(t){return this.getPropertyByAttribute(t,this.valueAttribute)},autocompleteText:function(t){this.$emit("input",t),this.inputElement.value=t,this.text=t},select:function(t){this.hovered=null,this.selected=t,this.$emit("select",t),this.autocompleteText(this.displayProperty(t))},hover:function(t,e){this.hovered=t,null!=this.hovered&&this.$emit("hover",t,e)},hoverList:function(t){this.isOverList=t},hideList:function(){this.listShown&&(this.listShown=!1,this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(this.suggestions.length>0||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:l(function(){var t=this;return c(function(){if(0===t.suggestions.length&&t.minLength===t.textLength)return function(t,e){if(!e)return Promise.resolve(t).then(h)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(n([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=n(this.controlScheme.selectionDown,t),i=2*e-1,s=e?0:this.suggestions.length-1,o=e?this.hoveredIndex<this.suggestions.length-1:this.hoveredIndex>0,r=null;r=this.hovered?o?this.suggestions[this.hoveredIndex+i]:this.suggestions[s]:this.selected||this.suggestions[s],this.hover(r)}},onListKeyUp:function(t){var e=this.controlScheme.select;n([e,this.controlScheme.hideList],t)&&(t.preventDefault(),this.listShown?(n(e,t)&&this.hovered&&this.select(this.hovered),this.hideList()):n(e,t)&&this.research())},onAutocomplete:function(t){n(this.controlScheme.autocomplete,t)&&(t.ctrlKey||t.shiftKey)&&this.suggestions.length>0&&this.suggestions[0]&&this.listShown&&(t.preventDefault(),this.hover(this.suggestions[0]),this.autocompleteText(this.displayProperty(this.suggestions[0])))},suggestionClick:function(t,e){this.$emit("suggestion-click",t,e),this.select(t),this.hideList(),this.isClicking=this.isOverList=!1},onBlur:function(t){this.isInFocus?(this.isClicking=this.isOverList&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&this.inputElement.focus():(this.isInFocus=!1,this.hideList(),this.$emit("blur",t))):(this.inputElement.blur(),console.error("This should never happen!\n If you encouneterd this error, please report at https://github.com/KazanExpress/vue-simple-suggest/issues")),this.isTabbed=!1},onFocus:function(t){this.isInFocus=!0,t&&t.sourceCapabilities&&this.$emit("focus",t),this.isClicking||this.showSuggestions()},onInput:function(t){var e=t.target?t.target.value:t;this.text!==e&&(this.text=e,this.$emit("input",this.text),this.selected&&(this.selected=null,this.$emit("select",null)),this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:l(function(){var t=this;return o(function(){return r(function(){return function(t){var e=t();if(e&&e.then)return e.then(h)}(function(){if(t.canSend){t.canSend=!1;var e=t.$set;return u(t.getSuggestions(t.text),function(n){e.call(t,t,"suggestions",n)})}})},function(e){throw t.clearSuggestions(),e})},function(){return t.canSend=!0,0===t.suggestions.length&&t.miscSlotsAreEmpty()?t.hideList():t.showList(),t.suggestions})}),getSuggestions:l(function(t){var e=this;if((t=t||"").length<e.minLength)return e.listShown?(e.hideList(),[]):e.suggestions;e.selected=null,e.listIsRequest&&(e.$emit("request-start",t),(e.suggestions.length>0||!e.miscSlotsAreEmpty())&&e.showList());var n=[];return o(function(){return r(function(){return c(function(){if(e.listIsRequest)return u(e.list(t),function(t){n=t||[]});n=e.list},function(){Array.isArray(n)||(n=[n]),e.isPlainSuggestion="object"!==i(n[0])||Array.isArray(n[0]),e.filterByQuery&&(n=n.filter(function(n){return e.filter(n,t)})),e.listIsRequest&&e.$emit("request-done",n)})},function(t){if(!e.listIsRequest)throw t;e.$emit("request-failed",t)})},function(){return e.maxSuggestions&&n.splice(e.maxSuggestions),n})}),clearSuggestions:function(){this.suggestions.splice(0)}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",f),f}(); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueSimpleSuggest=e()}(this,function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],autocomplete:[32,13]},e={input:String,select:Object};function i(t,e){if(t.length<=0)return!1;var i=function(t){return t.some(function(t){return t===e.keyCode})};return Array.isArray(t[0])?t.some(function(t){return i(t)}):i(t)}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function s(t,e){try{var i=t()}catch(t){return e()}return i&&i.then?i.then(e,e):e()}function o(t,e){try{var i=t()}catch(t){return e(t)}return i&&i.then?i.then(void 0,e):i}function r(t,e,i){return i?e?e(t):t:(t=Promise.resolve(t),e?t.then(e):t)}var u=function(){try{if(isNaN.apply(null,{}))return function(t){return function(){try{return Promise.resolve(t.apply(this,arguments))}catch(t){return Promise.reject(t)}}}}catch(t){}return function(t){return function(){try{return Promise.resolve(t.apply(this,Array.prototype.slice.call(arguments)))}catch(t){return Promise.reject(t)}}}}();function l(t,e){var i=t();return i&&i.then?i.then(e):e(i)}function c(){}var h="input",a={render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("div",{staticClass:"vue-simple-suggest",class:{designed:!t.destyled,focus:t.isInFocus},on:{keydown:function(e){if(!("button"in e)&&t._k(e.keyCode,"tab",9,e.key,"Tab"))return null;t.isTabbed=!0}}},[i("div",{ref:"inputSlot",staticClass:"input-wrapper"},[t._t("default",[i("input",t._b({staticClass:"default-input",domProps:{value:t.text||""}},"input",t.$attrs,!1))])],2),t._v(" "),t.listShown&&!t.removeList?i("div",{staticClass:"suggestions",on:{mouseenter:function(e){t.hoverList(!0)},mouseleave:function(e){t.hoverList(!1)}}},[t._t("misc-item-above",null,{suggestions:t.suggestions,query:t.text}),t._v(" "),t._l(t.suggestions,function(e,n){return i("div",{key:t.isPlainSuggestion?"suggestion-"+n:t.valueProperty(e),staticClass:"suggest-item",class:{selected:t.selected&&t.valueProperty(e)==t.valueProperty(t.selected),hover:t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)},on:{mouseenter:function(i){t.hover(e,i.target)},mouseleave:function(e){t.hover(null,e.target)},click:function(i){t.suggestionClick(e,i)}}},[t._t("suggestion-item",[i("span",[t._v(t._s(t.displayProperty(e)))])],{autocomplete:function(){return t.autocompleteText(t.displayProperty(e))},suggestion:e,query:t.text})],2)}),t._v(" "),t._t("misc-item-below",null,{suggestions:t.suggestions,query:t.text})],2):t._e()])},staticRenderFns:[],name:"vue-simple-suggest",model:{prop:"value",get event(){return h}},props:{controls:{type:Object,default:function(){return t}},minLength:{type:Number,default:1},maxSuggestions:{type:Number,default:10},displayAttribute:{type:String,default:"title"},valueAttribute:{type:String,default:"id"},list:{type:[Function,Array],default:function(){return[]}},removeList:{type:Boolean,default:!1},destyled:{type:Boolean,default:!1},filterByQuery:{type:Boolean,default:!1},filter:{type:Function,default:function(t,e){return!e||~this.displayProperty(t).toLowerCase().indexOf(e.toLowerCase())}},debounce:{type:Number,default:0},value:{},mode:{type:String,default:h,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t,e){h=t},immediate:!0},value:{handler:function(t){this.text=t},immediate:!0}},data:function(){return{selected:null,hovered:null,suggestions:[],listShown:!1,inputElement:null,canSend:!0,timeoutInstance:null,text:this.value,isPlainSuggestion:!1,isClicking:!1,isOverList:!1,isInFocus:!1,isTabbed:!1,controlScheme:{}}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&this.$slots.default.length>0&&!!this.$slots.default[0].componentInstance},input:function(){return this.inputIsComponent?this.$slots.default[0].componentInstance:this.inputElement},on:function(){return this.inputIsComponent?"$on":"addEventListener"},off:function(){return this.inputIsComponent?"$off":"removeEventListener"},hoveredIndex:function(){var t=this;return this.suggestions.findIndex(function(e){return t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)})}},created:function(){this.controlScheme=Object.assign({},t,this.controls)},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.prepareEventHandlers(!0)},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{prepareEventHandlers:function(t){var e=this,i=this[t?"on":"off"],n={keydown:function(t){return e.moveSelection(t),e.onAutocomplete(t)},keyup:this.onListKeyUp},s=Object.assign({blur:this.onBlur,focus:this.onFocus,input:this.onInput,click:this.showSuggestions},n);for(var o in s)this.input[i](o,s[o]);var r=t?"addEventListener":"removeEventListener";for(var u in n)this.inputElement[r](u,n[u])},isScopedSlotEmpty:function(t){if(t){var e=t(this);return!(Array.isArray(e)||e&&(e.tag||e.context||e.text||e.children))}return!0},miscSlotsAreEmpty:function(){var t=this,e=["misc-item-above","misc-item-below"].map(function(e){return t.$scopedSlots[e]});if(e.every(function(t){return!!t}))return e.every(this.isScopedSlotEmpty.bind(this));var i=e.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,i)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":n(t))?function(t,e){return e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},t)}(t,e):t},displayProperty:function(t){return String(this.getPropertyByAttribute(t,this.displayAttribute))},valueProperty:function(t){return this.getPropertyByAttribute(t,this.valueAttribute)},autocompleteText:function(t){this.$emit("input",t),this.inputElement.value=t,this.text=t},select:function(t){this.hovered=null,this.selected=t,this.$emit("select",t),this.autocompleteText(this.displayProperty(t))},hover:function(t,e){this.hovered=t,null!=this.hovered&&this.$emit("hover",t,e)},hoverList:function(t){this.isOverList=t},hideList:function(){this.listShown&&(this.listShown=!1,this.$emit("hide-list"))},showList:function(){this.listShown||(this.text&&this.text.length||0)>=this.minLength&&(this.suggestions.length>0||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:u(function(){var t=this;return l(function(){if(0===t.suggestions.length&&0===t.minLength&&!t.text)return function(t,e){if(!e)return Promise.resolve(t).then(c)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(i([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=i(this.controlScheme.selectionDown,t),n=2*e-1,s=e?0:this.suggestions.length-1,o=e?this.hoveredIndex<this.suggestions.length-1:this.hoveredIndex>0,r=null;r=this.hovered?o?this.suggestions[this.hoveredIndex+n]:this.suggestions[s]:this.selected||this.suggestions[s],this.hover(r)}},onListKeyUp:function(t){var e=this.controlScheme.select;i([e,this.controlScheme.hideList],t)&&(t.preventDefault(),this.listShown?(i(e,t)&&this.hovered&&this.select(this.hovered),this.hideList()):i(e,t)&&this.research())},onAutocomplete:function(t){i(this.controlScheme.autocomplete,t)&&(t.ctrlKey||t.shiftKey)&&this.suggestions.length>0&&this.suggestions[0]&&this.listShown&&(t.preventDefault(),this.hover(this.suggestions[0]),this.autocompleteText(this.displayProperty(this.suggestions[0])))},suggestionClick:function(t,e){this.$emit("suggestion-click",t,e),this.select(t),this.hideList(),this.isClicking=this.isOverList=!1},onBlur:function(t){this.isInFocus?(this.isClicking=this.isOverList&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&this.inputElement.focus():(this.isInFocus=!1,this.hideList(),this.$emit("blur",t))):(this.inputElement.blur(),console.error("This should never happen!\n If you encouneterd this error, please report at https://github.com/KazanExpress/vue-simple-suggest/issues")),this.isTabbed=!1},onFocus:function(t){this.isInFocus=!0,t&&t.sourceCapabilities&&this.$emit("focus",t),this.isClicking||this.showList()},onInput:function(t){var e=t.target?t.target.value:t;this.text!==e&&(this.text=e,this.$emit("input",this.text),this.selected&&(this.selected=null,this.$emit("select",null)),this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:u(function(){var t=this;return s(function(){return o(function(){return function(t){var e=t();if(e&&e.then)return e.then(c)}(function(){if(t.canSend){t.canSend=!1;var e=t.$set;return r(t.getSuggestions(t.text),function(i){e.call(t,t,"suggestions",i),t.canSend=!0})}})},function(e){throw t.clearSuggestions(),e})},function(){return 0===t.suggestions.length&&t.miscSlotsAreEmpty()?t.hideList():t.showList(),t.suggestions})}),getSuggestions:u(function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(t.listShown&&!e&&t.minLength>0)return t.hideList(),[];if(e.length<t.minLength)return t.suggestions;t.selected=null,t.listIsRequest&&(t.$emit("request-start",e),(t.suggestions.length>0||!t.miscSlotsAreEmpty())&&t.showList());var i=[];return s(function(){return o(function(){return l(function(){if(t.listIsRequest)return r(t.list(e),function(t){i=t||[]});i=t.list},function(){Array.isArray(i)||(i=[i]),t.isPlainSuggestion="object"!==n(i[0])||Array.isArray(i[0]),t.filterByQuery&&(i=i.filter(function(i){return t.filter(i,e)})),t.listIsRequest&&t.$emit("request-done",i)})},function(e){if(!t.listIsRequest)throw e;t.$emit("request-failed",e)})},function(){return t.maxSuggestions&&i.splice(t.maxSuggestions),i})}),clearSuggestions:function(){this.suggestions.splice(0)}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",a),a}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueSimpleSuggest=e()}(this,function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],autocomplete:[32,13]},e={input:String,select:Object};function n(t,e){if(t.length<=0)return!1;var n=function(t){return t.some(function(t){return t===e.keyCode})};return Array.isArray(t[0])?t.some(function(t){return n(t)}):n(t)}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function s(t,e){try{var n=t()}catch(t){return e()}return n&&n.then?n.then(e,e):e()}function o(t,e){try{var n=t()}catch(t){return e(t)}return n&&n.then?n.then(void 0,e):n}function r(t,e,n){return n?e?e(t):t:(t=Promise.resolve(t),e?t.then(e):t)}var u=function(){try{if(isNaN.apply(null,{}))return function(t){return function(){try{return Promise.resolve(t.apply(this,arguments))}catch(t){return Promise.reject(t)}}}}catch(t){}return function(t){return function(){try{return Promise.resolve(t.apply(this,Array.prototype.slice.call(arguments)))}catch(t){return Promise.reject(t)}}}}();function l(t,e){var n=t();return n&&n.then?n.then(e):e(n)}function c(){}var h="input",a={render:function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"vue-simple-suggest",class:{designed:!t.destyled,focus:t.isInFocus},on:{keydown:function(e){if(!("button"in e)&&t._k(e.keyCode,"tab",9,e.key,"Tab"))return null;t.isTabbed=!0}}},[n("div",{ref:"inputSlot",staticClass:"input-wrapper"},[t._t("default",[n("input",t._b({staticClass:"default-input",domProps:{value:t.text||""}},"input",t.$attrs,!1))])],2),t._v(" "),t.listShown&&!t.removeList?n("div",{staticClass:"suggestions",on:{mouseenter:function(e){t.hoverList(!0)},mouseleave:function(e){t.hoverList(!1)}}},[t._t("misc-item-above",null,{suggestions:t.suggestions,query:t.text}),t._v(" "),t._l(t.suggestions,function(e,i){return n("div",{key:t.isPlainSuggestion?"suggestion-"+i:t.valueProperty(e),staticClass:"suggest-item",class:{selected:t.selected&&t.valueProperty(e)==t.valueProperty(t.selected),hover:t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)},on:{mouseenter:function(n){t.hover(e,n.target)},mouseleave:function(e){t.hover(null,e.target)},click:function(n){t.suggestionClick(e,n)}}},[t._t("suggestion-item",[n("span",[t._v(t._s(t.displayProperty(e)))])],{autocomplete:function(){return t.autocompleteText(t.displayProperty(e))},suggestion:e,query:t.text})],2)}),t._v(" "),t._t("misc-item-below",null,{suggestions:t.suggestions,query:t.text})],2):t._e()])},staticRenderFns:[],name:"vue-simple-suggest",model:{prop:"value",get event(){return h}},props:{controls:{type:Object,default:function(){return t}},minLength:{type:Number,default:1},maxSuggestions:{type:Number,default:10},displayAttribute:{type:String,default:"title"},valueAttribute:{type:String,default:"id"},list:{type:[Function,Array],default:function(){return[]}},removeList:{type:Boolean,default:!1},destyled:{type:Boolean,default:!1},filterByQuery:{type:Boolean,default:!1},filter:{type:Function,default:function(t,e){return!e||~this.displayProperty(t).toLowerCase().indexOf(e.toLowerCase())}},debounce:{type:Number,default:0},value:{},mode:{type:String,default:h,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t,e){h=t},immediate:!0},value:{handler:function(t){this.text=t},immediate:!0}},data:function(){return{selected:null,hovered:null,suggestions:[],listShown:!1,inputElement:null,canSend:!0,timeoutInstance:null,text:this.value,isPlainSuggestion:!1,isClicking:!1,isOverList:!1,isInFocus:!1,isTabbed:!1,controlScheme:{}}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&this.$slots.default.length>0&&!!this.$slots.default[0].componentInstance},input:function(){return this.inputIsComponent?this.$slots.default[0].componentInstance:this.inputElement},on:function(){return this.inputIsComponent?"$on":"addEventListener"},off:function(){return this.inputIsComponent?"$off":"removeEventListener"},hoveredIndex:function(){var t=this;return this.suggestions.findIndex(function(e){return t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)})},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0}},created:function(){this.controlScheme=Object.assign({},t,this.controls)},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.prepareEventHandlers(!0)},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{prepareEventHandlers:function(t){var e=this,n=this[t?"on":"off"],i={click:this.showSuggestions,keydown:function(t){return e.moveSelection(t),e.onAutocomplete(t)},keyup:this.onListKeyUp},s=Object.assign({blur:this.onBlur,focus:this.onFocus,input:this.onInput},i);for(var o in s)this.input[n](o,s[o]);var r=t?"addEventListener":"removeEventListener";for(var u in i)this.inputElement[r](u,i[u])},isScopedSlotEmpty:function(t){if(t){var e=t(this);return!(Array.isArray(e)||e&&(e.tag||e.context||e.text||e.children))}return!0},miscSlotsAreEmpty:function(){var t=this,e=["misc-item-above","misc-item-below"].map(function(e){return t.$scopedSlots[e]});if(e.every(function(t){return!!t}))return e.every(this.isScopedSlotEmpty.bind(this));var n=e.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,n)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":i(t))?function(t,e){return e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},t)}(t,e):t},displayProperty:function(t){return String(this.getPropertyByAttribute(t,this.displayAttribute))},valueProperty:function(t){return this.getPropertyByAttribute(t,this.valueAttribute)},autocompleteText:function(t){this.$emit("input",t),this.inputElement.value=t,this.text=t},select:function(t){this.hovered=null,this.selected=t,this.$emit("select",t),this.autocompleteText(this.displayProperty(t))},hover:function(t,e){this.hovered=t,null!=this.hovered&&this.$emit("hover",t,e)},hoverList:function(t){this.isOverList=t},hideList:function(){this.listShown&&(this.listShown=!1,this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(this.suggestions.length>0||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:u(function(){var t=this;return l(function(){if(0===t.suggestions.length&&t.minLength===t.textLength)return function(t,e){if(!e)return Promise.resolve(t).then(c)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(n([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=n(this.controlScheme.selectionDown,t),i=2*e-1,s=e?0:this.suggestions.length-1,o=e?this.hoveredIndex<this.suggestions.length-1:this.hoveredIndex>0,r=null;r=this.hovered?o?this.suggestions[this.hoveredIndex+i]:this.suggestions[s]:this.selected||this.suggestions[s],this.hover(r)}},onListKeyUp:function(t){var e=this.controlScheme.select;n([e,this.controlScheme.hideList],t)&&(t.preventDefault(),this.listShown?(n(e,t)&&this.hovered&&this.select(this.hovered),this.hideList()):n(e,t)&&this.research())},onAutocomplete:function(t){n(this.controlScheme.autocomplete,t)&&(t.ctrlKey||t.shiftKey)&&this.suggestions.length>0&&this.suggestions[0]&&this.listShown&&(t.preventDefault(),this.hover(this.suggestions[0]),this.autocompleteText(this.displayProperty(this.suggestions[0])))},suggestionClick:function(t,e){this.$emit("suggestion-click",t,e),this.select(t),this.hideList(),this.isClicking=this.isOverList=!1},onBlur:function(t){this.isInFocus?(this.isClicking=this.isOverList&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&this.inputElement.focus():(this.isInFocus=!1,this.hideList(),this.$emit("blur",t))):(this.inputElement.blur(),console.error("This should never happen!\n If you encouneterd this error, please report at https://github.com/KazanExpress/vue-simple-suggest/issues")),this.isTabbed=!1},onFocus:function(t){this.isInFocus=!0,t&&t.sourceCapabilities&&this.$emit("focus",t),this.isClicking||this.showSuggestions()},onInput:function(t){var e=t.target?t.target.value:t;this.text!==e&&(this.text=e,this.$emit("input",this.text),this.selected&&(this.selected=null,this.$emit("select",null)),this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:u(function(){var t=this;return s(function(){return o(function(){return function(t){var e=t();if(e&&e.then)return e.then(c)}(function(){if(t.canSend){t.canSend=!1;var e=t.$set;return r(t.getSuggestions(t.text),function(n){e.call(t,t,"suggestions",n)})}})},function(e){throw t.clearSuggestions(),e})},function(){return t.canSend=!0,0===t.suggestions.length&&t.miscSlotsAreEmpty()?t.hideList():t.showList(),t.suggestions})}),getSuggestions:u(function(t){var e=this;if((t=t||"").length<e.minLength)return e.listShown?(e.hideList(),[]):e.suggestions;e.selected=null,e.listIsRequest&&(e.$emit("request-start",t),(e.suggestions.length>0||!e.miscSlotsAreEmpty())&&e.showList());var n=[];return s(function(){return o(function(){return l(function(){if(e.listIsRequest)return r(e.list(t),function(t){n=t||[]});n=e.list},function(){Array.isArray(n)||(n=[n]),e.isPlainSuggestion="object"!==i(n[0])||Array.isArray(n[0]),e.filterByQuery&&(n=n.filter(function(n){return e.filter(n,t)})),e.listIsRequest&&e.$emit("request-done",n)})},function(t){if(!e.listIsRequest)throw t;e.$emit("request-failed",t)})},function(){return e.maxSuggestions&&n.splice(e.maxSuggestions),n})}),clearSuggestions:function(){this.suggestions.splice(0)}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",a),a}); |
{ | ||
"name": "vue-simple-suggest", | ||
"description": "Feature-rich autocomplete component for Vue.js", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"author": "KazanExpress", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -349,3 +349,3 @@ # vue-simple-suggest | ||
| `filter-by-query` | Boolean | `false` | Whether to filter the resulting suggestions by input's text query (make it a search component). | | ||
| `filter` | Function | - | A custom function for filtering the suggestion results. Used only if `filter-by-query` is set `true`. | | ||
| `filter` | Function | - | A custom function for filtering the suggestion results that accepts a single item and a query to filter by as its 2 arguments. Used only if `filter-by-query` is set to `true`. | | ||
| `mode` <sup>[v1.4.0](https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.4.0)</sup> | String | `'input'` | The `v-model` event. Determines the event, that triggers `v-model`. Can be one of `'input'` (`v-model` binds a displayed property) or `'select'` (`v-model` binds a selected item). | | ||
@@ -352,0 +352,0 @@ | `type`, `value`, `pattern`, etc... | | | All of the HTML5 input attributes with their respected default values. | |
Sorry, the diff of this file is not supported yet
139466
1744