vue-simple-suggest
Advanced tools
Comparing version 1.9.1 to 1.9.2
@@ -95,3 +95,4 @@ 'use strict'; | ||
return result.then(then); | ||
}return then(result); | ||
} | ||
return then(result); | ||
}function _awaitIgnored(value, direct) { | ||
@@ -113,5 +114,5 @@ if (!direct) { | ||
} } }, [!!this.$scopedSlots['misc-item-above'] ? _c('li', [_vm._t("misc-item-above", null, { suggestions: _vm.suggestions, query: _vm.text })], 2) : _vm._e(), _vm._v(" "), _vm._l(_vm.suggestions, function (suggestion, index) { | ||
return _c('li', { key: _vm.getId(suggestion, index), staticClass: "suggest-item", class: [_vm.styles.suggestItem, { selected: _vm.selected && _vm.valueProperty(suggestion) == _vm.valueProperty(_vm.selected), | ||
hover: _vm.hovered && _vm.valueProperty(_vm.hovered) == _vm.valueProperty(suggestion) | ||
}], attrs: { "role": "option", "aria-selected": _vm.hovered && _vm.valueProperty(_vm.hovered) == _vm.valueProperty(suggestion) ? 'true' : 'false', "id": _vm.getId(suggestion, index) }, on: { "mouseenter": function mouseenter($event) { | ||
return _c('li', { key: _vm.getId(suggestion, index), staticClass: "suggest-item", class: [_vm.styles.suggestItem, { selected: _vm.isSelected(suggestion), | ||
hover: _vm.isHovered(suggestion) | ||
}], attrs: { "role": "option", "aria-selected": _vm.isHovered(suggestion) || _vm.isSelected(suggestion) ? 'true' : 'false', "id": _vm.getId(suggestion, index) }, on: { "mouseenter": function mouseenter($event) { | ||
_vm.hover(suggestion, $event.target); | ||
@@ -126,5 +127,5 @@ }, "mouseleave": function mouseleave($event) { | ||
}), _vm._v(" "), !!this.$scopedSlots['misc-item-below'] ? _c('li', [_vm._t("misc-item-below", null, { suggestions: _vm.suggestions, query: _vm.text })], 2) : _vm._e()], 2) : _vm._e()])], 1); | ||
}, | ||
staticRenderFns: [], | ||
name: 'vue-simple-suggest', model: { | ||
}, staticRenderFns: [], | ||
name: 'vue-simple-suggest', | ||
model: { | ||
prop: 'value', | ||
@@ -139,4 +140,3 @@ event: 'input' | ||
} | ||
}, | ||
controls: { | ||
}, controls: { | ||
type: Object, | ||
@@ -308,2 +308,11 @@ default: function _default() { | ||
methods: { | ||
isEqual: function isEqual(suggestion, item) { | ||
return item && this.valueProperty(suggestion) == this.valueProperty(item); | ||
}, | ||
isSelected: function isSelected(suggestion) { | ||
return this.isEqual(suggestion, this.selected); | ||
}, | ||
isHovered: function isHovered(suggestion) { | ||
return this.isEqual(suggestion, this.hovered); | ||
}, | ||
onSubmit: function onSubmit(e) { | ||
@@ -385,6 +394,30 @@ if (this.preventSubmit && e.key === 'Enter') { | ||
displayProperty: function displayProperty(obj) { | ||
return String(this.getPropertyByAttribute(obj, this.displayAttribute)); | ||
if (this.isPlainSuggestion) { | ||
return obj; | ||
} | ||
var display = this.getPropertyByAttribute(obj, this.displayAttribute); | ||
if (typeof display === 'undefined') { | ||
display = JSON.stringify(obj); | ||
if (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.'); | ||
} | ||
} | ||
return String(display); | ||
}, | ||
valueProperty: function valueProperty(obj) { | ||
return this.getPropertyByAttribute(obj, this.valueAttribute); | ||
if (this.isPlainSuggestion) { | ||
return obj; | ||
} | ||
var value = this.getPropertyByAttribute(obj, this.valueAttribute); | ||
if (typeof value === 'undefined') { | ||
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.'); | ||
} | ||
return value; | ||
}, | ||
@@ -409,6 +442,9 @@ | ||
select: function select(item) { | ||
if (this.selected !== item) { | ||
if (this.selected !== item || this.nullableSelect && !item) { | ||
this.selected = item; | ||
this.$emit('select', item); | ||
this.setText(this.displayProperty(item)); | ||
if (item) { | ||
this.setText(this.displayProperty(item)); | ||
} | ||
} | ||
@@ -488,3 +524,3 @@ | ||
if (this.listShown) { | ||
if (hasKeyCode(select, e) && (this.nullableSelect || this.hovered)) { | ||
if (hasKeyCode(select, e)) { | ||
this.select(this.hovered); | ||
@@ -682,3 +718,3 @@ } | ||
getId: function getId(value, i) { | ||
return this.listId + '-suggestion-' + (this.isPlainSuggestion ? i : this.valueProperty(value)); | ||
return this.listId + '-suggestion-' + (this.isPlainSuggestion ? i : this.valueProperty(value) || i); | ||
} | ||
@@ -685,0 +721,0 @@ } |
@@ -79,3 +79,4 @@ const defaultControls = { | ||
return result.then(then); | ||
}return then(result); | ||
} | ||
return then(result); | ||
}function _awaitIgnored(value, direct) { | ||
@@ -97,5 +98,5 @@ if (!direct) { | ||
} } }, [!!this.$scopedSlots['misc-item-above'] ? _c('li', [_vm._t("misc-item-above", null, { suggestions: _vm.suggestions, query: _vm.text })], 2) : _vm._e(), _vm._v(" "), _vm._l(_vm.suggestions, function (suggestion, index) { | ||
return _c('li', { key: _vm.getId(suggestion, index), staticClass: "suggest-item", class: [_vm.styles.suggestItem, { selected: _vm.selected && _vm.valueProperty(suggestion) == _vm.valueProperty(_vm.selected), | ||
hover: _vm.hovered && _vm.valueProperty(_vm.hovered) == _vm.valueProperty(suggestion) | ||
}], attrs: { "role": "option", "aria-selected": _vm.hovered && _vm.valueProperty(_vm.hovered) == _vm.valueProperty(suggestion) ? 'true' : 'false', "id": _vm.getId(suggestion, index) }, on: { "mouseenter": function ($event) { | ||
return _c('li', { key: _vm.getId(suggestion, index), staticClass: "suggest-item", class: [_vm.styles.suggestItem, { selected: _vm.isSelected(suggestion), | ||
hover: _vm.isHovered(suggestion) | ||
}], attrs: { "role": "option", "aria-selected": _vm.isHovered(suggestion) || _vm.isSelected(suggestion) ? 'true' : 'false', "id": _vm.getId(suggestion, index) }, on: { "mouseenter": function ($event) { | ||
_vm.hover(suggestion, $event.target); | ||
@@ -110,5 +111,5 @@ }, "mouseleave": function ($event) { | ||
}), _vm._v(" "), !!this.$scopedSlots['misc-item-below'] ? _c('li', [_vm._t("misc-item-below", null, { suggestions: _vm.suggestions, query: _vm.text })], 2) : _vm._e()], 2) : _vm._e()])], 1); | ||
}, | ||
staticRenderFns: [], | ||
name: 'vue-simple-suggest', model: { | ||
}, staticRenderFns: [], | ||
name: 'vue-simple-suggest', | ||
model: { | ||
prop: 'value', | ||
@@ -121,4 +122,3 @@ event: 'input' | ||
default: () => ({}) | ||
}, | ||
controls: { | ||
}, controls: { | ||
type: Object, | ||
@@ -274,2 +274,11 @@ default: () => defaultControls | ||
methods: { | ||
isEqual(suggestion, item) { | ||
return item && this.valueProperty(suggestion) == this.valueProperty(item); | ||
}, | ||
isSelected(suggestion) { | ||
return this.isEqual(suggestion, this.selected); | ||
}, | ||
isHovered(suggestion) { | ||
return this.isEqual(suggestion, this.hovered); | ||
}, | ||
onSubmit(e) { | ||
@@ -339,6 +348,31 @@ if (this.preventSubmit && e.key === 'Enter') { | ||
displayProperty(obj) { | ||
return String(this.getPropertyByAttribute(obj, this.displayAttribute)); | ||
if (this.isPlainSuggestion) { | ||
return obj; | ||
} | ||
let display = this.getPropertyByAttribute(obj, this.displayAttribute); | ||
if (typeof display === 'undefined') { | ||
display = JSON.stringify(obj); | ||
if (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.'); | ||
} | ||
} | ||
return String(display); | ||
}, | ||
valueProperty(obj) { | ||
return this.getPropertyByAttribute(obj, this.valueAttribute); | ||
if (this.isPlainSuggestion) { | ||
return obj; | ||
} | ||
const value = this.getPropertyByAttribute(obj, this.valueAttribute); | ||
if (typeof value === 'undefined') { | ||
console.error(`[vue-simple-suggest]: Please, check if you passed 'value-attribute' (default is 'id') and 'display-attribute' (default is 'title') props correctly. | ||
Your list objects should always contain a unique identifier.`); | ||
} | ||
return value; | ||
}, | ||
@@ -360,6 +394,9 @@ | ||
select(item) { | ||
if (this.selected !== item) { | ||
if (this.selected !== item || this.nullableSelect && !item) { | ||
this.selected = item; | ||
this.$emit('select', item); | ||
this.setText(this.displayProperty(item)); | ||
if (item) { | ||
this.setText(this.displayProperty(item)); | ||
} | ||
} | ||
@@ -440,3 +477,3 @@ | ||
if (this.listShown) { | ||
if (hasKeyCode(select, e) && (this.nullableSelect || this.hovered)) { | ||
if (hasKeyCode(select, e)) { | ||
this.select(this.hovered); | ||
@@ -512,3 +549,4 @@ } | ||
} | ||
}, onInput(inputEvent) { | ||
}, | ||
onInput(inputEvent) { | ||
const value = !inputEvent.target ? inputEvent : inputEvent.target.value; | ||
@@ -634,3 +672,3 @@ | ||
getId(value, i) { | ||
return `${this.listId}-suggestion-${this.isPlainSuggestion ? i : this.valueProperty(value)}`; | ||
return `${this.listId}-suggestion-${this.isPlainSuggestion ? i : this.valueProperty(value) || i}`; | ||
} | ||
@@ -637,0 +675,0 @@ } |
@@ -41,5 +41,5 @@ const defaultControls = { | ||
return _c('li', { key: _vm.getId(suggestion, index), staticClass: "suggest-item", class: [_vm.styles.suggestItem, { | ||
selected: _vm.selected && _vm.valueProperty(suggestion) == _vm.valueProperty(_vm.selected), | ||
hover: _vm.hovered && _vm.valueProperty(_vm.hovered) == _vm.valueProperty(suggestion) | ||
}], attrs: { "role": "option", "aria-selected": _vm.hovered && _vm.valueProperty(_vm.hovered) == _vm.valueProperty(suggestion) ? 'true' : 'false', "id": _vm.getId(suggestion, index) }, on: { "mouseenter": function ($event) { | ||
selected: _vm.isSelected(suggestion), | ||
hover: _vm.isHovered(suggestion) | ||
}], attrs: { "role": "option", "aria-selected": _vm.isHovered(suggestion) || _vm.isSelected(suggestion) ? 'true' : 'false', "id": _vm.getId(suggestion, index) }, on: { "mouseenter": function ($event) { | ||
_vm.hover(suggestion, $event.target); | ||
@@ -217,2 +217,11 @@ }, "mouseleave": function ($event) { | ||
methods: { | ||
isEqual(suggestion, item) { | ||
return item && this.valueProperty(suggestion) == this.valueProperty(item); | ||
}, | ||
isSelected(suggestion) { | ||
return this.isEqual(suggestion, this.selected); | ||
}, | ||
isHovered(suggestion) { | ||
return this.isEqual(suggestion, this.hovered); | ||
}, | ||
onSubmit(e) { | ||
@@ -282,6 +291,31 @@ if (this.preventSubmit && e.key === 'Enter') { | ||
displayProperty(obj) { | ||
return String(this.getPropertyByAttribute(obj, this.displayAttribute)); | ||
if (this.isPlainSuggestion) { | ||
return obj; | ||
} | ||
let display = this.getPropertyByAttribute(obj, this.displayAttribute); | ||
if (typeof display === 'undefined') { | ||
display = JSON.stringify(obj); | ||
if (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.'); | ||
} | ||
} | ||
return String(display); | ||
}, | ||
valueProperty(obj) { | ||
return this.getPropertyByAttribute(obj, this.valueAttribute); | ||
if (this.isPlainSuggestion) { | ||
return obj; | ||
} | ||
const value = this.getPropertyByAttribute(obj, this.valueAttribute); | ||
if (typeof value === 'undefined') { | ||
console.error(`[vue-simple-suggest]: Please, check if you passed 'value-attribute' (default is 'id') and 'display-attribute' (default is 'title') props correctly. | ||
Your list objects should always contain a unique identifier.`); | ||
} | ||
return value; | ||
}, | ||
@@ -303,6 +337,9 @@ | ||
select(item) { | ||
if (this.selected !== item) { | ||
if (this.selected !== item || this.nullableSelect && !item) { | ||
this.selected = item; | ||
this.$emit('select', item); | ||
this.setText(this.displayProperty(item)); | ||
if (item) { | ||
this.setText(this.displayProperty(item)); | ||
} | ||
} | ||
@@ -378,3 +415,3 @@ | ||
if (this.listShown) { | ||
if (hasKeyCode(select, e) && (this.nullableSelect || this.hovered)) { | ||
if (hasKeyCode(select, e)) { | ||
this.select(this.hovered); | ||
@@ -554,3 +591,3 @@ } | ||
getId(value, i) { | ||
return `${this.listId}-suggestion-${this.isPlainSuggestion ? i : this.valueProperty(value)}`; | ||
return `${this.listId}-suggestion-${this.isPlainSuggestion ? i : this.valueProperty(value) || i}`; | ||
} | ||
@@ -557,0 +594,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var VueSimpleSuggest=function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],autocomplete:[32,13]},e={input:String,select:Object};function i(t,e){if(t.length<=0)return!1;var i=function(t){return t.some(function(t){return t===e.keyCode})};return Array.isArray(t[0])?t.some(function(t){return i(t)}):i(t)}var s="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},n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}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={render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("div",{staticClass:"vue-simple-suggest",class:[t.styles.vueSimpleSuggest,{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",class:t.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":t.listId,"aria-expanded":t.listShown&&!t.removeList?"true":"false"}},[t._t("default",[i("input",t._b({staticClass:"default-input",class:t.styles.defaultInput,domProps:{value:t.text||""}},"input",t.$attrs,!1))])],2),t._v(" "),i("transition",{attrs:{name:"vue-simple-suggest"}},[t.listShown&&!t.removeList?i("ul",{staticClass:"suggestions",class:t.styles.suggestions,attrs:{id:t.listId,role:"listbox","aria-labelledby":t.listId},on:{mouseenter:function(e){t.hoverList(!0)},mouseleave:function(e){t.hoverList(!1)}}},[this.$scopedSlots["misc-item-above"]?i("li",[t._t("misc-item-above",null,{suggestions:t.suggestions,query:t.text})],2):t._e(),t._v(" "),t._l(t.suggestions,function(e,s){return i("li",{key:t.getId(e,s),staticClass:"suggest-item",class:[t.styles.suggestItem,{selected:t.selected&&t.valueProperty(e)==t.valueProperty(t.selected),hover:t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)}],attrs:{role:"option","aria-selected":t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)?"true":"false",id:t.getId(e,s)},on:{mouseenter:function(i){t.hover(e,i.target)},mouseleave:function(e){t.hover(void 0)},click:function(i){t.suggestionClick(e,i)}}},[t._t("suggestion-item",[i("span",[t._v(t._s(t.displayProperty(e)))])],{autocomplete:function(){return t.setText(t.displayProperty(e))},suggestion:e,query:t.text})],2)}),t._v(" "),this.$scopedSlots["misc-item-below"]?i("li",[t._t("misc-item-below",null,{suggestions:t.suggestions,query:t.text})],2):t._e()],2):t._e()])],1)},staticRenderFns:[],name:"vue-simple-suggest",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},preventSubmit:{type:Boolean,default:!0},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:event,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t,e){var i=this;this.constructor.options.model.event=t,this.$parent&&this.$parent.$forceUpdate(),this.$nextTick(function(){"input"===t?i.$emit("input",i.text):i.$emit("select",i.selected)})},immediate:!0},value:{handler:function(t){"string"==typeof t?this.text=t:t&&(this.text=this.displayProperty(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,isFalseFocus:!1,isTabbed:!1,controlScheme:{},listId:this._uid+"-suggestions"}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&this.$slots.default.length>0&&!!this.$slots.default[0].componentInstance},input:function(){return this.inputIsComponent?this.$slots.default[0].componentInstance:this.inputElement},on:function(){return this.inputIsComponent?"$on":"addEventListener"},off:function(){return this.inputIsComponent?"$off":"removeEventListener"},hoveredIndex:function(){var t=this;return this.suggestions.findIndex(function(e){return t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)})},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0},isSelectedUpToDate:function(){return!!this.selected&&this.displayProperty(this.selected)===this.text}},created:function(){this.controlScheme=n({},t,this.controls)},mounted:function(){this.inputElement=this.$refs.inputSlot.querySelector("input"),this.setInputAriaAttributes(),this.prepareEventHandlers(!0)},beforeDestroy:function(){this.prepareEventHandlers(!1)},methods:{onSubmit:function(t){this.preventSubmit&&"Enter"===t.key&&(t.stopPropagation(),t.preventDefault())},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,i=this[t?"on":"off"],s={click:this.showSuggestions,keydown:function(t){return e.moveSelection(t),e.onAutocomplete(t)},keyup:this.onListKeyUp},o=n({blur:this.onBlur,focus:this.onFocus,input:this.onInput},s);for(var r in o)this.input[i](r,o[r]);var u=t?"addEventListener":"removeEventListener";for(var l in s)this.inputElement[u](l,s[l]);if(!0===this.preventSubmit){var c=this.$el.closest("form");c&&c[u]("keydown",this.onSubmit)}},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":s(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.setText(t)},setText:function(t){var e=this;this.$nextTick(function(){e.$emit("input",t),e.inputElement.value=t,e.text=t})},select:function(t){this.selected!==t&&(this.selected=t,this.$emit("select",t),this.setText(this.displayProperty(t))),this.hover(null)},hover:function(t,e){var i=t?this.getId(t,this.hoveredIndex):"";this.inputElement.setAttribute("aria-activedescendant",i),t&&t!==this.hovered&&this.$emit("hover",t,e),this.hovered=t},hoverList:function(t){this.isOverList=t},hideList:function(){this.listShown&&(this.listShown=!1,this.hover(null),this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(this.suggestions.length>0||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:l(function(){var t=this;return c(function(){if(0===t.suggestions.length&&t.minLength===t.textLength)return function(t,e){if(!e)return Promise.resolve(t).then(h)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(this.listShown&&this.suggestions.length&&i([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=i(this.controlScheme.selectionDown,t),s=2*e-1,n=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+s]:this.suggestions[n]:this.selected||this.suggestions[n],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.nullableSelect||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.setText(this.displayProperty(this.suggestions[0])))},suggestionClick:function(t,e){var i=this;this.$emit("suggestion-click",t,e),this.select(t),this.isClicking=this.isOverList=!1,this.$nextTick(function(){i.hideList()})},onBlur:function(t){var e=this;this.isInFocus?(this.isClicking=this.isOverList&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&(this.isFalseFocus=!0,this.$nextTick(function(){e.inputElement.focus()})):(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.isFalseFocus=!1,this.isClicking||this.showSuggestions()},onInput:function(t){var e=t.target?t.target.value:t;this.text!==e&&(this.text=e,this.$emit("input",this.text),this.hovered&&this.hover(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)})}})},function(e){throw t.clearSuggestions(),e})},function(){return t.canSend=!0,0===t.suggestions.length&&t.miscSlotsAreEmpty()?t.hideList():t.showList(),t.suggestions})}),getSuggestions:l(function(t){var e=this;if((t=t||"").length<e.minLength)return e.listShown?(e.hideList(),[]):e.suggestions;e.selected=null,e.listIsRequest&&(e.$emit("request-start",t),(e.suggestions.length>0||!e.miscSlotsAreEmpty())&&e.showList());var i=[];return o(function(){return r(function(){return c(function(){if(e.listIsRequest)return u(e.list(t),function(t){i=t||[]});i=e.list},function(){Array.isArray(i)||(i=[i]),e.isPlainSuggestion="object"!==s(i[0])||Array.isArray(i[0]),e.filterByQuery&&(i=i.filter(function(i){return e.filter(i,t)})),e.listIsRequest&&e.$emit("request-done",i)})},function(t){if(!e.listIsRequest)throw t;e.$emit("request-failed",t)})},function(){return e.maxSuggestions&&i.splice(e.maxSuggestions),i})}),clearSuggestions:function(){this.suggestions.splice(0)},getId:function(t,e){return this.listId+"-suggestion-"+(this.isPlainSuggestion?e:this.valueProperty(t))}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",a),a}(); | ||
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 s="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},n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}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={render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("div",{staticClass:"vue-simple-suggest",class:[t.styles.vueSimpleSuggest,{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",class:t.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":t.listId,"aria-expanded":t.listShown&&!t.removeList?"true":"false"}},[t._t("default",[i("input",t._b({staticClass:"default-input",class:t.styles.defaultInput,domProps:{value:t.text||""}},"input",t.$attrs,!1))])],2),t._v(" "),i("transition",{attrs:{name:"vue-simple-suggest"}},[t.listShown&&!t.removeList?i("ul",{staticClass:"suggestions",class:t.styles.suggestions,attrs:{id:t.listId,role:"listbox","aria-labelledby":t.listId},on:{mouseenter:function(e){t.hoverList(!0)},mouseleave:function(e){t.hoverList(!1)}}},[this.$scopedSlots["misc-item-above"]?i("li",[t._t("misc-item-above",null,{suggestions:t.suggestions,query:t.text})],2):t._e(),t._v(" "),t._l(t.suggestions,function(e,s){return i("li",{key:t.getId(e,s),staticClass:"suggest-item",class:[t.styles.suggestItem,{selected:t.isSelected(e),hover:t.isHovered(e)}],attrs:{role:"option","aria-selected":t.isHovered(e)||t.isSelected(e)?"true":"false",id:t.getId(e,s)},on:{mouseenter:function(i){t.hover(e,i.target)},mouseleave:function(e){t.hover(void 0)},click:function(i){t.suggestionClick(e,i)}}},[t._t("suggestion-item",[i("span",[t._v(t._s(t.displayProperty(e)))])],{autocomplete:function(){return t.setText(t.displayProperty(e))},suggestion:e,query:t.text})],2)}),t._v(" "),this.$scopedSlots["misc-item-below"]?i("li",[t._t("misc-item-below",null,{suggestions:t.suggestions,query:t.text})],2):t._e()],2):t._e()])],1)},staticRenderFns:[],name:"vue-simple-suggest",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},preventSubmit:{type:Boolean,default:!0},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:event,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t,e){var i=this;this.constructor.options.model.event=t,this.$parent&&this.$parent.$forceUpdate(),this.$nextTick(function(){"input"===t?i.$emit("input",i.text):i.$emit("select",i.selected)})},immediate:!0},value:{handler:function(t){"string"==typeof t?this.text=t:t&&(this.text=this.displayProperty(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,isFalseFocus:!1,isTabbed:!1,controlScheme:{},listId:this._uid+"-suggestions"}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&this.$slots.default.length>0&&!!this.$slots.default[0].componentInstance},input:function(){return this.inputIsComponent?this.$slots.default[0].componentInstance:this.inputElement},on:function(){return this.inputIsComponent?"$on":"addEventListener"},off:function(){return this.inputIsComponent?"$off":"removeEventListener"},hoveredIndex:function(){var t=this;return this.suggestions.findIndex(function(e){return t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)})},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0},isSelectedUpToDate:function(){return!!this.selected&&this.displayProperty(this.selected)===this.text}},created:function(){this.controlScheme=n({},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)},onSubmit:function(t){this.preventSubmit&&"Enter"===t.key&&(t.stopPropagation(),t.preventDefault())},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,i=this[t?"on":"off"],s={click:this.showSuggestions,keydown:function(t){return e.moveSelection(t),e.onAutocomplete(t)},keyup:this.onListKeyUp},o=n({blur:this.onBlur,focus:this.onFocus,input:this.onInput},s);for(var r in o)this.input[i](r,o[r]);var u=t?"addEventListener":"removeEventListener";for(var l in s)this.inputElement[u](l,s[l]);if(!0===this.preventSubmit){var c=this.$el.closest("form");c&&c[u]("keydown",this.onSubmit)}},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":s(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){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(t)},setText:function(t){var e=this;this.$nextTick(function(){e.$emit("input",t),e.inputElement.value=t,e.text=t})},select:function(t){(this.selected!==t||this.nullableSelect&&!t)&&(this.selected=t,this.$emit("select",t),t&&this.setText(this.displayProperty(t))),this.hover(null)},hover:function(t,e){var i=t?this.getId(t,this.hoveredIndex):"";this.inputElement.setAttribute("aria-activedescendant",i),t&&t!==this.hovered&&this.$emit("hover",t,e),this.hovered=t},hoverList:function(t){this.isOverList=t},hideList:function(){this.listShown&&(this.listShown=!1,this.hover(null),this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(this.suggestions.length>0||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:l(function(){var t=this;return c(function(){if(0===t.suggestions.length&&t.minLength===t.textLength)return function(t,e){if(!e)return Promise.resolve(t).then(h)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(this.listShown&&this.suggestions.length&&i([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=i(this.controlScheme.selectionDown,t),s=2*e-1,n=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+s]:this.suggestions[n]:this.selected||this.suggestions[n],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.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.setText(this.displayProperty(this.suggestions[0])))},suggestionClick:function(t,e){var i=this;this.$emit("suggestion-click",t,e),this.select(t),this.isClicking=this.isOverList=!1,this.$nextTick(function(){i.hideList()})},onBlur:function(t){var e=this;this.isInFocus?(this.isClicking=this.isOverList&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&(this.isFalseFocus=!0,this.$nextTick(function(){e.inputElement.focus()})):(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.isFalseFocus=!1,this.isClicking||this.showSuggestions()},onInput:function(t){var e=t.target?t.target.value:t;this.text!==e&&(this.text=e,this.$emit("input",this.text),this.hovered&&this.hover(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)})}})},function(e){throw t.clearSuggestions(),e})},function(){return t.canSend=!0,0===t.suggestions.length&&t.miscSlotsAreEmpty()?t.hideList():t.showList(),t.suggestions})}),getSuggestions:l(function(t){var e=this;if((t=t||"").length<e.minLength)return e.listShown?(e.hideList(),[]):e.suggestions;e.selected=null,e.listIsRequest&&(e.$emit("request-start",t),(e.suggestions.length>0||!e.miscSlotsAreEmpty())&&e.showList());var i=[];return o(function(){return r(function(){return c(function(){if(e.listIsRequest)return u(e.list(t),function(t){i=t||[]});i=e.list},function(){Array.isArray(i)||(i=[i]),e.isPlainSuggestion="object"!==s(i[0])||Array.isArray(i[0]),e.filterByQuery&&(i=i.filter(function(i){return e.filter(i,t)})),e.listIsRequest&&e.$emit("request-done",i)})},function(t){if(!e.listIsRequest)throw t;e.$emit("request-failed",t)})},function(){return e.maxSuggestions&&i.splice(e.maxSuggestions),i})}),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",a),a}(); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueSimpleSuggest=e()}(this,function(){"use strict";var t={selectionUp:[38],selectionDown:[40],select:[13],hideList:[27],autocomplete:[32,13]},e={input:String,select:Object};function i(t,e){if(t.length<=0)return!1;var i=function(t){return t.some(function(t){return t===e.keyCode})};return Array.isArray(t[0])?t.some(function(t){return i(t)}):i(t)}var s="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 n(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={render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("div",{staticClass:"vue-simple-suggest",class:[t.styles.vueSimpleSuggest,{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",class:t.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":t.listId,"aria-expanded":t.listShown&&!t.removeList?"true":"false"}},[t._t("default",[i("input",t._b({staticClass:"default-input",class:t.styles.defaultInput,domProps:{value:t.text||""}},"input",t.$attrs,!1))])],2),t._v(" "),i("transition",{attrs:{name:"vue-simple-suggest"}},[t.listShown&&!t.removeList?i("ul",{staticClass:"suggestions",class:t.styles.suggestions,attrs:{id:t.listId,role:"listbox","aria-labelledby":t.listId},on:{mouseenter:function(e){t.hoverList(!0)},mouseleave:function(e){t.hoverList(!1)}}},[this.$scopedSlots["misc-item-above"]?i("li",[t._t("misc-item-above",null,{suggestions:t.suggestions,query:t.text})],2):t._e(),t._v(" "),t._l(t.suggestions,function(e,s){return i("li",{key:t.getId(e,s),staticClass:"suggest-item",class:[t.styles.suggestItem,{selected:t.selected&&t.valueProperty(e)==t.valueProperty(t.selected),hover:t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)}],attrs:{role:"option","aria-selected":t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)?"true":"false",id:t.getId(e,s)},on:{mouseenter:function(i){t.hover(e,i.target)},mouseleave:function(e){t.hover(void 0)},click:function(i){t.suggestionClick(e,i)}}},[t._t("suggestion-item",[i("span",[t._v(t._s(t.displayProperty(e)))])],{autocomplete:function(){return t.setText(t.displayProperty(e))},suggestion:e,query:t.text})],2)}),t._v(" "),this.$scopedSlots["misc-item-below"]?i("li",[t._t("misc-item-below",null,{suggestions:t.suggestions,query:t.text})],2):t._e()],2):t._e()])],1)},staticRenderFns:[],name:"vue-simple-suggest",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},preventSubmit:{type:Boolean,default:!0},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:event,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t,e){var i=this;this.constructor.options.model.event=t,this.$parent&&this.$parent.$forceUpdate(),this.$nextTick(function(){"input"===t?i.$emit("input",i.text):i.$emit("select",i.selected)})},immediate:!0},value:{handler:function(t){"string"==typeof t?this.text=t:t&&(this.text=this.displayProperty(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,isFalseFocus:!1,isTabbed:!1,controlScheme:{},listId:this._uid+"-suggestions"}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&this.$slots.default.length>0&&!!this.$slots.default[0].componentInstance},input:function(){return this.inputIsComponent?this.$slots.default[0].componentInstance:this.inputElement},on:function(){return this.inputIsComponent?"$on":"addEventListener"},off:function(){return this.inputIsComponent?"$off":"removeEventListener"},hoveredIndex:function(){var t=this;return this.suggestions.findIndex(function(e){return t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)})},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0},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:{onSubmit:function(t){this.preventSubmit&&"Enter"===t.key&&(t.stopPropagation(),t.preventDefault())},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,i=this[t?"on":"off"],s={click:this.showSuggestions,keydown:function(t){return e.moveSelection(t),e.onAutocomplete(t)},keyup:this.onListKeyUp},n=Object.assign({blur:this.onBlur,focus:this.onFocus,input:this.onInput},s);for(var o in n)this.input[i](o,n[o]);var r=t?"addEventListener":"removeEventListener";for(var u in s)this.inputElement[r](u,s[u]);if(!0===this.preventSubmit){var l=this.$el.closest("form");l&&l[r]("keydown",this.onSubmit)}},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":s(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.setText(t)},setText:function(t){var e=this;this.$nextTick(function(){e.$emit("input",t),e.inputElement.value=t,e.text=t})},select:function(t){this.selected!==t&&(this.selected=t,this.$emit("select",t),this.setText(this.displayProperty(t))),this.hover(null)},hover:function(t,e){var i=t?this.getId(t,this.hoveredIndex):"";this.inputElement.setAttribute("aria-activedescendant",i),t&&t!==this.hovered&&this.$emit("hover",t,e),this.hovered=t},hoverList:function(t){this.isOverList=t},hideList:function(){this.listShown&&(this.listShown=!1,this.hover(null),this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(this.suggestions.length>0||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:u(function(){var t=this;return l(function(){if(0===t.suggestions.length&&t.minLength===t.textLength)return function(t,e){if(!e)return Promise.resolve(t).then(c)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(this.listShown&&this.suggestions.length&&i([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=i(this.controlScheme.selectionDown,t),s=2*e-1,n=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+s]:this.suggestions[n]:this.selected||this.suggestions[n],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.nullableSelect||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.setText(this.displayProperty(this.suggestions[0])))},suggestionClick:function(t,e){var i=this;this.$emit("suggestion-click",t,e),this.select(t),this.isClicking=this.isOverList=!1,this.$nextTick(function(){i.hideList()})},onBlur:function(t){var e=this;this.isInFocus?(this.isClicking=this.isOverList&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&(this.isFalseFocus=!0,this.$nextTick(function(){e.inputElement.focus()})):(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.isFalseFocus=!1,this.isClicking||this.showSuggestions()},onInput:function(t){var e=t.target?t.target.value:t;this.text!==e&&(this.text=e,this.$emit("input",this.text),this.hovered&&this.hover(null),this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:u(function(){var t=this;return n(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)})}})},function(e){throw t.clearSuggestions(),e})},function(){return t.canSend=!0,0===t.suggestions.length&&t.miscSlotsAreEmpty()?t.hideList():t.showList(),t.suggestions})}),getSuggestions:u(function(t){var e=this;if((t=t||"").length<e.minLength)return e.listShown?(e.hideList(),[]):e.suggestions;e.selected=null,e.listIsRequest&&(e.$emit("request-start",t),(e.suggestions.length>0||!e.miscSlotsAreEmpty())&&e.showList());var i=[];return n(function(){return o(function(){return l(function(){if(e.listIsRequest)return r(e.list(t),function(t){i=t||[]});i=e.list},function(){Array.isArray(i)||(i=[i]),e.isPlainSuggestion="object"!==s(i[0])||Array.isArray(i[0]),e.filterByQuery&&(i=i.filter(function(i){return e.filter(i,t)})),e.listIsRequest&&e.$emit("request-done",i)})},function(t){if(!e.listIsRequest)throw t;e.$emit("request-failed",t)})},function(){return e.maxSuggestions&&i.splice(e.maxSuggestions),i})}),clearSuggestions:function(){this.suggestions.splice(0)},getId:function(t,e){return this.listId+"-suggestion-"+(this.isPlainSuggestion?e:this.valueProperty(t))}}};return(Vue||window&&window.Vue)&&(Vue||window.Vue).component("vue-simple-suggest",h),h}); | ||
!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 s="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 n(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={render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("div",{staticClass:"vue-simple-suggest",class:[t.styles.vueSimpleSuggest,{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",class:t.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":t.listId,"aria-expanded":t.listShown&&!t.removeList?"true":"false"}},[t._t("default",[i("input",t._b({staticClass:"default-input",class:t.styles.defaultInput,domProps:{value:t.text||""}},"input",t.$attrs,!1))])],2),t._v(" "),i("transition",{attrs:{name:"vue-simple-suggest"}},[t.listShown&&!t.removeList?i("ul",{staticClass:"suggestions",class:t.styles.suggestions,attrs:{id:t.listId,role:"listbox","aria-labelledby":t.listId},on:{mouseenter:function(e){t.hoverList(!0)},mouseleave:function(e){t.hoverList(!1)}}},[this.$scopedSlots["misc-item-above"]?i("li",[t._t("misc-item-above",null,{suggestions:t.suggestions,query:t.text})],2):t._e(),t._v(" "),t._l(t.suggestions,function(e,s){return i("li",{key:t.getId(e,s),staticClass:"suggest-item",class:[t.styles.suggestItem,{selected:t.isSelected(e),hover:t.isHovered(e)}],attrs:{role:"option","aria-selected":t.isHovered(e)||t.isSelected(e)?"true":"false",id:t.getId(e,s)},on:{mouseenter:function(i){t.hover(e,i.target)},mouseleave:function(e){t.hover(void 0)},click:function(i){t.suggestionClick(e,i)}}},[t._t("suggestion-item",[i("span",[t._v(t._s(t.displayProperty(e)))])],{autocomplete:function(){return t.setText(t.displayProperty(e))},suggestion:e,query:t.text})],2)}),t._v(" "),this.$scopedSlots["misc-item-below"]?i("li",[t._t("misc-item-below",null,{suggestions:t.suggestions,query:t.text})],2):t._e()],2):t._e()])],1)},staticRenderFns:[],name:"vue-simple-suggest",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},preventSubmit:{type:Boolean,default:!0},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:event,validator:function(t){return!!~Object.keys(e).indexOf(t.toLowerCase())}}},watch:{mode:{handler:function(t,e){var i=this;this.constructor.options.model.event=t,this.$parent&&this.$parent.$forceUpdate(),this.$nextTick(function(){"input"===t?i.$emit("input",i.text):i.$emit("select",i.selected)})},immediate:!0},value:{handler:function(t){"string"==typeof t?this.text=t:t&&(this.text=this.displayProperty(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,isFalseFocus:!1,isTabbed:!1,controlScheme:{},listId:this._uid+"-suggestions"}},computed:{listIsRequest:function(){return"function"==typeof this.list},inputIsComponent:function(){return this.$slots.default&&this.$slots.default.length>0&&!!this.$slots.default[0].componentInstance},input:function(){return this.inputIsComponent?this.$slots.default[0].componentInstance:this.inputElement},on:function(){return this.inputIsComponent?"$on":"addEventListener"},off:function(){return this.inputIsComponent?"$off":"removeEventListener"},hoveredIndex:function(){var t=this;return this.suggestions.findIndex(function(e){return t.hovered&&t.valueProperty(t.hovered)==t.valueProperty(e)})},textLength:function(){return this.text&&this.text.length||this.inputElement.value.length||0},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)},onSubmit:function(t){this.preventSubmit&&"Enter"===t.key&&(t.stopPropagation(),t.preventDefault())},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,i=this[t?"on":"off"],s={click:this.showSuggestions,keydown:function(t){return e.moveSelection(t),e.onAutocomplete(t)},keyup:this.onListKeyUp},n=Object.assign({blur:this.onBlur,focus:this.onFocus,input:this.onInput},s);for(var o in n)this.input[i](o,n[o]);var r=t?"addEventListener":"removeEventListener";for(var u in s)this.inputElement[r](u,s[u]);if(!0===this.preventSubmit){var l=this.$el.closest("form");l&&l[r]("keydown",this.onSubmit)}},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":s(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){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(t)},setText:function(t){var e=this;this.$nextTick(function(){e.$emit("input",t),e.inputElement.value=t,e.text=t})},select:function(t){(this.selected!==t||this.nullableSelect&&!t)&&(this.selected=t,this.$emit("select",t),t&&this.setText(this.displayProperty(t))),this.hover(null)},hover:function(t,e){var i=t?this.getId(t,this.hoveredIndex):"";this.inputElement.setAttribute("aria-activedescendant",i),t&&t!==this.hovered&&this.$emit("hover",t,e),this.hovered=t},hoverList:function(t){this.isOverList=t},hideList:function(){this.listShown&&(this.listShown=!1,this.hover(null),this.$emit("hide-list"))},showList:function(){this.listShown||this.textLength>=this.minLength&&(this.suggestions.length>0||!this.miscSlotsAreEmpty())&&(this.listShown=!0,this.$emit("show-list"))},showSuggestions:u(function(){var t=this;return l(function(){if(0===t.suggestions.length&&t.minLength===t.textLength)return function(t,e){if(!e)return Promise.resolve(t).then(c)}(t.research())},function(){t.showList()})}),moveSelection:function(t){if(this.listShown&&this.suggestions.length&&i([this.controlScheme.selectionUp,this.controlScheme.selectionDown],t)){t.preventDefault(),this.showSuggestions();var e=i(this.controlScheme.selectionDown,t),s=2*e-1,n=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+s]:this.suggestions[n]:this.selected||this.suggestions[n],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.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.setText(this.displayProperty(this.suggestions[0])))},suggestionClick:function(t,e){var i=this;this.$emit("suggestion-click",t,e),this.select(t),this.isClicking=this.isOverList=!1,this.$nextTick(function(){i.hideList()})},onBlur:function(t){var e=this;this.isInFocus?(this.isClicking=this.isOverList&&!this.isTabbed,this.isClicking?t&&t.isTrusted&&!this.isTabbed&&(this.isFalseFocus=!0,this.$nextTick(function(){e.inputElement.focus()})):(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.isFalseFocus=!1,this.isClicking||this.showSuggestions()},onInput:function(t){var e=t.target?t.target.value:t;this.text!==e&&(this.text=e,this.$emit("input",this.text),this.hovered&&this.hover(null),this.debounce?(clearTimeout(this.timeoutInstance),this.timeoutInstance=setTimeout(this.research,this.debounce)):this.research())},research:u(function(){var t=this;return n(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)})}})},function(e){throw t.clearSuggestions(),e})},function(){return t.canSend=!0,0===t.suggestions.length&&t.miscSlotsAreEmpty()?t.hideList():t.showList(),t.suggestions})}),getSuggestions:u(function(t){var e=this;if((t=t||"").length<e.minLength)return e.listShown?(e.hideList(),[]):e.suggestions;e.selected=null,e.listIsRequest&&(e.$emit("request-start",t),(e.suggestions.length>0||!e.miscSlotsAreEmpty())&&e.showList());var i=[];return n(function(){return o(function(){return l(function(){if(e.listIsRequest)return r(e.list(t),function(t){i=t||[]});i=e.list},function(){Array.isArray(i)||(i=[i]),e.isPlainSuggestion="object"!==s(i[0])||Array.isArray(i[0]),e.filterByQuery&&(i=i.filter(function(i){return e.filter(i,t)})),e.listIsRequest&&e.$emit("request-done",i)})},function(t){if(!e.listIsRequest)throw t;e.$emit("request-failed",t)})},function(){return e.maxSuggestions&&i.splice(e.maxSuggestions),i})}),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",h),h}); |
{ | ||
"name": "vue-simple-suggest", | ||
"description": "Feature-rich autocomplete component for Vue.js", | ||
"version": "1.9.1", | ||
"version": "1.9.2", | ||
"author": "KazanExpress", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
182160
2122