vue-simple-suggest
Advanced tools
Comparing version 1.10.4 to 1.11.0
@@ -65,3 +65,4 @@ 'use strict'; | ||
}function _invokeIgnored(body) { | ||
var result = body();if (result && result.then) { | ||
var result = body(); | ||
if (result && result.then) { | ||
return result.then(_empty); | ||
@@ -74,8 +75,7 @@ } | ||
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) { | ||
try { | ||
@@ -184,2 +184,6 @@ var result = body(); | ||
} | ||
}, | ||
preventHide: { | ||
type: Boolean, | ||
default: false | ||
} | ||
@@ -532,4 +536,5 @@ }, | ||
this.select(suggestion); | ||
this.hideList(); | ||
if (!this.preventHide) this.hideList(); | ||
/// Ensure, that all needed flags are off before finishing the click. | ||
@@ -597,5 +602,3 @@ this.isClicking = false; | ||
return; | ||
} | ||
if (this.debounce) { | ||
}if (this.debounce) { | ||
clearTimeout(this.timeoutInstance); | ||
@@ -661,2 +664,3 @@ this.timeoutInstance = setTimeout(this.research, this.debounce); | ||
var nextIsPlainSuggestion = false; | ||
var result = []; | ||
@@ -680,3 +684,3 @@ return _finally(function () { | ||
_this12.isPlainSuggestion = _typeof(result[0]) !== 'object' || Array.isArray(result[0]); | ||
nextIsPlainSuggestion = _typeof(result[0]) !== 'object' && typeof result[0] !== 'undefined' || Array.isArray(result[0]); | ||
@@ -705,2 +709,3 @@ if (_this12.filterByQuery) { | ||
_this12.isPlainSuggestion = nextIsPlainSuggestion; | ||
return result; | ||
@@ -707,0 +712,0 @@ }); |
@@ -59,3 +59,4 @@ const defaultControls = { | ||
}function _invokeIgnored(body) { | ||
var result = body();if (result && result.then) { | ||
var result = body(); | ||
if (result && result.then) { | ||
return result.then(_empty); | ||
@@ -68,8 +69,7 @@ } | ||
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) { | ||
try { | ||
@@ -170,2 +170,6 @@ var result = body(); | ||
validator: value => !!~Object.keys(modes).indexOf(value.toLowerCase()) | ||
}, | ||
preventHide: { | ||
type: Boolean, | ||
default: false | ||
} | ||
@@ -498,4 +502,5 @@ }, | ||
this.select(suggestion); | ||
this.hideList(); | ||
if (!this.preventHide) this.hideList(); | ||
/// Ensure, that all needed flags are off before finishing the click. | ||
@@ -566,5 +571,3 @@ this.isClicking = false; | ||
return; | ||
} | ||
if (this.debounce) { | ||
}if (this.debounce) { | ||
clearTimeout(this.timeoutInstance); | ||
@@ -625,2 +628,3 @@ this.timeoutInstance = setTimeout(this.research, this.debounce); | ||
let nextIsPlainSuggestion = false; | ||
let result = []; | ||
@@ -644,3 +648,3 @@ return _finally(function () { | ||
_this4.isPlainSuggestion = typeof result[0] !== 'object' || Array.isArray(result[0]); | ||
nextIsPlainSuggestion = typeof result[0] !== 'object' && typeof result[0] !== 'undefined' || Array.isArray(result[0]); | ||
@@ -667,2 +671,3 @@ if (_this4.filterByQuery) { | ||
_this4.isPlainSuggestion = nextIsPlainSuggestion; | ||
return result; | ||
@@ -669,0 +674,0 @@ }); |
@@ -122,2 +122,6 @@ const defaultControls = { | ||
validator: value => !!~Object.keys(modes).indexOf(value.toLowerCase()) | ||
}, | ||
preventHide: { | ||
type: Boolean, | ||
default: false | ||
} | ||
@@ -440,4 +444,5 @@ }, | ||
this.select(suggestion); | ||
this.hideList(); | ||
if (!this.preventHide) this.hideList(); | ||
/// Ensure, that all needed flags are off before finishing the click. | ||
@@ -558,2 +563,3 @@ this.isClicking = false; | ||
let nextIsPlainSuggestion = false; | ||
let result = []; | ||
@@ -572,3 +578,3 @@ try { | ||
this.isPlainSuggestion = typeof result[0] !== 'object' || Array.isArray(result[0]); | ||
nextIsPlainSuggestion = typeof result[0] !== 'object' && typeof result[0] !== 'undefined' || Array.isArray(result[0]); | ||
@@ -593,2 +599,3 @@ if (this.filterByQuery) { | ||
this.isPlainSuggestion = nextIsPlainSuggestion; | ||
return result; | ||
@@ -595,0 +602,0 @@ } |
@@ -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(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}(); | ||
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 s(t,e.keyCode)}function s(t,e){if(t.length<=0)return!1;function i(t){return t.some(function(t){return t===e})}return Array.isArray(t[0])?t.some(function(t){return i(t)}):i(t)}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=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,i){return i?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function l(){}function h(t,e){var i=t();return i&&i.then?i.then(e):e(i)}function c(t,e){try{var i=t()}catch(t){return e(t)}return i&&i.then?i.then(void 0,e):i}function a(t,e){try{var i=t()}catch(t){return e()}return i&&i.then?i.then(e,e):e()}var i={render:function(){var i=this,t=i.$createElement,s=i._self._c||t;return s("div",{staticClass:"vue-simple-suggest",class:[i.styles.vueSimpleSuggest,{designed:!i.destyled,focus:i.isInFocus}],on:{keydown:function(t){if(!t.type.indexOf("key")&&i._k(t.keyCode,"tab",9,t.key,"Tab"))return null;i.isTabbed=!0}}},[s("div",{ref:"inputSlot",staticClass:"input-wrapper",class:i.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":i.listId,"aria-expanded":i.listShown&&!i.removeList?"true":"false"}},[i._t("default",[s("input",i._b({staticClass:"default-input",class:i.styles.defaultInput,domProps:{value:i.text||""}},"input",i.$attrs,!1))])],2),i._v(" "),s("transition",{attrs:{name:"vue-simple-suggest"}},[i.listShown&&!i.removeList?s("ul",{staticClass:"suggestions",class:i.styles.suggestions,attrs:{id:i.listId,role:"listbox","aria-labelledby":i.listId}},[this.$scopedSlots["misc-item-above"]?s("li",[i._t("misc-item-above",null,{suggestions:i.suggestions,query:i.text})],2):i._e(),i._v(" "),i._l(i.suggestions,function(e,t){return s("li",{key:i.getId(e,t),staticClass:"suggest-item",class:[i.styles.suggestItem,{selected:i.isSelected(e),hover:i.isHovered(e)}],attrs:{role:"option","aria-selected":i.isHovered(e)||i.isSelected(e)?"true":"false",id:i.getId(e,t)},on:{mouseenter:function(t){return i.hover(e,t.target)},mouseleave:function(){return i.hover(void 0)},click:function(t){return i.suggestionClick(e,t)}}},[i._t("suggestion-item",[s("span",[i._v(i._s(i.displayProperty(e)))])],{autocomplete:function(){return i.autocompleteText(e)},suggestion:e,query:i.text})],2)}),i._v(" "),this.$scopedSlots["misc-item-below"]?s("li",[i._t("misc-item-below",null,{suggestions:i.suggestions,query:i.text})],2):i._e()],2):i._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())}},preventHide:{type:Boolean,default:!1}},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"],i={click:this.showSuggestions,keydown:this.onKeyDown,keyup:this.onListKeyUp},s=u({blur:this.onBlur,focus:this.onFocus,input:this.onInput},i);for(var n in s)this.input[e](n,s[n]);var o=t?"addEventListener":"removeEventListener";for(var r in i)this.inputElement[o](r,i[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 i=t.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,i)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":n(t))?(i=t,e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},i)):t;var i},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 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},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),i=2*e-1,s=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+i]:this.suggestions[s]:this.selected||this.suggestions[s],this.hover(o)}},onKeyDown:function(t){var e=this.controlScheme.select,i=this.controlScheme.hideList;"Enter"===t.key&&this.listShown&&s([e,i],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,i=this.controlScheme.hideList;this.listShown&&r([e,i],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.preventHide||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 i=this;return a(function(){return c(function(){return function(t){var e=t();if(e&&e.then)return e.then(l)}(function(){if(i.canSend){i.canSend=!1;var e=i.text;return o(i.getSuggestions(i.text),function(t){e===i.text&&i.$set(i,"suggestions",t)})}})},function(t){throw i.clearSuggestions(),t})},function(){return i.canSend=!0,0===i.suggestions.length&&i.miscSlotsAreEmpty()?i.hideList():i.isInFocus&&i.showList(),i.suggestions})}catch(t){return Promise.reject(t)}},getSuggestions:function(e){try{var i=this;if((e=e||"").length<i.minLength)return[];i.selected=null,i.listIsRequest&&i.$emit("request-start",e);var t=!1,s=[];return a(function(){return c(function(){return h(function(){if(i.listIsRequest)return o(i.list(e),function(t){s=t||[]});s=i.list},function(){Array.isArray(s)||(s=[s]),t="object"!==n(s[0])&&void 0!==s[0]||Array.isArray(s[0]),i.filterByQuery&&(s=s.filter(function(t){return i.filter(t,e)})),i.listIsRequest&&i.$emit("request-done",s)})},function(t){if(!i.listIsRequest)throw t;i.$emit("request-failed",t)})},function(){return i.maxSuggestions&&s.splice(i.maxSuggestions),i.isPlainSuggestion=t,s})}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",i),i}(); |
@@ -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(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}); | ||
!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 s(t,e.keyCode)}function s(t,e){if(t.length<=0)return!1;function i(t){return t.some(function(t){return t===e})}return Array.isArray(t[0])?t.some(function(t){return i(t)}):i(t)}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function o(t,e,i){return i?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function u(){}function l(t,e){var i=t();return i&&i.then?i.then(e):e(i)}function h(t,e){try{var i=t()}catch(t){return e(t)}return i&&i.then?i.then(void 0,e):i}function c(t,e){try{var i=t()}catch(t){return e()}return i&&i.then?i.then(e,e):e()}var i={render:function(){var i=this,t=i.$createElement,s=i._self._c||t;return s("div",{staticClass:"vue-simple-suggest",class:[i.styles.vueSimpleSuggest,{designed:!i.destyled,focus:i.isInFocus}],on:{keydown:function(t){if(!t.type.indexOf("key")&&i._k(t.keyCode,"tab",9,t.key,"Tab"))return null;i.isTabbed=!0}}},[s("div",{ref:"inputSlot",staticClass:"input-wrapper",class:i.styles.inputWrapper,attrs:{role:"combobox","aria-haspopup":"listbox","aria-owns":i.listId,"aria-expanded":i.listShown&&!i.removeList?"true":"false"}},[i._t("default",[s("input",i._b({staticClass:"default-input",class:i.styles.defaultInput,domProps:{value:i.text||""}},"input",i.$attrs,!1))])],2),i._v(" "),s("transition",{attrs:{name:"vue-simple-suggest"}},[i.listShown&&!i.removeList?s("ul",{staticClass:"suggestions",class:i.styles.suggestions,attrs:{id:i.listId,role:"listbox","aria-labelledby":i.listId}},[this.$scopedSlots["misc-item-above"]?s("li",[i._t("misc-item-above",null,{suggestions:i.suggestions,query:i.text})],2):i._e(),i._v(" "),i._l(i.suggestions,function(e,t){return s("li",{key:i.getId(e,t),staticClass:"suggest-item",class:[i.styles.suggestItem,{selected:i.isSelected(e),hover:i.isHovered(e)}],attrs:{role:"option","aria-selected":i.isHovered(e)||i.isSelected(e)?"true":"false",id:i.getId(e,t)},on:{mouseenter:function(t){return i.hover(e,t.target)},mouseleave:function(){return i.hover(void 0)},click:function(t){return i.suggestionClick(e,t)}}},[i._t("suggestion-item",[s("span",[i._v(i._s(i.displayProperty(e)))])],{autocomplete:function(){return i.autocompleteText(e)},suggestion:e,query:i.text})],2)}),i._v(" "),this.$scopedSlots["misc-item-below"]?s("li",[i._t("misc-item-below",null,{suggestions:i.suggestions,query:i.text})],2):i._e()],2):i._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())}},preventHide:{type:Boolean,default:!1}},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"],i={click:this.showSuggestions,keydown:this.onKeyDown,keyup:this.onListKeyUp},s=Object.assign({blur:this.onBlur,focus:this.onFocus,input:this.onInput},i);for(var n in s)this.input[e](n,s[n]);var o=t?"addEventListener":"removeEventListener";for(var r in i)this.inputElement[o](r,i[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 i=t.find(function(t){return!!t});return this.isScopedSlotEmpty.call(this,i)},getPropertyByAttribute:function(t,e){return this.isPlainSuggestion?t:void 0!==(void 0===t?"undefined":n(t))?(i=t,e.split(".").reduce(function(t,e){return t===Object(t)?t[e]:t},i)):t;var i},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 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},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),i=2*e-1,s=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+i]:this.suggestions[s]:this.selected||this.suggestions[s],this.hover(o)}},onKeyDown:function(t){var e=this.controlScheme.select,i=this.controlScheme.hideList;"Enter"===t.key&&this.listShown&&s([e,i],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,i=this.controlScheme.hideList;this.listShown&&r([e,i],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.preventHide||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 i=this;return c(function(){return h(function(){return function(t){var e=t();if(e&&e.then)return e.then(u)}(function(){if(i.canSend){i.canSend=!1;var e=i.text;return o(i.getSuggestions(i.text),function(t){e===i.text&&i.$set(i,"suggestions",t)})}})},function(t){throw i.clearSuggestions(),t})},function(){return i.canSend=!0,0===i.suggestions.length&&i.miscSlotsAreEmpty()?i.hideList():i.isInFocus&&i.showList(),i.suggestions})}catch(t){return Promise.reject(t)}},getSuggestions:function(e){try{var i=this;if((e=e||"").length<i.minLength)return[];i.selected=null,i.listIsRequest&&i.$emit("request-start",e);var t=!1,s=[];return c(function(){return h(function(){return l(function(){if(i.listIsRequest)return o(i.list(e),function(t){s=t||[]});s=i.list},function(){Array.isArray(s)||(s=[s]),t="object"!==n(s[0])&&void 0!==s[0]||Array.isArray(s[0]),i.filterByQuery&&(s=s.filter(function(t){return i.filter(t,e)})),i.listIsRequest&&i.$emit("request-done",s)})},function(t){if(!i.listIsRequest)throw t;i.$emit("request-failed",t)})},function(){return i.maxSuggestions&&s.splice(i.maxSuggestions),i.isPlainSuggestion=t,s})}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",i),i}); |
{ | ||
"name": "vue-simple-suggest", | ||
"description": "Feature-rich autocomplete component for Vue.js", | ||
"version": "1.10.4", | ||
"version": "1.11.0", | ||
"author": "KazanExpress", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -55,3 +55,3 @@ # vue-simple-suggest | ||
- [Custom suggestion item](#custom-suggestion-item) | ||
- [Custom miscellanious item slots](#custom-miscellanious-item-slots) | ||
- [Custom miscellaneous item slots](#custom-miscellaneous-item-slots) | ||
- [Contributors](#contributors) | ||
@@ -516,3 +516,4 @@ | ||
| `type`, `value`, `pattern`, etc... | | | All of the HTML5 input attributes with their respected default values. | | ||
| `nullable-select` <sup>[v1.9.0](https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.4.0)</sup> | Boolean | `false` | Whether the `select` should accept `null` or not. | | ||
| `nullable-select` <sup>[v1.9.0](https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.9.0)</sup> | Boolean | `false` | Whether the `select` should accept `null` or not. | | ||
|`preventHide` <sup>[v1.11.0](https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.11.0)</sup>|Boolean|`false`|Whether to keep the input open or not, allowing the user to select multiple inputs| | ||
@@ -813,3 +814,3 @@ ##### mode | ||
##### Custom miscellanious item slots | ||
##### Custom miscellaneous item slots | ||
> `misc-item-above` and `misc-item-below` slots (optional) | ||
@@ -816,0 +817,0 @@ |
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
191282
2146
917