vue-simple-suggest
Advanced tools
Comparing version 1.10.3 to 1.10.4
134
dist/cjs.js
@@ -50,3 +50,9 @@ 'use strict'; | ||
function _empty() {}function _awaitIgnored(value, direct) { | ||
function _await(value, then, direct) { | ||
if (direct) { | ||
return then ? then(value) : value; | ||
}if (!value || !value.then) { | ||
value = Promise.resolve(value); | ||
}return then ? value.then(then) : value; | ||
}function _empty() {}function _awaitIgnored(value, direct) { | ||
if (!direct) { | ||
@@ -57,11 +63,4 @@ return value && value.then ? value.then(_empty) : Promise.resolve(); | ||
var result = body();if (result && result.then) { | ||
return result.then(then); | ||
}return then(result); | ||
}function _await(value, then, direct) { | ||
if (direct) { | ||
return then ? then(value) : value; | ||
}if (!value || !value.then) { | ||
value = Promise.resolve(value); | ||
}return then ? value.then(then) : value; | ||
}function _invokeIgnored(body) { | ||
@@ -76,5 +75,7 @@ var result = body();if (result && result.then) { | ||
return recover(e); | ||
}if (result && result.then) { | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
}return result; | ||
} | ||
return result; | ||
}function _finally(body, finalizer) { | ||
@@ -276,6 +277,19 @@ try { | ||
mounted: function mounted() { | ||
this.inputElement = this.$refs['inputSlot'].querySelector('input'); | ||
try { | ||
var _this3 = this; | ||
this.setInputAriaAttributes(); | ||
this.prepareEventHandlers(true); | ||
return _await(_this3.$slots.default, function () { | ||
_this3.inputElement = _this3.$refs['inputSlot'].querySelector('input'); | ||
if (_this3.inputElement) { | ||
_this3.setInputAriaAttributes(); | ||
_this3.prepareEventHandlers(true); | ||
} else { | ||
console.error('No input element found'); | ||
} | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}, | ||
@@ -333,6 +347,6 @@ beforeDestroy: function beforeDestroy() { | ||
miscSlotsAreEmpty: function miscSlotsAreEmpty() { | ||
var _this2 = this; | ||
var _this4 = this; | ||
var slots = ['misc-item-above', 'misc-item-below'].map(function (s) { | ||
return _this2.$scopedSlots[s]; | ||
return _this4.$scopedSlots[s]; | ||
}); | ||
@@ -389,8 +403,8 @@ | ||
setText: function setText(text) { | ||
var _this3 = this; | ||
var _this5 = this; | ||
this.$nextTick(function () { | ||
_this3.inputElement.value = text; | ||
_this3.text = text; | ||
_this3.$emit('input', text); | ||
_this5.inputElement.value = text; | ||
_this5.text = text; | ||
_this5.$emit('input', text); | ||
}); | ||
@@ -438,13 +452,13 @@ }, | ||
try { | ||
var _this5 = this; | ||
var _this7 = this; | ||
return _invoke(function () { | ||
if (_this5.suggestions.length === 0 && _this5.minLength <= _this5.textLength) { | ||
if (_this7.suggestions.length === 0 && _this7.minLength <= _this7.textLength) { | ||
// try show misc slots while researching | ||
_this5.showList(); | ||
return _awaitIgnored(_this5.research()); | ||
_this7.showList(); | ||
return _awaitIgnored(_this7.research()); | ||
} | ||
}, function () { | ||
_this5.showList(); | ||
_this7.showList(); | ||
}); | ||
@@ -528,3 +542,3 @@ } catch (e) { | ||
onBlur: function onBlur(e) { | ||
var _this6 = this; | ||
var _this8 = this; | ||
@@ -545,3 +559,3 @@ if (this.isInFocus) { | ||
setTimeout(function () { | ||
_this6.inputElement.focus(); | ||
_this8.inputElement.focus(); | ||
}, 0); | ||
@@ -557,3 +571,5 @@ } | ||
onFocus: function onFocus(e) { | ||
this.isInFocus = true; // Only emit, if it was a native input focus | ||
this.isInFocus = true; | ||
// Only emit, if it was a native input focus | ||
if (e && !this.isFalseFocus) { | ||
@@ -598,3 +614,3 @@ this.$emit('focus', e); | ||
try { | ||
var _this8 = this; | ||
var _this10 = this; | ||
@@ -604,9 +620,9 @@ return _finally(function () { | ||
return _invokeIgnored(function () { | ||
if (_this8.canSend) { | ||
_this8.canSend = false; | ||
if (_this10.canSend) { | ||
_this10.canSend = false; | ||
// @TODO: fix when promises will be cancelable (never :D) | ||
var textBeforeRequest = _this8.text; | ||
return _await(_this8.getSuggestions(_this8.text), function (newList) { | ||
if (textBeforeRequest === _this8.text) { | ||
_this8.$set(_this8, 'suggestions', newList); | ||
var textBeforeRequest = _this10.text; | ||
return _await(_this10.getSuggestions(_this10.text), function (newList) { | ||
if (textBeforeRequest === _this10.text) { | ||
_this10.$set(_this10, 'suggestions', newList); | ||
} | ||
@@ -617,15 +633,15 @@ }); | ||
}, function (e) { | ||
_this8.clearSuggestions(); | ||
_this10.clearSuggestions(); | ||
throw e; | ||
}); | ||
}, function () { | ||
_this8.canSend = true; | ||
_this10.canSend = true; | ||
if (_this8.suggestions.length === 0 && _this8.miscSlotsAreEmpty()) { | ||
_this8.hideList(); | ||
} else if (_this8.isInFocus) { | ||
_this8.showList(); | ||
if (_this10.suggestions.length === 0 && _this10.miscSlotsAreEmpty()) { | ||
_this10.hideList(); | ||
} else if (_this10.isInFocus) { | ||
_this10.showList(); | ||
} | ||
return _this8.suggestions; | ||
return _this10.suggestions; | ||
}); | ||
@@ -638,15 +654,15 @@ } catch (e) { | ||
try { | ||
var _this10 = this; | ||
var _this12 = this; | ||
value = value || ''; | ||
if (value.length < _this10.minLength) { | ||
if (value.length < _this12.minLength) { | ||
return []; | ||
} | ||
_this10.selected = null; | ||
_this12.selected = null; | ||
// Start request if can | ||
if (_this10.listIsRequest) { | ||
_this10.$emit('request-start', value); | ||
if (_this12.listIsRequest) { | ||
_this12.$emit('request-start', value); | ||
} | ||
@@ -658,8 +674,8 @@ | ||
return _invoke(function () { | ||
if (_this10.listIsRequest) { | ||
return _await(_this10.list(value), function (_this9$list) { | ||
result = _this9$list || []; | ||
if (_this12.listIsRequest) { | ||
return _await(_this12.list(value), function (_this11$list) { | ||
result = _this11$list || []; | ||
}); | ||
} else { | ||
result = _this10.list; | ||
result = _this12.list; | ||
} | ||
@@ -673,17 +689,17 @@ }, function () { | ||
_this10.isPlainSuggestion = _typeof(result[0]) !== 'object' || Array.isArray(result[0]); | ||
_this12.isPlainSuggestion = _typeof(result[0]) !== 'object' || Array.isArray(result[0]); | ||
if (_this10.filterByQuery) { | ||
if (_this12.filterByQuery) { | ||
result = result.filter(function (el) { | ||
return _this10.filter(el, value); | ||
return _this12.filter(el, value); | ||
}); | ||
} | ||
if (_this10.listIsRequest) { | ||
_this10.$emit('request-done', result); | ||
if (_this12.listIsRequest) { | ||
_this12.$emit('request-done', result); | ||
} | ||
}); | ||
}, function (e) { | ||
if (_this10.listIsRequest) { | ||
_this10.$emit('request-failed', e); | ||
if (_this12.listIsRequest) { | ||
_this12.$emit('request-failed', e); | ||
} else { | ||
@@ -694,4 +710,4 @@ throw e; | ||
}, function () { | ||
if (_this10.maxSuggestions) { | ||
result.splice(_this10.maxSuggestions); | ||
if (_this12.maxSuggestions) { | ||
result.splice(_this12.maxSuggestions); | ||
} | ||
@@ -698,0 +714,0 @@ |
133
dist/es6.js
@@ -34,11 +34,8 @@ const defaultControls = { | ||
function _empty() {}function _awaitIgnored(value, direct) { | ||
if (!direct) { | ||
return value && value.then ? value.then(_empty) : Promise.resolve(); | ||
} | ||
}function _invoke(body, then) { | ||
var result = body();if (result && result.then) { | ||
return result.then(then); | ||
}return then(result); | ||
function _await(value, then, direct) { | ||
if (direct) { | ||
return then ? then(value) : value; | ||
}if (!value || !value.then) { | ||
value = Promise.resolve(value); | ||
}return then ? value.then(then) : value; | ||
}function _async(f) { | ||
@@ -54,8 +51,10 @@ return function () { | ||
}; | ||
}function _await(value, then, direct) { | ||
if (direct) { | ||
return then ? then(value) : value; | ||
}if (!value || !value.then) { | ||
value = Promise.resolve(value); | ||
}return then ? value.then(then) : value; | ||
}function _empty() {}function _awaitIgnored(value, direct) { | ||
if (!direct) { | ||
return value && value.then ? value.then(_empty) : Promise.resolve(); | ||
} | ||
}function _invoke(body, then) { | ||
var result = body();if (result && result.then) { | ||
return result.then(then); | ||
}return then(result); | ||
}function _invokeIgnored(body) { | ||
@@ -70,5 +69,7 @@ var result = body();if (result && result.then) { | ||
return recover(e); | ||
}if (result && result.then) { | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
}return result; | ||
} | ||
return result; | ||
}function _finally(body, finalizer) { | ||
@@ -256,8 +257,18 @@ try { | ||
}, | ||
mounted() { | ||
this.inputElement = this.$refs['inputSlot'].querySelector('input'); | ||
mounted: _async(function () { | ||
const _this = this; | ||
this.setInputAriaAttributes(); | ||
this.prepareEventHandlers(true); | ||
}, | ||
return _await(_this.$slots.default, function () { | ||
_this.inputElement = _this.$refs['inputSlot'].querySelector('input'); | ||
if (_this.inputElement) { | ||
_this.setInputAriaAttributes(); | ||
_this.prepareEventHandlers(true); | ||
} else { | ||
console.error('No input element found'); | ||
} | ||
}); | ||
}), | ||
beforeDestroy() { | ||
@@ -407,13 +418,13 @@ this.prepareEventHandlers(false); | ||
showSuggestions: _async(function () { | ||
const _this = this; | ||
const _this2 = this; | ||
return _invoke(function () { | ||
if (_this.suggestions.length === 0 && _this.minLength <= _this.textLength) { | ||
if (_this2.suggestions.length === 0 && _this2.minLength <= _this2.textLength) { | ||
// try show misc slots while researching | ||
_this.showList(); | ||
return _awaitIgnored(_this.research()); | ||
_this2.showList(); | ||
return _awaitIgnored(_this2.research()); | ||
} | ||
}, function () { | ||
_this.showList(); | ||
_this2.showList(); | ||
}); | ||
@@ -525,3 +536,5 @@ }), | ||
onFocus(e) { | ||
this.isInFocus = true; // Only emit, if it was a native input focus | ||
this.isInFocus = true; | ||
// Only emit, if it was a native input focus | ||
if (e && !this.isFalseFocus) { | ||
@@ -565,3 +578,3 @@ this.$emit('focus', e); | ||
research: _async(function () { | ||
const _this2 = this; | ||
const _this3 = this; | ||
@@ -571,9 +584,9 @@ return _finally(function () { | ||
return _invokeIgnored(function () { | ||
if (_this2.canSend) { | ||
_this2.canSend = false; | ||
if (_this3.canSend) { | ||
_this3.canSend = false; | ||
// @TODO: fix when promises will be cancelable (never :D) | ||
let textBeforeRequest = _this2.text; | ||
return _await(_this2.getSuggestions(_this2.text), function (newList) { | ||
if (textBeforeRequest === _this2.text) { | ||
_this2.$set(_this2, 'suggestions', newList); | ||
let textBeforeRequest = _this3.text; | ||
return _await(_this3.getSuggestions(_this3.text), function (newList) { | ||
if (textBeforeRequest === _this3.text) { | ||
_this3.$set(_this3, 'suggestions', newList); | ||
} | ||
@@ -584,31 +597,31 @@ }); | ||
}, function (e) { | ||
_this2.clearSuggestions(); | ||
_this3.clearSuggestions(); | ||
throw e; | ||
}); | ||
}, function () { | ||
_this2.canSend = true; | ||
_this3.canSend = true; | ||
if (_this2.suggestions.length === 0 && _this2.miscSlotsAreEmpty()) { | ||
_this2.hideList(); | ||
} else if (_this2.isInFocus) { | ||
_this2.showList(); | ||
if (_this3.suggestions.length === 0 && _this3.miscSlotsAreEmpty()) { | ||
_this3.hideList(); | ||
} else if (_this3.isInFocus) { | ||
_this3.showList(); | ||
} | ||
return _this2.suggestions; | ||
return _this3.suggestions; | ||
}); | ||
}), | ||
getSuggestions: _async(function (value) { | ||
const _this3 = this; | ||
const _this4 = this; | ||
value = value || ''; | ||
if (value.length < _this3.minLength) { | ||
if (value.length < _this4.minLength) { | ||
return []; | ||
} | ||
_this3.selected = null; | ||
_this4.selected = null; | ||
// Start request if can | ||
if (_this3.listIsRequest) { | ||
_this3.$emit('request-start', value); | ||
if (_this4.listIsRequest) { | ||
_this4.$emit('request-start', value); | ||
} | ||
@@ -620,8 +633,8 @@ | ||
return _invoke(function () { | ||
if (_this3.listIsRequest) { | ||
return _await(_this3.list(value), function (_this3$list) { | ||
result = _this3$list || []; | ||
if (_this4.listIsRequest) { | ||
return _await(_this4.list(value), function (_this4$list) { | ||
result = _this4$list || []; | ||
}); | ||
} else { | ||
result = _this3.list; | ||
result = _this4.list; | ||
} | ||
@@ -635,15 +648,15 @@ }, function () { | ||
_this3.isPlainSuggestion = typeof result[0] !== 'object' || Array.isArray(result[0]); | ||
_this4.isPlainSuggestion = typeof result[0] !== 'object' || Array.isArray(result[0]); | ||
if (_this3.filterByQuery) { | ||
result = result.filter(el => _this3.filter(el, value)); | ||
if (_this4.filterByQuery) { | ||
result = result.filter(el => _this4.filter(el, value)); | ||
} | ||
if (_this3.listIsRequest) { | ||
_this3.$emit('request-done', result); | ||
if (_this4.listIsRequest) { | ||
_this4.$emit('request-done', result); | ||
} | ||
}); | ||
}, function (e) { | ||
if (_this3.listIsRequest) { | ||
_this3.$emit('request-failed', e); | ||
if (_this4.listIsRequest) { | ||
_this4.$emit('request-failed', e); | ||
} else { | ||
@@ -654,4 +667,4 @@ throw e; | ||
}, function () { | ||
if (_this3.maxSuggestions) { | ||
result.splice(_this3.maxSuggestions); | ||
if (_this4.maxSuggestions) { | ||
result.splice(_this4.maxSuggestions); | ||
} | ||
@@ -658,0 +671,0 @@ |
@@ -208,7 +208,13 @@ const defaultControls = { | ||
}, | ||
mounted() { | ||
async mounted() { | ||
await this.$slots.default; | ||
this.inputElement = this.$refs['inputSlot'].querySelector('input'); | ||
this.setInputAriaAttributes(); | ||
this.prepareEventHandlers(true); | ||
if (this.inputElement) { | ||
this.setInputAriaAttributes(); | ||
this.prepareEventHandlers(true); | ||
} else { | ||
console.error('No input element found'); | ||
} | ||
}, | ||
@@ -215,0 +221,0 @@ beforeDestroy() { |
@@ -1,1 +0,1 @@ | ||
var VueSimpleSuggest=function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],showList:[40],autocomplete:[32,13]},e={input:String,select:Object};function r(t,e){return i(t,e.keyCode)}function i(t,e){if(t.length<=0)return!1;function s(t){return t.some(function(t){return t===e})}return Array.isArray(t[0])?t.some(function(t){return s(t)}):s(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},u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t};function o(){}function l(t,e){var s=t();return s&&s.then?s.then(e):e(s)}function h(t,e,s){return s?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function c(t,e){try{var s=t()}catch(t){return e(t)}return s&&s.then?s.then(void 0,e):s}function a(t,e){try{var s=t()}catch(t){return e()}return s&&s.then?s.then(e,e):e()}var s={render:function(){var s=this,t=s.$createElement,i=s._self._c||t;return i("div",{staticClass:"vue-simple-suggest",class:[s.styles.vueSimpleSuggest,{designed:!s.destyled,focus:s.isInFocus}],on:{keydown:function(t){if(!t.type.indexOf("key")&&s._k(t.keyCode,"tab",9,t.key,"Tab"))return null;s.isTabbed=!0}}},[i("div",{ref:"inputSlot",staticClass:"input-wrapper",class:s.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":s.listId,"aria-expanded":s.listShown&&!s.removeList?"true":"false"}},[s._t("default",[i("input",s._b({staticClass:"default-input",class:s.styles.defaultInput,domProps:{value:s.text||""}},"input",s.$attrs,!1))])],2),s._v(" "),i("transition",{attrs:{name:"vue-simple-suggest"}},[s.listShown&&!s.removeList?i("ul",{staticClass:"suggestions",class:s.styles.suggestions,attrs:{id:s.listId,role:"listbox","aria-labelledby":s.listId}},[this.$scopedSlots["misc-item-above"]?i("li",[s._t("misc-item-above",null,{suggestions:s.suggestions,query:s.text})],2):s._e(),s._v(" "),s._l(s.suggestions,function(e,t){return i("li",{key:s.getId(e,t),staticClass:"suggest-item",class:[s.styles.suggestItem,{selected:s.isSelected(e),hover:s.isHovered(e)}],attrs:{role:"option","aria-selected":s.isHovered(e)||s.isSelected(e)?"true":"false",id:s.getId(e,t)},on:{mouseenter:function(t){return s.hover(e,t.target)},mouseleave:function(){return s.hover(void 0)},click:function(t){return s.suggestionClick(e,t)}}},[s._t("suggestion-item",[i("span",[s._v(s._s(s.displayProperty(e)))])],{autocomplete:function(){return s.autocompleteText(e)},suggestion:e,query:s.text})],2)}),s._v(" "),this.$scopedSlots["misc-item-below"]?i("li",[s._t("misc-item-below",null,{suggestions:s.suggestions,query:s.text})],2):s._e()],2):s._e()])],1)},staticRenderFns:[],name:"vue-simple-suggest",inheritAttrs:!1,model:{prop:"value",event:"input"},props:{styles:{type:Object,default:function(){return{}}},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},nullableSelect:{type:Boolean,default:!1},value:{},mode:{type:String,default:"input",validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t){var e=this;this.constructor.options.model.event=t,this.$parent&&this.$parent.$forceUpdate(),this.$nextTick(function(){"input"===t?e.$emit("input",e.text):e.$emit("select",e.selected)})},immediate:!0},value:{handler:function(t){"string"!=typeof t&&(t=this.displayProperty(t)),this.updateTextOutside(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,isInFocus:!1,isFalseFocus:!1,isTabbed:!1,controlScheme:{},listId:this._uid+"-suggestions"}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&0<this.$slots.default.length&&!!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(){for(var t=0;t<this.suggestions.length;t++){var e=this.suggestions[t];if(this.hovered&&this.valueProperty(this.hovered)==this.valueProperty(e))return t}return-1},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0},isSelectedUpToDate:function(){return!!this.selected&&this.displayProperty(this.selected)===this.text}},created:function(){this.controlScheme=u({},t,this.controls)},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.setInputAriaAttributes(),this.prepareEventHandlers(!0)},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{isEqual:function(t,e){return e&&this.valueProperty(t)==this.valueProperty(e)},isSelected:function(t){return this.isEqual(t,this.selected)},isHovered:function(t){return this.isEqual(t,this.hovered)},setInputAriaAttributes:function(){this.inputElement.setAttribute("aria-activedescendant",""),this.inputElement.setAttribute("aria-autocomplete","list"),this.inputElement.setAttribute("aria-controls",this.listId)},prepareEventHandlers:function(t){var e=this[t?"on":"off"],s={click:this.showSuggestions,keydown:this.onKeyDown,keyup:this.onListKeyUp},i=u({blur:this.onBlur,focus:this.onFocus,input:this.onInput},s);for(var n in i)this.input[e](n,i[n]);var o=t?"addEventListener":"removeEventListener";for(var r in s)this.inputElement[o](r,s[r])},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 e=this,t=["misc-item-above","misc-item-below"].map(function(t){return e.$scopedSlots[t]});if(t.every(function(t){return!!t}))return t.every(this.isScopedSlotEmpty.bind(this));var s=t.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,s)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":n(t))?(s=t,e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},s)):t;var s},displayProperty:function(t){if(this.isPlainSuggestion)return t;var e=this.getPropertyByAttribute(t,this.displayAttribute);return void 0===e&&(e=JSON.stringify(t),process&&~process.env.NODE_ENV.indexOf("dev")&&console.warn("[vue-simple-suggest]: Please, provide `display-attribute` as a key or a dotted path for a property from your object.")),String(e||"")},valueProperty:function(t){if(this.isPlainSuggestion)return t;var e=this.getPropertyByAttribute(t,this.valueAttribute);return void 0===e&&console.error("[vue-simple-suggest]: Please, check if you passed 'value-attribute' (default is 'id') and 'display-attribute' (default is 'title') props correctly.\n Your list objects should always contain a unique identifier."),e},autocompleteText:function(t){this.setText(this.displayProperty(t))},setText:function(t){var e=this;this.$nextTick(function(){e.inputElement.value=t,e.text=t,e.$emit("input",t)})},select:function(t){(this.selected!==t||this.nullableSelect&&!t)&&(this.selected=t,this.$emit("select",t),t&&this.autocompleteText(t)),this.hover(null)},hover:function(t,e){var s=t?this.getId(t,this.hoveredIndex):"";this.inputElement.setAttribute("aria-activedescendant",s),t&&t!==this.hovered&&this.$emit("hover",t,e),this.hovered=t},hideList:function(){this.listShown&&(this.listShown=!1,this.hover(null),this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(0<this.suggestions.length||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:function(){try{var t=this;return l(function(){if(0===t.suggestions.length&&t.minLength<=t.textLength)return t.showList(),function(t,e){if(!e)return t&&t.then?t.then(o):Promise.resolve()}(t.research())},function(){t.showList()})}catch(t){return Promise.reject(t)}},onShowList:function(t){r(this.controlScheme.showList,t)&&this.showSuggestions()},moveSelection:function(t){if(this.listShown&&this.suggestions.length&&r([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault();var e=r(this.controlScheme.selectionDown,t),s=2*e-1,i=e?0:this.suggestions.length-1,n=e?this.hoveredIndex<this.suggestions.length-1:0<this.hoveredIndex,o=null;o=this.hovered?n?this.suggestions[this.hoveredIndex+s]:this.suggestions[i]:this.selected||this.suggestions[i],this.hover(o)}},onKeyDown:function(t){var e=this.controlScheme.select,s=this.controlScheme.hideList;"Enter"===t.key&&this.listShown&&i([e,s],13)&&t.preventDefault(),"Tab"===t.key&&this.hovered&&this.select(this.hovered),this.onShowList(t),this.moveSelection(t),this.onAutocomplete(t)},onListKeyUp:function(t){var e=this.controlScheme.select,s=this.controlScheme.hideList;this.listShown&&r([e,s],t)&&(t.preventDefault(),r(e,t)&&this.select(this.hovered),this.hideList())},onAutocomplete:function(t){r(this.controlScheme.autocomplete,t)&&(t.ctrlKey||t.shiftKey)&&0<this.suggestions.length&&this.suggestions[0]&&this.listShown&&(t.preventDefault(),this.hover(this.suggestions[0]),this.autocompleteText(this.suggestions[0]))},suggestionClick:function(t,e){this.$emit("suggestion-click",t,e),this.select(t),this.hideList(),this.isClicking=!1},onBlur:function(t){var e=this;this.isInFocus?(this.isClicking=this.hovered&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&(this.isFalseFocus=!0,setTimeout(function(){e.inputElement.focus()},0)):(this.isInFocus=!1,this.hideList(),this.$emit("blur",t))):(this.inputElement.blur(),console.error("This should never happen!\n If you encountered this error, please make sure that your input component emits 'focus' events properly.\n For more info see https://github.com/KazanExpress/vue-simple-suggest#custom-input.\n\n If your 'vue-simple-suggest' setup does not include a custom input component - please,\n report to https://github.com/KazanExpress/vue-simple-suggest/issues/new")),this.isTabbed=!1},onFocus:function(t){this.isInFocus=!0,t&&!this.isFalseFocus&&this.$emit("focus",t),this.isClicking||this.isFalseFocus||this.showSuggestions(),this.isFalseFocus=!1},onInput:function(t){var e=t.target?t.target.value:t;this.updateTextOutside(e),this.$emit("input",e)},updateTextOutside:function(t){this.text!==t&&(this.text=t,this.hovered&&this.hover(null),this.text.length<this.minLength?this.hideList():this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:function(){try{var s=this;return a(function(){return c(function(){return function(t){var e=t();if(e&&e.then)return e.then(o)}(function(){if(s.canSend){s.canSend=!1;var e=s.text;return h(s.getSuggestions(s.text),function(t){e===s.text&&s.$set(s,"suggestions",t)})}})},function(t){throw s.clearSuggestions(),t})},function(){return s.canSend=!0,0===s.suggestions.length&&s.miscSlotsAreEmpty()?s.hideList():s.isInFocus&&s.showList(),s.suggestions})}catch(t){return Promise.reject(t)}},getSuggestions:function(e){try{var s=this;if((e=e||"").length<s.minLength)return[];s.selected=null,s.listIsRequest&&s.$emit("request-start",e);var i=[];return a(function(){return c(function(){return l(function(){if(s.listIsRequest)return h(s.list(e),function(t){i=t||[]});i=s.list},function(){Array.isArray(i)||(i=[i]),s.isPlainSuggestion="object"!==n(i[0])||Array.isArray(i[0]),s.filterByQuery&&(i=i.filter(function(t){return s.filter(t,e)})),s.listIsRequest&&s.$emit("request-done",i)})},function(t){if(!s.listIsRequest)throw t;s.$emit("request-failed",t)})},function(){return s.maxSuggestions&&i.splice(s.maxSuggestions),i})}catch(t){return Promise.reject(t)}},clearSuggestions:function(){this.suggestions.splice(0)},getId:function(t,e){return this.listId+"-suggestion-"+(this.isPlainSuggestion?e:this.valueProperty(t)||e)}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",s),s}(); | ||
var VueSimpleSuggest=function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],showList:[40],autocomplete:[32,13]},e={input:String,select:Object};function r(t,e){return i(t,e.keyCode)}function i(t,e){if(t.length<=0)return!1;function s(t){return t.some(function(t){return t===e})}return Array.isArray(t[0])?t.some(function(t){return s(t)}):s(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},u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t};function o(t,e,s){return s?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function l(){}function h(t,e){var s=t();return s&&s.then?s.then(e):e(s)}function c(t,e){try{var s=t()}catch(t){return e(t)}return s&&s.then?s.then(void 0,e):s}function a(t,e){try{var s=t()}catch(t){return e()}return s&&s.then?s.then(e,e):e()}var s={render:function(){var s=this,t=s.$createElement,i=s._self._c||t;return i("div",{staticClass:"vue-simple-suggest",class:[s.styles.vueSimpleSuggest,{designed:!s.destyled,focus:s.isInFocus}],on:{keydown:function(t){if(!t.type.indexOf("key")&&s._k(t.keyCode,"tab",9,t.key,"Tab"))return null;s.isTabbed=!0}}},[i("div",{ref:"inputSlot",staticClass:"input-wrapper",class:s.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":s.listId,"aria-expanded":s.listShown&&!s.removeList?"true":"false"}},[s._t("default",[i("input",s._b({staticClass:"default-input",class:s.styles.defaultInput,domProps:{value:s.text||""}},"input",s.$attrs,!1))])],2),s._v(" "),i("transition",{attrs:{name:"vue-simple-suggest"}},[s.listShown&&!s.removeList?i("ul",{staticClass:"suggestions",class:s.styles.suggestions,attrs:{id:s.listId,role:"listbox","aria-labelledby":s.listId}},[this.$scopedSlots["misc-item-above"]?i("li",[s._t("misc-item-above",null,{suggestions:s.suggestions,query:s.text})],2):s._e(),s._v(" "),s._l(s.suggestions,function(e,t){return i("li",{key:s.getId(e,t),staticClass:"suggest-item",class:[s.styles.suggestItem,{selected:s.isSelected(e),hover:s.isHovered(e)}],attrs:{role:"option","aria-selected":s.isHovered(e)||s.isSelected(e)?"true":"false",id:s.getId(e,t)},on:{mouseenter:function(t){return s.hover(e,t.target)},mouseleave:function(){return s.hover(void 0)},click:function(t){return s.suggestionClick(e,t)}}},[s._t("suggestion-item",[i("span",[s._v(s._s(s.displayProperty(e)))])],{autocomplete:function(){return s.autocompleteText(e)},suggestion:e,query:s.text})],2)}),s._v(" "),this.$scopedSlots["misc-item-below"]?i("li",[s._t("misc-item-below",null,{suggestions:s.suggestions,query:s.text})],2):s._e()],2):s._e()])],1)},staticRenderFns:[],name:"vue-simple-suggest",inheritAttrs:!1,model:{prop:"value",event:"input"},props:{styles:{type:Object,default:function(){return{}}},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},nullableSelect:{type:Boolean,default:!1},value:{},mode:{type:String,default:"input",validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t){var e=this;this.constructor.options.model.event=t,this.$parent&&this.$parent.$forceUpdate(),this.$nextTick(function(){"input"===t?e.$emit("input",e.text):e.$emit("select",e.selected)})},immediate:!0},value:{handler:function(t){"string"!=typeof t&&(t=this.displayProperty(t)),this.updateTextOutside(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,isInFocus:!1,isFalseFocus:!1,isTabbed:!1,controlScheme:{},listId:this._uid+"-suggestions"}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&0<this.$slots.default.length&&!!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(){for(var t=0;t<this.suggestions.length;t++){var e=this.suggestions[t];if(this.hovered&&this.valueProperty(this.hovered)==this.valueProperty(e))return t}return-1},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0},isSelectedUpToDate:function(){return!!this.selected&&this.displayProperty(this.selected)===this.text}},created:function(){this.controlScheme=u({},t,this.controls)},mounted:function(){try{var t=this;return o(t.$slots.default,function(){t.inputElement=t.$refs.inputSlot.querySelector("input"),t.inputElement?(t.setInputAriaAttributes(),t.prepareEventHandlers(!0)):console.error("No input element found")})}catch(t){return Promise.reject(t)}},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{isEqual:function(t,e){return e&&this.valueProperty(t)==this.valueProperty(e)},isSelected:function(t){return this.isEqual(t,this.selected)},isHovered:function(t){return this.isEqual(t,this.hovered)},setInputAriaAttributes:function(){this.inputElement.setAttribute("aria-activedescendant",""),this.inputElement.setAttribute("aria-autocomplete","list"),this.inputElement.setAttribute("aria-controls",this.listId)},prepareEventHandlers:function(t){var e=this[t?"on":"off"],s={click:this.showSuggestions,keydown:this.onKeyDown,keyup:this.onListKeyUp},i=u({blur:this.onBlur,focus:this.onFocus,input:this.onInput},s);for(var n in i)this.input[e](n,i[n]);var o=t?"addEventListener":"removeEventListener";for(var r in s)this.inputElement[o](r,s[r])},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 e=this,t=["misc-item-above","misc-item-below"].map(function(t){return e.$scopedSlots[t]});if(t.every(function(t){return!!t}))return t.every(this.isScopedSlotEmpty.bind(this));var s=t.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,s)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":n(t))?(s=t,e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},s)):t;var s},displayProperty:function(t){if(this.isPlainSuggestion)return t;var e=this.getPropertyByAttribute(t,this.displayAttribute);return void 0===e&&(e=JSON.stringify(t),process&&~process.env.NODE_ENV.indexOf("dev")&&console.warn("[vue-simple-suggest]: Please, provide `display-attribute` as a key or a dotted path for a property from your object.")),String(e||"")},valueProperty:function(t){if(this.isPlainSuggestion)return t;var e=this.getPropertyByAttribute(t,this.valueAttribute);return void 0===e&&console.error("[vue-simple-suggest]: Please, check if you passed 'value-attribute' (default is 'id') and 'display-attribute' (default is 'title') props correctly.\n Your list objects should always contain a unique identifier."),e},autocompleteText:function(t){this.setText(this.displayProperty(t))},setText:function(t){var e=this;this.$nextTick(function(){e.inputElement.value=t,e.text=t,e.$emit("input",t)})},select:function(t){(this.selected!==t||this.nullableSelect&&!t)&&(this.selected=t,this.$emit("select",t),t&&this.autocompleteText(t)),this.hover(null)},hover:function(t,e){var s=t?this.getId(t,this.hoveredIndex):"";this.inputElement.setAttribute("aria-activedescendant",s),t&&t!==this.hovered&&this.$emit("hover",t,e),this.hovered=t},hideList:function(){this.listShown&&(this.listShown=!1,this.hover(null),this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(0<this.suggestions.length||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:function(){try{var t=this;return h(function(){if(0===t.suggestions.length&&t.minLength<=t.textLength)return t.showList(),function(t,e){if(!e)return t&&t.then?t.then(l):Promise.resolve()}(t.research())},function(){t.showList()})}catch(t){return Promise.reject(t)}},onShowList:function(t){r(this.controlScheme.showList,t)&&this.showSuggestions()},moveSelection:function(t){if(this.listShown&&this.suggestions.length&&r([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault();var e=r(this.controlScheme.selectionDown,t),s=2*e-1,i=e?0:this.suggestions.length-1,n=e?this.hoveredIndex<this.suggestions.length-1:0<this.hoveredIndex,o=null;o=this.hovered?n?this.suggestions[this.hoveredIndex+s]:this.suggestions[i]:this.selected||this.suggestions[i],this.hover(o)}},onKeyDown:function(t){var e=this.controlScheme.select,s=this.controlScheme.hideList;"Enter"===t.key&&this.listShown&&i([e,s],13)&&t.preventDefault(),"Tab"===t.key&&this.hovered&&this.select(this.hovered),this.onShowList(t),this.moveSelection(t),this.onAutocomplete(t)},onListKeyUp:function(t){var e=this.controlScheme.select,s=this.controlScheme.hideList;this.listShown&&r([e,s],t)&&(t.preventDefault(),r(e,t)&&this.select(this.hovered),this.hideList())},onAutocomplete:function(t){r(this.controlScheme.autocomplete,t)&&(t.ctrlKey||t.shiftKey)&&0<this.suggestions.length&&this.suggestions[0]&&this.listShown&&(t.preventDefault(),this.hover(this.suggestions[0]),this.autocompleteText(this.suggestions[0]))},suggestionClick:function(t,e){this.$emit("suggestion-click",t,e),this.select(t),this.hideList(),this.isClicking=!1},onBlur:function(t){var e=this;this.isInFocus?(this.isClicking=this.hovered&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&(this.isFalseFocus=!0,setTimeout(function(){e.inputElement.focus()},0)):(this.isInFocus=!1,this.hideList(),this.$emit("blur",t))):(this.inputElement.blur(),console.error("This should never happen!\n If you encountered this error, please make sure that your input component emits 'focus' events properly.\n For more info see https://github.com/KazanExpress/vue-simple-suggest#custom-input.\n\n If your 'vue-simple-suggest' setup does not include a custom input component - please,\n report to https://github.com/KazanExpress/vue-simple-suggest/issues/new")),this.isTabbed=!1},onFocus:function(t){this.isInFocus=!0,t&&!this.isFalseFocus&&this.$emit("focus",t),this.isClicking||this.isFalseFocus||this.showSuggestions(),this.isFalseFocus=!1},onInput:function(t){var e=t.target?t.target.value:t;this.updateTextOutside(e),this.$emit("input",e)},updateTextOutside:function(t){this.text!==t&&(this.text=t,this.hovered&&this.hover(null),this.text.length<this.minLength?this.hideList():this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:function(){try{var s=this;return a(function(){return c(function(){return function(t){var e=t();if(e&&e.then)return e.then(l)}(function(){if(s.canSend){s.canSend=!1;var e=s.text;return o(s.getSuggestions(s.text),function(t){e===s.text&&s.$set(s,"suggestions",t)})}})},function(t){throw s.clearSuggestions(),t})},function(){return s.canSend=!0,0===s.suggestions.length&&s.miscSlotsAreEmpty()?s.hideList():s.isInFocus&&s.showList(),s.suggestions})}catch(t){return Promise.reject(t)}},getSuggestions:function(e){try{var s=this;if((e=e||"").length<s.minLength)return[];s.selected=null,s.listIsRequest&&s.$emit("request-start",e);var i=[];return a(function(){return c(function(){return h(function(){if(s.listIsRequest)return o(s.list(e),function(t){i=t||[]});i=s.list},function(){Array.isArray(i)||(i=[i]),s.isPlainSuggestion="object"!==n(i[0])||Array.isArray(i[0]),s.filterByQuery&&(i=i.filter(function(t){return s.filter(t,e)})),s.listIsRequest&&s.$emit("request-done",i)})},function(t){if(!s.listIsRequest)throw t;s.$emit("request-failed",t)})},function(){return s.maxSuggestions&&i.splice(s.maxSuggestions),i})}catch(t){return Promise.reject(t)}},clearSuggestions:function(){this.suggestions.splice(0)},getId:function(t,e){return this.listId+"-suggestion-"+(this.isPlainSuggestion?e:this.valueProperty(t)||e)}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",s),s}(); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).VueSimpleSuggest=e()}(this,function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],showList:[40],autocomplete:[32,13]},e={input:String,select:Object};function r(t,e){return i(t,e.keyCode)}function i(t,e){if(t.length<=0)return!1;function s(t){return t.some(function(t){return t===e})}return Array.isArray(t[0])?t.some(function(t){return s(t)}):s(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 o(){}function u(t,e){var s=t();return s&&s.then?s.then(e):e(s)}function l(t,e,s){return s?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function h(t,e){try{var s=t()}catch(t){return e(t)}return s&&s.then?s.then(void 0,e):s}function c(t,e){try{var s=t()}catch(t){return e()}return s&&s.then?s.then(e,e):e()}var s={render:function(){var s=this,t=s.$createElement,i=s._self._c||t;return i("div",{staticClass:"vue-simple-suggest",class:[s.styles.vueSimpleSuggest,{designed:!s.destyled,focus:s.isInFocus}],on:{keydown:function(t){if(!t.type.indexOf("key")&&s._k(t.keyCode,"tab",9,t.key,"Tab"))return null;s.isTabbed=!0}}},[i("div",{ref:"inputSlot",staticClass:"input-wrapper",class:s.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":s.listId,"aria-expanded":s.listShown&&!s.removeList?"true":"false"}},[s._t("default",[i("input",s._b({staticClass:"default-input",class:s.styles.defaultInput,domProps:{value:s.text||""}},"input",s.$attrs,!1))])],2),s._v(" "),i("transition",{attrs:{name:"vue-simple-suggest"}},[s.listShown&&!s.removeList?i("ul",{staticClass:"suggestions",class:s.styles.suggestions,attrs:{id:s.listId,role:"listbox","aria-labelledby":s.listId}},[this.$scopedSlots["misc-item-above"]?i("li",[s._t("misc-item-above",null,{suggestions:s.suggestions,query:s.text})],2):s._e(),s._v(" "),s._l(s.suggestions,function(e,t){return i("li",{key:s.getId(e,t),staticClass:"suggest-item",class:[s.styles.suggestItem,{selected:s.isSelected(e),hover:s.isHovered(e)}],attrs:{role:"option","aria-selected":s.isHovered(e)||s.isSelected(e)?"true":"false",id:s.getId(e,t)},on:{mouseenter:function(t){return s.hover(e,t.target)},mouseleave:function(){return s.hover(void 0)},click:function(t){return s.suggestionClick(e,t)}}},[s._t("suggestion-item",[i("span",[s._v(s._s(s.displayProperty(e)))])],{autocomplete:function(){return s.autocompleteText(e)},suggestion:e,query:s.text})],2)}),s._v(" "),this.$scopedSlots["misc-item-below"]?i("li",[s._t("misc-item-below",null,{suggestions:s.suggestions,query:s.text})],2):s._e()],2):s._e()])],1)},staticRenderFns:[],name:"vue-simple-suggest",inheritAttrs:!1,model:{prop:"value",event:"input"},props:{styles:{type:Object,default:function(){return{}}},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},nullableSelect:{type:Boolean,default:!1},value:{},mode:{type:String,default:"input",validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t){var e=this;this.constructor.options.model.event=t,this.$parent&&this.$parent.$forceUpdate(),this.$nextTick(function(){"input"===t?e.$emit("input",e.text):e.$emit("select",e.selected)})},immediate:!0},value:{handler:function(t){"string"!=typeof t&&(t=this.displayProperty(t)),this.updateTextOutside(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,isInFocus:!1,isFalseFocus:!1,isTabbed:!1,controlScheme:{},listId:this._uid+"-suggestions"}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&0<this.$slots.default.length&&!!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(){for(var t=0;t<this.suggestions.length;t++){var e=this.suggestions[t];if(this.hovered&&this.valueProperty(this.hovered)==this.valueProperty(e))return t}return-1},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0},isSelectedUpToDate:function(){return!!this.selected&&this.displayProperty(this.selected)===this.text}},created:function(){this.controlScheme=Object.assign({},t,this.controls)},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.setInputAriaAttributes(),this.prepareEventHandlers(!0)},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{isEqual:function(t,e){return e&&this.valueProperty(t)==this.valueProperty(e)},isSelected:function(t){return this.isEqual(t,this.selected)},isHovered:function(t){return this.isEqual(t,this.hovered)},setInputAriaAttributes:function(){this.inputElement.setAttribute("aria-activedescendant",""),this.inputElement.setAttribute("aria-autocomplete","list"),this.inputElement.setAttribute("aria-controls",this.listId)},prepareEventHandlers:function(t){var e=this[t?"on":"off"],s={click:this.showSuggestions,keydown:this.onKeyDown,keyup:this.onListKeyUp},i=Object.assign({blur:this.onBlur,focus:this.onFocus,input:this.onInput},s);for(var n in i)this.input[e](n,i[n]);var o=t?"addEventListener":"removeEventListener";for(var r in s)this.inputElement[o](r,s[r])},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 e=this,t=["misc-item-above","misc-item-below"].map(function(t){return e.$scopedSlots[t]});if(t.every(function(t){return!!t}))return t.every(this.isScopedSlotEmpty.bind(this));var s=t.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,s)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":n(t))?(s=t,e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},s)):t;var s},displayProperty:function(t){if(this.isPlainSuggestion)return t;var e=this.getPropertyByAttribute(t,this.displayAttribute);return void 0===e&&(e=JSON.stringify(t),process&&~process.env.NODE_ENV.indexOf("dev")&&console.warn("[vue-simple-suggest]: Please, provide `display-attribute` as a key or a dotted path for a property from your object.")),String(e||"")},valueProperty:function(t){if(this.isPlainSuggestion)return t;var e=this.getPropertyByAttribute(t,this.valueAttribute);return void 0===e&&console.error("[vue-simple-suggest]: Please, check if you passed 'value-attribute' (default is 'id') and 'display-attribute' (default is 'title') props correctly.\n Your list objects should always contain a unique identifier."),e},autocompleteText:function(t){this.setText(this.displayProperty(t))},setText:function(t){var e=this;this.$nextTick(function(){e.inputElement.value=t,e.text=t,e.$emit("input",t)})},select:function(t){(this.selected!==t||this.nullableSelect&&!t)&&(this.selected=t,this.$emit("select",t),t&&this.autocompleteText(t)),this.hover(null)},hover:function(t,e){var s=t?this.getId(t,this.hoveredIndex):"";this.inputElement.setAttribute("aria-activedescendant",s),t&&t!==this.hovered&&this.$emit("hover",t,e),this.hovered=t},hideList:function(){this.listShown&&(this.listShown=!1,this.hover(null),this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(0<this.suggestions.length||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:function(){try{var t=this;return u(function(){if(0===t.suggestions.length&&t.minLength<=t.textLength)return t.showList(),function(t,e){if(!e)return t&&t.then?t.then(o):Promise.resolve()}(t.research())},function(){t.showList()})}catch(t){return Promise.reject(t)}},onShowList:function(t){r(this.controlScheme.showList,t)&&this.showSuggestions()},moveSelection:function(t){if(this.listShown&&this.suggestions.length&&r([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault();var e=r(this.controlScheme.selectionDown,t),s=2*e-1,i=e?0:this.suggestions.length-1,n=e?this.hoveredIndex<this.suggestions.length-1:0<this.hoveredIndex,o=null;o=this.hovered?n?this.suggestions[this.hoveredIndex+s]:this.suggestions[i]:this.selected||this.suggestions[i],this.hover(o)}},onKeyDown:function(t){var e=this.controlScheme.select,s=this.controlScheme.hideList;"Enter"===t.key&&this.listShown&&i([e,s],13)&&t.preventDefault(),"Tab"===t.key&&this.hovered&&this.select(this.hovered),this.onShowList(t),this.moveSelection(t),this.onAutocomplete(t)},onListKeyUp:function(t){var e=this.controlScheme.select,s=this.controlScheme.hideList;this.listShown&&r([e,s],t)&&(t.preventDefault(),r(e,t)&&this.select(this.hovered),this.hideList())},onAutocomplete:function(t){r(this.controlScheme.autocomplete,t)&&(t.ctrlKey||t.shiftKey)&&0<this.suggestions.length&&this.suggestions[0]&&this.listShown&&(t.preventDefault(),this.hover(this.suggestions[0]),this.autocompleteText(this.suggestions[0]))},suggestionClick:function(t,e){this.$emit("suggestion-click",t,e),this.select(t),this.hideList(),this.isClicking=!1},onBlur:function(t){var e=this;this.isInFocus?(this.isClicking=this.hovered&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&(this.isFalseFocus=!0,setTimeout(function(){e.inputElement.focus()},0)):(this.isInFocus=!1,this.hideList(),this.$emit("blur",t))):(this.inputElement.blur(),console.error("This should never happen!\n If you encountered this error, please make sure that your input component emits 'focus' events properly.\n For more info see https://github.com/KazanExpress/vue-simple-suggest#custom-input.\n\n If your 'vue-simple-suggest' setup does not include a custom input component - please,\n report to https://github.com/KazanExpress/vue-simple-suggest/issues/new")),this.isTabbed=!1},onFocus:function(t){this.isInFocus=!0,t&&!this.isFalseFocus&&this.$emit("focus",t),this.isClicking||this.isFalseFocus||this.showSuggestions(),this.isFalseFocus=!1},onInput:function(t){var e=t.target?t.target.value:t;this.updateTextOutside(e),this.$emit("input",e)},updateTextOutside:function(t){this.text!==t&&(this.text=t,this.hovered&&this.hover(null),this.text.length<this.minLength?this.hideList():this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:function(){try{var s=this;return c(function(){return h(function(){return function(t){var e=t();if(e&&e.then)return e.then(o)}(function(){if(s.canSend){s.canSend=!1;var e=s.text;return l(s.getSuggestions(s.text),function(t){e===s.text&&s.$set(s,"suggestions",t)})}})},function(t){throw s.clearSuggestions(),t})},function(){return s.canSend=!0,0===s.suggestions.length&&s.miscSlotsAreEmpty()?s.hideList():s.isInFocus&&s.showList(),s.suggestions})}catch(t){return Promise.reject(t)}},getSuggestions:function(e){try{var s=this;if((e=e||"").length<s.minLength)return[];s.selected=null,s.listIsRequest&&s.$emit("request-start",e);var i=[];return c(function(){return h(function(){return u(function(){if(s.listIsRequest)return l(s.list(e),function(t){i=t||[]});i=s.list},function(){Array.isArray(i)||(i=[i]),s.isPlainSuggestion="object"!==n(i[0])||Array.isArray(i[0]),s.filterByQuery&&(i=i.filter(function(t){return s.filter(t,e)})),s.listIsRequest&&s.$emit("request-done",i)})},function(t){if(!s.listIsRequest)throw t;s.$emit("request-failed",t)})},function(){return s.maxSuggestions&&i.splice(s.maxSuggestions),i})}catch(t){return Promise.reject(t)}},clearSuggestions:function(){this.suggestions.splice(0)},getId:function(t,e){return this.listId+"-suggestion-"+(this.isPlainSuggestion?e:this.valueProperty(t)||e)}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",s),s}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).VueSimpleSuggest=e()}(this,function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],showList:[40],autocomplete:[32,13]},e={input:String,select:Object};function r(t,e){return i(t,e.keyCode)}function i(t,e){if(t.length<=0)return!1;function s(t){return t.some(function(t){return t===e})}return Array.isArray(t[0])?t.some(function(t){return s(t)}):s(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 o(t,e,s){return s?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function u(){}function l(t,e){var s=t();return s&&s.then?s.then(e):e(s)}function h(t,e){try{var s=t()}catch(t){return e(t)}return s&&s.then?s.then(void 0,e):s}function c(t,e){try{var s=t()}catch(t){return e()}return s&&s.then?s.then(e,e):e()}var s={render:function(){var s=this,t=s.$createElement,i=s._self._c||t;return i("div",{staticClass:"vue-simple-suggest",class:[s.styles.vueSimpleSuggest,{designed:!s.destyled,focus:s.isInFocus}],on:{keydown:function(t){if(!t.type.indexOf("key")&&s._k(t.keyCode,"tab",9,t.key,"Tab"))return null;s.isTabbed=!0}}},[i("div",{ref:"inputSlot",staticClass:"input-wrapper",class:s.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":s.listId,"aria-expanded":s.listShown&&!s.removeList?"true":"false"}},[s._t("default",[i("input",s._b({staticClass:"default-input",class:s.styles.defaultInput,domProps:{value:s.text||""}},"input",s.$attrs,!1))])],2),s._v(" "),i("transition",{attrs:{name:"vue-simple-suggest"}},[s.listShown&&!s.removeList?i("ul",{staticClass:"suggestions",class:s.styles.suggestions,attrs:{id:s.listId,role:"listbox","aria-labelledby":s.listId}},[this.$scopedSlots["misc-item-above"]?i("li",[s._t("misc-item-above",null,{suggestions:s.suggestions,query:s.text})],2):s._e(),s._v(" "),s._l(s.suggestions,function(e,t){return i("li",{key:s.getId(e,t),staticClass:"suggest-item",class:[s.styles.suggestItem,{selected:s.isSelected(e),hover:s.isHovered(e)}],attrs:{role:"option","aria-selected":s.isHovered(e)||s.isSelected(e)?"true":"false",id:s.getId(e,t)},on:{mouseenter:function(t){return s.hover(e,t.target)},mouseleave:function(){return s.hover(void 0)},click:function(t){return s.suggestionClick(e,t)}}},[s._t("suggestion-item",[i("span",[s._v(s._s(s.displayProperty(e)))])],{autocomplete:function(){return s.autocompleteText(e)},suggestion:e,query:s.text})],2)}),s._v(" "),this.$scopedSlots["misc-item-below"]?i("li",[s._t("misc-item-below",null,{suggestions:s.suggestions,query:s.text})],2):s._e()],2):s._e()])],1)},staticRenderFns:[],name:"vue-simple-suggest",inheritAttrs:!1,model:{prop:"value",event:"input"},props:{styles:{type:Object,default:function(){return{}}},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},nullableSelect:{type:Boolean,default:!1},value:{},mode:{type:String,default:"input",validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t){var e=this;this.constructor.options.model.event=t,this.$parent&&this.$parent.$forceUpdate(),this.$nextTick(function(){"input"===t?e.$emit("input",e.text):e.$emit("select",e.selected)})},immediate:!0},value:{handler:function(t){"string"!=typeof t&&(t=this.displayProperty(t)),this.updateTextOutside(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,isInFocus:!1,isFalseFocus:!1,isTabbed:!1,controlScheme:{},listId:this._uid+"-suggestions"}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&0<this.$slots.default.length&&!!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(){for(var t=0;t<this.suggestions.length;t++){var e=this.suggestions[t];if(this.hovered&&this.valueProperty(this.hovered)==this.valueProperty(e))return t}return-1},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0},isSelectedUpToDate:function(){return!!this.selected&&this.displayProperty(this.selected)===this.text}},created:function(){this.controlScheme=Object.assign({},t,this.controls)},mounted:function(){try{var t=this;return o(t.$slots.default,function(){t.inputElement=t.$refs.inputSlot.querySelector("input"),t.inputElement?(t.setInputAriaAttributes(),t.prepareEventHandlers(!0)):console.error("No input element found")})}catch(t){return Promise.reject(t)}},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{isEqual:function(t,e){return e&&this.valueProperty(t)==this.valueProperty(e)},isSelected:function(t){return this.isEqual(t,this.selected)},isHovered:function(t){return this.isEqual(t,this.hovered)},setInputAriaAttributes:function(){this.inputElement.setAttribute("aria-activedescendant",""),this.inputElement.setAttribute("aria-autocomplete","list"),this.inputElement.setAttribute("aria-controls",this.listId)},prepareEventHandlers:function(t){var e=this[t?"on":"off"],s={click:this.showSuggestions,keydown:this.onKeyDown,keyup:this.onListKeyUp},i=Object.assign({blur:this.onBlur,focus:this.onFocus,input:this.onInput},s);for(var n in i)this.input[e](n,i[n]);var o=t?"addEventListener":"removeEventListener";for(var r in s)this.inputElement[o](r,s[r])},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 e=this,t=["misc-item-above","misc-item-below"].map(function(t){return e.$scopedSlots[t]});if(t.every(function(t){return!!t}))return t.every(this.isScopedSlotEmpty.bind(this));var s=t.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,s)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":n(t))?(s=t,e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},s)):t;var s},displayProperty:function(t){if(this.isPlainSuggestion)return t;var e=this.getPropertyByAttribute(t,this.displayAttribute);return void 0===e&&(e=JSON.stringify(t),process&&~process.env.NODE_ENV.indexOf("dev")&&console.warn("[vue-simple-suggest]: Please, provide `display-attribute` as a key or a dotted path for a property from your object.")),String(e||"")},valueProperty:function(t){if(this.isPlainSuggestion)return t;var e=this.getPropertyByAttribute(t,this.valueAttribute);return void 0===e&&console.error("[vue-simple-suggest]: Please, check if you passed 'value-attribute' (default is 'id') and 'display-attribute' (default is 'title') props correctly.\n Your list objects should always contain a unique identifier."),e},autocompleteText:function(t){this.setText(this.displayProperty(t))},setText:function(t){var e=this;this.$nextTick(function(){e.inputElement.value=t,e.text=t,e.$emit("input",t)})},select:function(t){(this.selected!==t||this.nullableSelect&&!t)&&(this.selected=t,this.$emit("select",t),t&&this.autocompleteText(t)),this.hover(null)},hover:function(t,e){var s=t?this.getId(t,this.hoveredIndex):"";this.inputElement.setAttribute("aria-activedescendant",s),t&&t!==this.hovered&&this.$emit("hover",t,e),this.hovered=t},hideList:function(){this.listShown&&(this.listShown=!1,this.hover(null),this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(0<this.suggestions.length||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:function(){try{var t=this;return l(function(){if(0===t.suggestions.length&&t.minLength<=t.textLength)return t.showList(),function(t,e){if(!e)return t&&t.then?t.then(u):Promise.resolve()}(t.research())},function(){t.showList()})}catch(t){return Promise.reject(t)}},onShowList:function(t){r(this.controlScheme.showList,t)&&this.showSuggestions()},moveSelection:function(t){if(this.listShown&&this.suggestions.length&&r([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault();var e=r(this.controlScheme.selectionDown,t),s=2*e-1,i=e?0:this.suggestions.length-1,n=e?this.hoveredIndex<this.suggestions.length-1:0<this.hoveredIndex,o=null;o=this.hovered?n?this.suggestions[this.hoveredIndex+s]:this.suggestions[i]:this.selected||this.suggestions[i],this.hover(o)}},onKeyDown:function(t){var e=this.controlScheme.select,s=this.controlScheme.hideList;"Enter"===t.key&&this.listShown&&i([e,s],13)&&t.preventDefault(),"Tab"===t.key&&this.hovered&&this.select(this.hovered),this.onShowList(t),this.moveSelection(t),this.onAutocomplete(t)},onListKeyUp:function(t){var e=this.controlScheme.select,s=this.controlScheme.hideList;this.listShown&&r([e,s],t)&&(t.preventDefault(),r(e,t)&&this.select(this.hovered),this.hideList())},onAutocomplete:function(t){r(this.controlScheme.autocomplete,t)&&(t.ctrlKey||t.shiftKey)&&0<this.suggestions.length&&this.suggestions[0]&&this.listShown&&(t.preventDefault(),this.hover(this.suggestions[0]),this.autocompleteText(this.suggestions[0]))},suggestionClick:function(t,e){this.$emit("suggestion-click",t,e),this.select(t),this.hideList(),this.isClicking=!1},onBlur:function(t){var e=this;this.isInFocus?(this.isClicking=this.hovered&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&(this.isFalseFocus=!0,setTimeout(function(){e.inputElement.focus()},0)):(this.isInFocus=!1,this.hideList(),this.$emit("blur",t))):(this.inputElement.blur(),console.error("This should never happen!\n If you encountered this error, please make sure that your input component emits 'focus' events properly.\n For more info see https://github.com/KazanExpress/vue-simple-suggest#custom-input.\n\n If your 'vue-simple-suggest' setup does not include a custom input component - please,\n report to https://github.com/KazanExpress/vue-simple-suggest/issues/new")),this.isTabbed=!1},onFocus:function(t){this.isInFocus=!0,t&&!this.isFalseFocus&&this.$emit("focus",t),this.isClicking||this.isFalseFocus||this.showSuggestions(),this.isFalseFocus=!1},onInput:function(t){var e=t.target?t.target.value:t;this.updateTextOutside(e),this.$emit("input",e)},updateTextOutside:function(t){this.text!==t&&(this.text=t,this.hovered&&this.hover(null),this.text.length<this.minLength?this.hideList():this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:function(){try{var s=this;return c(function(){return h(function(){return function(t){var e=t();if(e&&e.then)return e.then(u)}(function(){if(s.canSend){s.canSend=!1;var e=s.text;return o(s.getSuggestions(s.text),function(t){e===s.text&&s.$set(s,"suggestions",t)})}})},function(t){throw s.clearSuggestions(),t})},function(){return s.canSend=!0,0===s.suggestions.length&&s.miscSlotsAreEmpty()?s.hideList():s.isInFocus&&s.showList(),s.suggestions})}catch(t){return Promise.reject(t)}},getSuggestions:function(e){try{var s=this;if((e=e||"").length<s.minLength)return[];s.selected=null,s.listIsRequest&&s.$emit("request-start",e);var i=[];return c(function(){return h(function(){return l(function(){if(s.listIsRequest)return o(s.list(e),function(t){i=t||[]});i=s.list},function(){Array.isArray(i)||(i=[i]),s.isPlainSuggestion="object"!==n(i[0])||Array.isArray(i[0]),s.filterByQuery&&(i=i.filter(function(t){return s.filter(t,e)})),s.listIsRequest&&s.$emit("request-done",i)})},function(t){if(!s.listIsRequest)throw t;s.$emit("request-failed",t)})},function(){return s.maxSuggestions&&i.splice(s.maxSuggestions),i})}catch(t){return Promise.reject(t)}},clearSuggestions:function(){this.suggestions.splice(0)},getId:function(t,e){return this.listId+"-suggestion-"+(this.isPlainSuggestion?e:this.valueProperty(t)||e)}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",s),s}); |
{ | ||
"name": "vue-simple-suggest", | ||
"description": "Feature-rich autocomplete component for Vue.js", | ||
"version": "1.10.3", | ||
"version": "1.10.4", | ||
"author": "KazanExpress", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
190035
2131