Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-simple-suggest

Package Overview
Dependencies
Maintainers
3
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-simple-suggest - npm Package Compare versions

Comparing version 1.6.4 to 1.7.0

208

dist/cjs.js

@@ -16,43 +16,2 @@ 'use strict';

var inputProp = {
type: String
};
var inputProps = {
type: inputProp,
accesskey: inputProp,
autocomplete: inputProp,
form: inputProp,
formaction: inputProp,
formenctype: inputProp,
formmethod: inputProp,
formtarget: inputProp,
height: inputProp,
width: inputProp,
inputmode: inputProp,
max: inputProp,
min: inputProp,
minlength: inputProp,
maxlength: inputProp,
name: inputProp,
pattern: inputProp,
placeholder: inputProp,
selectionDirection: inputProp,
selectionEnd: inputProp,
selectionStart: inputProp,
size: inputProp,
src: inputProp,
step: inputProp,
tabindex: inputProp,
title: inputProp,
spellcheck: {},
readonly: {},
required: {},
multiple: {},
formnovalidate: {},
autofocus: {},
checked: {},
disabled: {}
};
function fromPath(obj, path) {

@@ -111,4 +70,3 @@ return path.split('.').reduce(function (o, i) {

}value = Promise.resolve(value);return then ? value.then(then) : value;
}
var _async = function () {
}var _async = function () {
try {

@@ -153,5 +111,3 @@ if (isNaN.apply(null, {})) {

}_vm.isTabbed = true;
} } }, [_c('div', { ref: "inputSlot", staticClass: "input-wrapper", on: { "click": _vm.showSuggestions, "input": _vm.onInput, "keydown": function keydown($event) {
_vm.moveSelection($event), _vm.onAutocomplete($event);
}, "keyup": _vm.onListKeyUp } }, [_vm._t("default", [_c('input', _vm._b({ staticClass: "default-input", domProps: { "value": _vm.text || '' } }, 'input', _vm.$props, false))])], 2), _vm._v(" "), !!_vm.listShown && !_vm.removeList ? _c('div', { staticClass: "suggestions", on: { "mouseenter": function mouseenter($event) {
} } }, [_c('div', { ref: "inputSlot", staticClass: "input-wrapper" }, [_vm._t("default", [_c('input', _vm._b({ staticClass: "default-input", domProps: { "value": _vm.text || '' } }, 'input', _vm.$attrs, false))])], 2), _vm._v(" "), !!_vm.listShown && !_vm.removeList ? _c('div', { staticClass: "suggestions", on: { "mouseenter": function mouseenter($event) {
_vm.hoverList(true);

@@ -171,3 +127,3 @@ }, "mouseleave": function mouseleave($event) {

} } }, [_vm._t("suggestion-item", [_c('span', [_vm._v(_vm._s(_vm.displayProperty(suggestion)))])], { autocomplete: function autocomplete() {
return _vm.autocompleteText(suggestion);
return _vm.autocompleteText(_vm.displayProperty(suggestion));
}, suggestion: suggestion, query: _vm.text })], 2);

@@ -184,3 +140,3 @@ }), _vm._v(" "), _vm._t("misc-item-below", null, { suggestions: _vm.suggestions, query: _vm.text })], 2) : _vm._e()]);

},
props: Object.assign({}, inputProps, {
props: {
controls: {

@@ -198,3 +154,4 @@ type: Object,

type: Number,
default: 10 },
default: 10
},
displayAttribute: {

@@ -244,7 +201,18 @@ type: String,

}
}),
},
// Handle run-time mode changes (not working):
watch: {
mode: function mode(v) {
return event = v;
mode: {
handler: function handler(current, old) {
event = current;
},
immediate: true
},
value: {
handler: function handler(current) {
this.text = current;
},
immediate: true
}

@@ -298,15 +266,40 @@ },

this.controlScheme = Object.assign({}, defaultControls, this.controls);
event = this.mode;
},
mounted: function mounted() {
this.inputElement = this.$refs['inputSlot'].querySelector('input');
this.input[this.on]('blur', this.onBlur);
this.input[this.on]('focus', this.onFocus);
this.prepareEventHandlers(true);
},
beforeDestroy: function beforeDestroy() {
this.input[this.off]('blur', this.onBlur);
this.input[this.off]('focus', this.onFocus);
this.prepareEventHandlers(false);
},
methods: {
prepareEventHandlers: function prepareEventHandlers(enable) {
var _this2 = this;
var binder = this[enable ? 'on' : 'off'];
var keyEventsList = {
keydown: function keydown($event) {
return _this2.moveSelection($event), _this2.onAutocomplete($event);
},
keyup: this.onListKeyUp
};
var eventsList = Object.assign({
blur: this.onBlur,
focus: this.onFocus,
input: this.onInput,
click: this.showSuggestions
}, keyEventsList);
for (var _event in eventsList) {
this.input[binder](_event, eventsList[_event]);
}
var listenerBinder = enable ? 'addEventListener' : 'removeEventListener';
for (var _event2 in keyEventsList) {
this.inputElement[listenerBinder](_event2, keyEventsList[_event2]);
}
},
isScopedSlotEmpty: function isScopedSlotEmpty(slot) {

@@ -321,6 +314,6 @@ if (slot) {

miscSlotsAreEmpty: function miscSlotsAreEmpty() {
var _this2 = this;
var _this3 = this;
var slots = ['misc-item-above', 'misc-item-below'].map(function (s) {
return _this2.$scopedSlots[s];
return _this3.$scopedSlots[s];
});

@@ -340,7 +333,10 @@

},
getPropertyByAttribute: function getPropertyByAttribute(obj, attr) {
return this.isPlainSuggestion ? obj : (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== undefined ? fromPath(obj, attr) : obj;
},
displayProperty: function displayProperty(obj) {
return (this.isPlainSuggestion ? obj : fromPath(obj, this.displayAttribute)) + '';
return String(this.getPropertyByAttribute(obj, this.displayAttribute));
},
valueProperty: function valueProperty(obj) {
return this.isPlainSuggestion ? obj : fromPath(obj, this.valueAttribute);
return this.getPropertyByAttribute(obj, this.valueAttribute);
},

@@ -386,10 +382,10 @@ autocompleteText: function autocompleteText(text) {

showSuggestions: _async(function () {
var _this3 = this;
var _this4 = this;
return _invoke(function () {
if (_this3.suggestions.length === 0 && _this3.minLength === 0 && !_this3.text) {
return _awaitIgnored(_this3.research());
if (_this4.suggestions.length === 0 && _this4.minLength === 0 && !_this4.text) {
return _awaitIgnored(_this4.research());
}
}, function () {
_this3.showList();
_this4.showList();
});

@@ -464,3 +460,3 @@ }),

this.$emit('blur', e);
} else if (e.isTrusted && !this.isTabbed) {
} else if (e && e.isTrusted && !this.isTabbed) {
this.inputElement.focus();

@@ -479,3 +475,3 @@ }

// Only emit, if it was a native input focus
if (e.sourceCapabilities) {
if (e && e.sourceCapabilities) {
this.$emit('focus', e);

@@ -490,3 +486,9 @@ }

onInput: function onInput(inputEvent) {
this.text = inputEvent.target.value;
var value = !inputEvent.target ? inputEvent : inputEvent.target.value;
if (this.text === value) {
return;
}
this.text = value;
this.$emit('input', this.text);

@@ -507,3 +509,3 @@

research: _async(function () {
var _this4 = this;
var _this5 = this;

@@ -513,8 +515,8 @@ return _finally(function () {

return _invokeIgnored(function () {
if (_this4.canSend) {
_this4.canSend = false;
var _$set = _this4.$set;
return _await(_this4.getSuggestions(_this4.text), function (_this4$getSuggestions) {
_$set.call(_this4, _this4, 'suggestions', _this4$getSuggestions);
_this4.canSend = true;
if (_this5.canSend) {
_this5.canSend = false;
var _$set = _this5.$set;
return _await(_this5.getSuggestions(_this5.text), function (_this5$getSuggestions) {
_$set.call(_this5, _this5, 'suggestions', _this5$getSuggestions);
_this5.canSend = true;
});

@@ -524,37 +526,37 @@ }

}, function (e) {
_this4.clearSuggestions();
_this5.clearSuggestions();
throw e;
});
}, function () {
if (_this4.suggestions.length === 0 && _this4.miscSlotsAreEmpty()) {
_this4.hideList();
if (_this5.suggestions.length === 0 && _this5.miscSlotsAreEmpty()) {
_this5.hideList();
} else {
_this4.showList();
_this5.showList();
}
return _this4.suggestions;
return _this5.suggestions;
});
}),
getSuggestions: _async(function () {
var _this5 = this;
var _this6 = this;
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
if (_this5.listShown && !value && _this5.minLength > 0) {
_this5.hideList();
if (_this6.listShown && !value && _this6.minLength > 0) {
_this6.hideList();
return [];
}
if (value.length < _this5.minLength) {
return _this5.suggestions;
if (value.length < _this6.minLength) {
return _this6.suggestions;
}
_this5.selected = null;
_this6.selected = null;
// Start request if can
if (_this5.listIsRequest) {
_this5.$emit('request-start', value);
if (_this6.listIsRequest) {
_this6.$emit('request-start', value);
if (_this5.suggestions.length > 0 || !_this5.miscSlotsAreEmpty()) {
_this5.showList();
if (_this6.suggestions.length > 0 || !_this6.miscSlotsAreEmpty()) {
_this6.showList();
}

@@ -567,8 +569,8 @@ }

return _invoke(function () {
if (_this5.listIsRequest) {
return _await(_this5.list(value), function (_this5$list) {
result = _this5$list || [];
if (_this6.listIsRequest) {
return _await(_this6.list(value), function (_this6$list) {
result = _this6$list || [];
});
} else {
result = _this5.list;
result = _this6.list;
}

@@ -581,17 +583,17 @@ }, function () {

_this5.isPlainSuggestion = _typeof(result[0]) !== 'object' || Array.isArray(result[0]);
_this6.isPlainSuggestion = _typeof(result[0]) !== 'object' || Array.isArray(result[0]);
if (_this5.filterByQuery) {
if (_this6.filterByQuery) {
result = result.filter(function (el) {
return _this5.filter(el, value);
return _this6.filter(el, value);
});
}
if (_this5.listIsRequest) {
_this5.$emit('request-done', result);
if (_this6.listIsRequest) {
_this6.$emit('request-done', result);
}
});
}, function (e) {
if (_this5.listIsRequest) {
_this5.$emit('request-failed', e);
if (_this6.listIsRequest) {
_this6.$emit('request-failed', e);
} else {

@@ -602,4 +604,4 @@ throw e;

}, function () {
if (_this5.maxSuggestions) {
result.splice(_this5.maxSuggestions);
if (_this6.maxSuggestions) {
result.splice(_this6.maxSuggestions);
}

@@ -606,0 +608,0 @@

@@ -14,43 +14,2 @@ const defaultControls = {

const inputProp = {
type: String
};
const inputProps = {
type: inputProp,
accesskey: inputProp,
autocomplete: inputProp,
form: inputProp,
formaction: inputProp,
formenctype: inputProp,
formmethod: inputProp,
formtarget: inputProp,
height: inputProp,
width: inputProp,
inputmode: inputProp,
max: inputProp,
min: inputProp,
minlength: inputProp,
maxlength: inputProp,
name: inputProp,
pattern: inputProp,
placeholder: inputProp,
selectionDirection: inputProp,
selectionEnd: inputProp,
selectionStart: inputProp,
size: inputProp,
src: inputProp,
step: inputProp,
tabindex: inputProp,
title: inputProp,
spellcheck: {},
readonly: {},
required: {},
multiple: {},
formnovalidate: {},
autofocus: {},
checked: {},
disabled: {}
};
function fromPath(obj, path) {

@@ -95,4 +54,3 @@ return path.split('.').reduce((o, i) => o === Object(o) ? o[i] : o, obj);

}value = Promise.resolve(value);return then ? value.then(then) : value;
}
const _async = function () {
}const _async = function () {
try {

@@ -137,5 +95,3 @@ if (isNaN.apply(null, {})) {

}_vm.isTabbed = true;
} } }, [_c('div', { ref: "inputSlot", staticClass: "input-wrapper", on: { "click": _vm.showSuggestions, "input": _vm.onInput, "keydown": function ($event) {
_vm.moveSelection($event), _vm.onAutocomplete($event);
}, "keyup": _vm.onListKeyUp } }, [_vm._t("default", [_c('input', _vm._b({ staticClass: "default-input", domProps: { "value": _vm.text || '' } }, 'input', _vm.$props, false))])], 2), _vm._v(" "), !!_vm.listShown && !_vm.removeList ? _c('div', { staticClass: "suggestions", on: { "mouseenter": function ($event) {
} } }, [_c('div', { ref: "inputSlot", staticClass: "input-wrapper" }, [_vm._t("default", [_c('input', _vm._b({ staticClass: "default-input", domProps: { "value": _vm.text || '' } }, 'input', _vm.$attrs, false))])], 2), _vm._v(" "), !!_vm.listShown && !_vm.removeList ? _c('div', { staticClass: "suggestions", on: { "mouseenter": function ($event) {
_vm.hoverList(true);

@@ -155,3 +111,3 @@ }, "mouseleave": function ($event) {

} } }, [_vm._t("suggestion-item", [_c('span', [_vm._v(_vm._s(_vm.displayProperty(suggestion)))])], { autocomplete: function () {
return _vm.autocompleteText(suggestion);
return _vm.autocompleteText(_vm.displayProperty(suggestion));
}, suggestion: suggestion, query: _vm.text })], 2);

@@ -168,3 +124,3 @@ }), _vm._v(" "), _vm._t("misc-item-below", null, { suggestions: _vm.suggestions, query: _vm.text })], 2) : _vm._e()]);

},
props: Object.assign({}, inputProps, {
props: {
controls: {

@@ -180,3 +136,4 @@ type: Object,

type: Number,
default: 10 },
default: 10
},
displayAttribute: {

@@ -222,6 +179,17 @@ type: String,

}
}),
},
// Handle run-time mode changes (not working):
watch: {
mode: v => event = v
mode: {
handler(current, old) {
event = current;
},
immediate: true
},
value: {
handler(current) {
this.text = current;
},
immediate: true
}
},

@@ -269,14 +237,35 @@ //

this.controlScheme = Object.assign({}, defaultControls, this.controls);
event = this.mode;
},
mounted() {
this.inputElement = this.$refs['inputSlot'].querySelector('input');
this.input[this.on]('blur', this.onBlur);
this.input[this.on]('focus', this.onFocus);
this.prepareEventHandlers(true);
},
beforeDestroy() {
this.input[this.off]('blur', this.onBlur);
this.input[this.off]('focus', this.onFocus);
this.prepareEventHandlers(false);
},
methods: {
prepareEventHandlers(enable) {
const binder = this[enable ? 'on' : 'off'];
const keyEventsList = {
keydown: $event => (this.moveSelection($event), this.onAutocomplete($event)),
keyup: this.onListKeyUp
};
const eventsList = Object.assign({
blur: this.onBlur,
focus: this.onFocus,
input: this.onInput,
click: this.showSuggestions
}, keyEventsList);
for (const event in eventsList) {
this.input[binder](event, eventsList[event]);
}
const listenerBinder = enable ? 'addEventListener' : 'removeEventListener';
for (const event in keyEventsList) {
this.inputElement[listenerBinder](event, keyEventsList[event]);
}
},
isScopedSlotEmpty(slot) {

@@ -301,7 +290,10 @@ if (slot) {

},
getPropertyByAttribute(obj, attr) {
return this.isPlainSuggestion ? obj : typeof obj !== undefined ? fromPath(obj, attr) : obj;
},
displayProperty(obj) {
return (this.isPlainSuggestion ? obj : fromPath(obj, this.displayAttribute)) + '';
return String(this.getPropertyByAttribute(obj, this.displayAttribute));
},
valueProperty(obj) {
return this.isPlainSuggestion ? obj : fromPath(obj, this.valueAttribute);
return this.getPropertyByAttribute(obj, this.valueAttribute);
},

@@ -425,3 +417,3 @@ autocompleteText(text) {

this.$emit('blur', e);
} else if (e.isTrusted && !this.isTabbed) {
} else if (e && e.isTrusted && !this.isTabbed) {
this.inputElement.focus();

@@ -441,3 +433,3 @@ }

// Only emit, if it was a native input focus
if (e.sourceCapabilities) {
if (e && e.sourceCapabilities) {
this.$emit('focus', e);

@@ -452,3 +444,9 @@ }

onInput(inputEvent) {
this.text = inputEvent.target.value;
const value = !inputEvent.target ? inputEvent : inputEvent.target.value;
if (this.text === value) {
return;
}
this.text = value;
this.$emit('input', this.text);

@@ -455,0 +453,0 @@

@@ -14,43 +14,2 @@ const defaultControls = {

const inputProp = {
type: String
};
const inputProps = {
type: inputProp,
accesskey: inputProp,
autocomplete: inputProp,
form: inputProp,
formaction: inputProp,
formenctype: inputProp,
formmethod: inputProp,
formtarget: inputProp,
height: inputProp,
width: inputProp,
inputmode: inputProp,
max: inputProp,
min: inputProp,
minlength: inputProp,
maxlength: inputProp,
name: inputProp,
pattern: inputProp,
placeholder: inputProp,
selectionDirection: inputProp,
selectionEnd: inputProp,
selectionStart: inputProp,
size: inputProp,
src: inputProp,
step: inputProp,
tabindex: inputProp,
title: inputProp,
spellcheck: {},
readonly: {},
required: {},
multiple: {},
formnovalidate: {},
autofocus: {},
checked: {},
disabled: {}
};
function fromPath(obj, path) {

@@ -79,5 +38,3 @@ return path.split('.').reduce((o, i) => o === Object(o) ? o[i] : o, obj);

}_vm.isTabbed = true;
} } }, [_c('div', { ref: "inputSlot", staticClass: "input-wrapper", on: { "click": _vm.showSuggestions, "input": _vm.onInput, "keydown": function ($event) {
_vm.moveSelection($event), _vm.onAutocomplete($event);
}, "keyup": _vm.onListKeyUp } }, [_vm._t("default", [_c('input', _vm._b({ staticClass: "default-input", domProps: { "value": _vm.text || '' } }, 'input', _vm.$props, false))])], 2), _vm._v(" "), !!_vm.listShown && !_vm.removeList ? _c('div', { staticClass: "suggestions", on: { "mouseenter": function ($event) {
} } }, [_c('div', { ref: "inputSlot", staticClass: "input-wrapper" }, [_vm._t("default", [_c('input', _vm._b({ staticClass: "default-input", domProps: { "value": _vm.text || '' } }, 'input', _vm.$attrs, false))])], 2), _vm._v(" "), !!_vm.listShown && !_vm.removeList ? _c('div', { staticClass: "suggestions", on: { "mouseenter": function ($event) {
_vm.hoverList(true);

@@ -97,3 +54,3 @@ }, "mouseleave": function ($event) {

} } }, [_vm._t("suggestion-item", [_c('span', [_vm._v(_vm._s(_vm.displayProperty(suggestion)))])], { autocomplete: function () {
return _vm.autocompleteText(suggestion);
return _vm.autocompleteText(_vm.displayProperty(suggestion));
}, suggestion: suggestion, query: _vm.text })], 2);

@@ -110,3 +67,3 @@ }), _vm._v(" "), _vm._t("misc-item-below", null, { suggestions: _vm.suggestions, query: _vm.text })], 2) : _vm._e()]);

},
props: Object.assign({}, inputProps, {
props: {
controls: {

@@ -164,6 +121,17 @@ type: Object,

}
}),
},
// Handle run-time mode changes (not working):
watch: {
mode: v => event = v
mode: {
handler(current, old) {
event = current;
},
immediate: true
},
value: {
handler(current) {
this.text = current;
},
immediate: true
}
},

@@ -211,14 +179,35 @@ //

this.controlScheme = Object.assign({}, defaultControls, this.controls);
event = this.mode;
},
mounted() {
this.inputElement = this.$refs['inputSlot'].querySelector('input');
this.input[this.on]('blur', this.onBlur);
this.input[this.on]('focus', this.onFocus);
this.prepareEventHandlers(true);
},
beforeDestroy() {
this.input[this.off]('blur', this.onBlur);
this.input[this.off]('focus', this.onFocus);
this.prepareEventHandlers(false);
},
methods: {
prepareEventHandlers(enable) {
const binder = this[enable ? 'on' : 'off'];
const keyEventsList = {
keydown: $event => (this.moveSelection($event), this.onAutocomplete($event)),
keyup: this.onListKeyUp
};
const eventsList = Object.assign({
blur: this.onBlur,
focus: this.onFocus,
input: this.onInput,
click: this.showSuggestions
}, keyEventsList);
for (const event in eventsList) {
this.input[binder](event, eventsList[event]);
}
const listenerBinder = enable ? 'addEventListener' : 'removeEventListener';
for (const event in keyEventsList) {
this.inputElement[listenerBinder](event, keyEventsList[event]);
}
},
isScopedSlotEmpty(slot) {

@@ -243,7 +232,10 @@ if (slot) {

},
getPropertyByAttribute(obj, attr) {
return this.isPlainSuggestion ? obj : typeof obj !== undefined ? fromPath(obj, attr) : obj;
},
displayProperty(obj) {
return (this.isPlainSuggestion ? obj : fromPath(obj, this.displayAttribute)) + '';
return String(this.getPropertyByAttribute(obj, this.displayAttribute));
},
valueProperty(obj) {
return this.isPlainSuggestion ? obj : fromPath(obj, this.valueAttribute);
return this.getPropertyByAttribute(obj, this.valueAttribute);
},

@@ -362,3 +354,3 @@ autocompleteText(text) {

this.$emit('blur', e);
} else if (e.isTrusted && !this.isTabbed) {
} else if (e && e.isTrusted && !this.isTabbed) {
this.inputElement.focus();

@@ -378,3 +370,3 @@ }

// Only emit, if it was a native input focus
if (e.sourceCapabilities) {
if (e && e.sourceCapabilities) {
this.$emit('focus', e);

@@ -389,3 +381,9 @@ }

onInput(inputEvent) {
this.text = inputEvent.target.value;
const value = !inputEvent.target ? inputEvent : inputEvent.target.value;
if (this.text === value) {
return;
}
this.text = value;
this.$emit('input', this.text);

@@ -392,0 +390,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},i={type:String},n={type:i,accesskey:i,autocomplete:i,form:i,formaction:i,formenctype:i,formmethod:i,formtarget:i,height:i,width:i,inputmode:i,max:i,min:i,minlength:i,maxlength:i,name:i,pattern:i,placeholder:i,selectionDirection:i,selectionEnd:i,selectionStart:i,size:i,src:i,step:i,tabindex:i,title:i,spellcheck:{},readonly:{},required:{},multiple:{},formnovalidate:{},autofocus:{},checked:{},disabled:{}};function s(t,e){return e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},t)}function o(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 r="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},u=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 l(t,e){try{var i=t()}catch(t){return e()}return i&&i.then?i.then(e,e):e()}function c(t,e){try{var i=t()}catch(t){return e(t)}return i&&i.then?i.then(void 0,e):i}function h(t,e,i){return i?e?e(t):t:(t=Promise.resolve(t),e?t.then(e):t)}var a=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 f(t,e){var i=t();return i&&i.then?i.then(e):e(i)}function p(){}var g="input",d={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",on:{click:t.showSuggestions,input:t.onInput,keydown:function(e){t.moveSelection(e),t.onAutocomplete(e)},keyup:t.onListKeyUp}},[t._t("default",[i("input",t._b({staticClass:"default-input",domProps:{value:t.text||""}},"input",t.$props,!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(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 g}},props:u({},n,{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:g,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}}),watch:{mode:function(t){return g=t}},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=u({},t,this.controls),g=this.mode},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.input[this.on]("blur",this.onBlur),this.input[this.on]("focus",this.onFocus)},beforeDestroy:function(){this.input[this.off]("blur",this.onBlur),this.input[this.off]("focus",this.onFocus)},methods:{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)},displayProperty:function(t){return(this.isPlainSuggestion?t:s(t,this.displayAttribute))+""},valueProperty:function(t){return this.isPlainSuggestion?t:s(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:a(function(){var t=this;return f(function(){if(0===t.suggestions.length&&0===t.minLength&&!t.text)return function(t,e){if(!e)return Promise.resolve(t).then(p)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(o([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=o(this.controlScheme.selectionDown,t),i=2*e-1,n=e?0:this.suggestions.length-1,s=e?this.hoveredIndex<this.suggestions.length-1:this.hoveredIndex>0,r=null;r=this.hovered?s?this.suggestions[this.hoveredIndex+i]:this.suggestions[n]:this.selected||this.suggestions[n],this.hover(r)}},onListKeyUp:function(t){var e=this.controlScheme.select;o([e,this.controlScheme.hideList],t)&&(t.preventDefault(),this.listShown?(o(e,t)&&this.hovered&&this.select(this.hovered),this.hideList()):o(e,t)&&this.research())},onAutocomplete:function(t){o(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.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.sourceCapabilities&&this.$emit("focus",t),this.isClicking||this.showList()},onInput:function(t){this.text=t.target.value,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:a(function(){var t=this;return l(function(){return c(function(){return function(t){var e=t();if(e&&e.then)return e.then(p)}(function(){if(t.canSend){t.canSend=!1;var e=t.$set;return h(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:a(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 l(function(){return c(function(){return f(function(){if(t.listIsRequest)return h(t.list(e),function(t){i=t||[]});i=t.list},function(){Array.isArray(i)||(i=[i]),t.isPlainSuggestion="object"!==r(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",d),d}();
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}();

@@ -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},i={type:String},n={type:i,accesskey:i,autocomplete:i,form:i,formaction:i,formenctype:i,formmethod:i,formtarget:i,height:i,width:i,inputmode:i,max:i,min:i,minlength:i,maxlength:i,name:i,pattern:i,placeholder:i,selectionDirection:i,selectionEnd:i,selectionStart:i,size:i,src:i,step:i,tabindex:i,title:i,spellcheck:{},readonly:{},required:{},multiple:{},formnovalidate:{},autofocus:{},checked:{},disabled:{}};function s(t,e){return e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},t)}function o(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 u="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 r(t,e){try{var i=t()}catch(t){return e()}return i&&i.then?i.then(e,e):e()}function l(t,e){try{var i=t()}catch(t){return e(t)}return i&&i.then?i.then(void 0,e):i}function c(t,e,i){return i?e?e(t):t:(t=Promise.resolve(t),e?t.then(e):t)}var h=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 a(t,e){var i=t();return i&&i.then?i.then(e):e(i)}function f(){}var p="input",d={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",on:{click:t.showSuggestions,input:t.onInput,keydown:function(e){t.moveSelection(e),t.onAutocomplete(e)},keyup:t.onListKeyUp}},[t._t("default",[i("input",t._b({staticClass:"default-input",domProps:{value:t.text||""}},"input",t.$props,!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(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 p}},props:Object.assign({},n,{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:p,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}}),watch:{mode:function(t){return p=t}},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),p=this.mode},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.input[this.on]("blur",this.onBlur),this.input[this.on]("focus",this.onFocus)},beforeDestroy:function(){this.input[this.off]("blur",this.onBlur),this.input[this.off]("focus",this.onFocus)},methods:{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)},displayProperty:function(t){return(this.isPlainSuggestion?t:s(t,this.displayAttribute))+""},valueProperty:function(t){return this.isPlainSuggestion?t:s(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:h(function(){var t=this;return a(function(){if(0===t.suggestions.length&&0===t.minLength&&!t.text)return function(t,e){if(!e)return Promise.resolve(t).then(f)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(o([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=o(this.controlScheme.selectionDown,t),i=2*e-1,n=e?0:this.suggestions.length-1,s=e?this.hoveredIndex<this.suggestions.length-1:this.hoveredIndex>0,u=null;u=this.hovered?s?this.suggestions[this.hoveredIndex+i]:this.suggestions[n]:this.selected||this.suggestions[n],this.hover(u)}},onListKeyUp:function(t){var e=this.controlScheme.select;o([e,this.controlScheme.hideList],t)&&(t.preventDefault(),this.listShown?(o(e,t)&&this.hovered&&this.select(this.hovered),this.hideList()):o(e,t)&&this.research())},onAutocomplete:function(t){o(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.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.sourceCapabilities&&this.$emit("focus",t),this.isClicking||this.showList()},onInput:function(t){this.text=t.target.value,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:h(function(){var t=this;return r(function(){return l(function(){return function(t){var e=t();if(e&&e.then)return e.then(f)}(function(){if(t.canSend){t.canSend=!1;var e=t.$set;return c(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:h(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 r(function(){return l(function(){return a(function(){if(t.listIsRequest)return c(t.list(e),function(t){i=t||[]});i=t.list},function(){Array.isArray(i)||(i=[i]),t.isPlainSuggestion="object"!==u(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",d),d});
!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});

@@ -14,43 +14,2 @@ export const defaultControls = {

const inputProp = {
type: String
}
export const inputProps = {
type: inputProp,
accesskey: inputProp,
autocomplete: inputProp,
form: inputProp,
formaction: inputProp,
formenctype: inputProp,
formmethod: inputProp,
formtarget: inputProp,
height: inputProp,
width: inputProp,
inputmode: inputProp,
max: inputProp,
min: inputProp,
minlength: inputProp,
maxlength: inputProp,
name: inputProp,
pattern: inputProp,
placeholder: inputProp,
selectionDirection: inputProp,
selectionEnd: inputProp,
selectionStart: inputProp,
size: inputProp,
src: inputProp,
step: inputProp,
tabindex: inputProp,
title: inputProp,
spellcheck: {},
readonly: {},
required: {},
multiple: {},
formnovalidate: {},
autofocus: {},
checked: {},
disabled: {},
}
export function fromPath(obj, path) {

@@ -57,0 +16,0 @@ return path.split('.').reduce((o, i) => (o === Object(o) ? o[i] : o), obj);

{
"name": "vue-simple-suggest",
"description": "Feature-rich autocomplete component for Vue.js",
"version": "1.6.4",
"version": "1.7.0",
"author": "KazanExpress",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -267,3 +267,3 @@ # vue-simple-suggest

:list="getListFunction"
:max-count="10"
:max-suggestions="10"
:min-length="3"

@@ -457,4 +457,2 @@ :debounce="100"

**To work with the `vue-simple-suggest` your custom input component MUST emit `focus` and `blur` events!**
**Warning:** `v-model` on a custom input IS NOT the same as `v-model` on vue-simple-suggest!

@@ -485,3 +483,3 @@

<!-- Vanilla HTMLInputElement example 4 (nested): -->
<vue-simple-suggest>
<vue-simple-suggest v-model="model">
<div>

@@ -496,7 +494,27 @@ <section>

<!-- Vue component example (also supports nesting): -->
<vue-simple-suggest>
<my-custom-input-somponent></my-custom-input-somponent>
<vue-simple-suggest v-model="vModelGoesHere">
<my-custom-input-somponent :value="initialInputValueGoesHere"></my-custom-input-somponent>
</vue-simple-suggest>
```
**Custom input component caveats:**
To work with the `vue-simple-suggest` your custom input component has to follow certain standard behaviours.
Custom input component **must** (in order to work properly):
- Emit an `input` event.
- Emit `focus` and `blur` events.
- Have a `value` prop.
Custom input component **should** (in order to avoid usage limitations):
- Not stop any event propagations from internal input HTML element.
- Forward an original event argument with `focus` and `blur` events.
If `vue-simple-suggest` with your custom component doesn't seem to react to outside variable changes - bind both components' v-model to the same variable, like so:
```html
<vue-simple-suggest v-model="model">
<my-custom-input-somponent v-model="model"></my-custom-input-somponent>
</vue-simple-suggest>
```
##### Custom suggestion item

@@ -566,3 +584,7 @@ > `suggestion-item` slot (optional)

```js
boldenSuggestion({ suggestion, query }) {
boldenSuggestion(scope) {
if (!scope) return scope;
const { suggestion, query } = scope;
let result = this.$refs.suggestComponent.displayProperty(suggestion);

@@ -569,0 +591,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc