@tarekraafat/autocomplete.js
Advanced tools
Comparing version 9.0.2 to 9.0.3
@@ -189,5 +189,5 @@ (function (global, factory) { | ||
var closeList = function closeList(config) { | ||
var closeList = function closeList(config, target) { | ||
var list = document.getElementById(config.resultsList.idName); | ||
if (list) { | ||
if (list && target !== config.inputField) { | ||
list.remove(); | ||
@@ -236,2 +236,5 @@ config.inputField.removeAttribute("aria-activedescendant"); | ||
} | ||
document.addEventListener("click", function (event) { | ||
return closeList(config, event.target); | ||
}); | ||
}; | ||
@@ -278,6 +281,2 @@ | ||
switch (event.keyCode) { | ||
case 27: | ||
config.inputField.value = ""; | ||
closeList(config); | ||
break; | ||
case 40: | ||
@@ -289,9 +288,14 @@ update(event, list, true); | ||
break; | ||
case 27: | ||
config.inputField.value = ""; | ||
closeList(config); | ||
break; | ||
case 13: | ||
event.preventDefault(); | ||
if (currentFocus > -1) { | ||
list[currentFocus].click(); | ||
closeList(config); | ||
} | ||
list[currentFocus].click(); | ||
closeList(config); | ||
break; | ||
case 9: | ||
closeList(config); | ||
break; | ||
} | ||
@@ -524,3 +528,2 @@ } | ||
value: function start(input, query) { | ||
var _this = this; | ||
var results = this.data.results ? this.data.results(listMatchingResults(this, query)) : listMatchingResults(this, query); | ||
@@ -538,5 +541,2 @@ var dataFeedback = { | ||
eventEmitter(this.inputField, dataFeedback, "open"); | ||
document.addEventListener("click", function () { | ||
return closeList(_this); | ||
}); | ||
} | ||
@@ -546,14 +546,14 @@ }, { | ||
value: function dataStore() { | ||
var _this2 = this; | ||
var _this = this; | ||
return new Promise(function ($return, $error) { | ||
if (_this2.data.cache && _this2.data.store) return $return(null); | ||
if (_this.data.cache && _this.data.store) return $return(null); | ||
return new Promise(function ($return, $error) { | ||
if (typeof _this2.data.src === "function") { | ||
return _this2.data.src().then($return, $error); | ||
if (typeof _this.data.src === "function") { | ||
return _this.data.src().then($return, $error); | ||
} | ||
return $return(_this2.data.src); | ||
return $return(_this.data.src); | ||
}).then(function ($await_5) { | ||
try { | ||
_this2.data.store = $await_5; | ||
eventEmitter(_this2.inputField, _this2.data.store, "fetch"); | ||
_this.data.store = $await_5; | ||
eventEmitter(_this.inputField, _this.data.store, "fetch"); | ||
return $return(); | ||
@@ -569,13 +569,13 @@ } catch ($boundEx) { | ||
value: function compose(event) { | ||
var _this3 = this; | ||
var _this2 = this; | ||
return new Promise(function ($return, $error) { | ||
var input, query, triggerCondition; | ||
input = getInputValue(_this3.inputField); | ||
query = prepareQueryValue(input, _this3); | ||
triggerCondition = checkTriggerCondition(_this3, event, query); | ||
input = getInputValue(_this2.inputField); | ||
query = prepareQueryValue(input, _this2); | ||
triggerCondition = checkTriggerCondition(_this2, event, query); | ||
if (triggerCondition) { | ||
return _this3.dataStore().then(function ($await_6) { | ||
return _this2.dataStore().then(function ($await_6) { | ||
try { | ||
_this3.start(input, query); | ||
return $If_3.call(_this3); | ||
_this2.start(input, query); | ||
return $If_3.call(_this2); | ||
} catch ($boundEx) { | ||
@@ -586,4 +586,4 @@ return $error($boundEx); | ||
} else { | ||
closeList(_this3); | ||
return $If_3.call(_this3); | ||
closeList(_this2); | ||
return $If_3.call(_this2); | ||
} | ||
@@ -598,11 +598,11 @@ function $If_3() { | ||
value: function init() { | ||
var _this4 = this; | ||
var _this3 = this; | ||
inputComponent(this); | ||
if (this.placeHolder) this.inputField.setAttribute("placeholder", this.placeHolder); | ||
this.hook = debouncer(function (event) { | ||
_this4.compose(event); | ||
_this3.compose(event); | ||
}, this.debounce); | ||
this.trigger.event.forEach(function (eventType) { | ||
_this4.inputField.removeEventListener(eventType, _this4.hook); | ||
_this4.inputField.addEventListener(eventType, _this4.hook); | ||
_this3.inputField.removeEventListener(eventType, _this3.hook); | ||
_this3.inputField.addEventListener(eventType, _this3.hook); | ||
}); | ||
@@ -614,3 +614,3 @@ eventEmitter(this.inputField, null, "init"); | ||
value: function preInit() { | ||
var _this5 = this; | ||
var _this4 = this; | ||
var config = { | ||
@@ -626,5 +626,5 @@ childList: true, | ||
var mutation = _step.value; | ||
if (_this5.inputField) { | ||
if (_this4.inputField) { | ||
observer.disconnect(); | ||
_this5.init(); | ||
_this4.init(); | ||
} | ||
@@ -631,0 +631,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var e,t;e=this,t=function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function i(e){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?n(Object(r),!0).forEach((function(n){t(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function s(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw o}}}}var o=function(e,t,n){e.dispatchEvent(new CustomEvent(n,{bubbles:!0,detail:t,cancelable:!0}))},a=function(e){var t=document.getElementById(e.resultsList.idName);t&&(t.remove(),e.inputField.removeAttribute("aria-activedescendant"),e.inputField.setAttribute("aria-expanded",!1),o(e.inputField,null,"close"))},l=function(e,t,n){var r=document.getElementById(e.resultsList.idName);if(r?r.innerHTML="":r=function(e){var t=document.createElement(e.resultsList.element);return t.setAttribute("id",e.resultsList.idName),t.setAttribute("class",e.resultsList.className),t.setAttribute("role","listbox"),e.resultsList.container&&e.resultsList.container(t),("string"==typeof e.resultsList.destination?document.querySelector(e.resultsList.destination):e.resultsList.destination()).insertAdjacentElement(e.resultsList.position,t),t}(e),e.inputField.setAttribute("aria-expanded",!0),n.length)for(var s=function(s){var o=t.results[s],a=function(e,t,n){var i=document.createElement(n.resultItem.element);return i.setAttribute("id","".concat(n.resultItem.idName,"_").concat(t)),i.setAttribute("class",n.resultItem.className),i.setAttribute("role","option"),i.innerHTML=e.match,n.resultItem.content&&n.resultItem.content(e,i),i}(o,s,e);a.addEventListener("click",(function(r){var a={event:r,matches:n,input:t.input,query:t.query,results:t.results,selection:i(i({},o),{},{index:s})};e.onSelection&&e.onSelection(a)})),r.appendChild(a)},o=0;o<t.results.length;o++)s(o);else e.resultsList.noResults?e.resultsList.noResults(r,t.query):r.remove()},u="keydown",c=function(e,t){var n=-1,r=function(r,a,l){r.preventDefault(),l?n++:n--,s(a),e.inputField.setAttribute("aria-activedescendant",a[n].id),o(r.srcElement,i(i({event:r},t),{},{selection:t.results[n]}),"navigate")},s=function(t){if(!t)return!1;!function(t){for(var n=0;n<t.length;n++)t[n].removeAttribute("aria-selected"),e.resultItem.selected.className&&t[n].classList.remove(e.resultItem.selected.className)}(t),n>=t.length&&(n=0),n<0&&(n=t.length-1),t[n].setAttribute("aria-selected","true"),e.resultItem.selected.className&&t[n].classList.add(e.resultItem.selected.className)},l=e.resultsList.navigation||function(t){var i=document.getElementById(e.resultsList.idName);if(i)switch(i=i.getElementsByTagName(e.resultItem.element),t.keyCode){case 27:e.inputField.value="",a(e);break;case 40:r(t,i,!0);break;case 38:r(t,i,!1);break;case 13:t.preventDefault(),n>-1&&(i[n].click(),a(e))}else e.inputField.removeEventListener(u,l)};e.inputField.autoCompleteNavigate&&e.inputField.removeEventListener(u,e.inputField.autoCompleteNavigate),e.inputField.autoCompleteNavigate=l,e.inputField.addEventListener(u,l)},d=function(e,t){for(var n=[],i=function(i){var r=e.data.store[i],o=function(s){var o=(s?r[s]:r).toString();if(o){var a="function"==typeof e.searchEngine?e.searchEngine(t,o):function(e,t,n){var i=n.diacritics?t.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):t.toLowerCase();if("loose"===n.searchEngine){e=e.replace(/ /g,"");for(var r=[],s=0,o=0;o<i.length;o++){var a=t[o];s<e.length&&i[o]===e[s]&&(a=n.resultItem.highlight.render?'<span class="'.concat(n.resultItem.highlight.className,'">').concat(a,"</span>"):a,s++),r.push(a)}if(s===e.length)return r.join("")}else if(i.includes(e)){var l=new RegExp(e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i");return e=l.exec(t),n.resultItem.highlight.render?t.replace(e,'<span class="'.concat(n.resultItem.highlight.className,'">').concat(e,"</span>")):t}}(t,o,e);a&&s?n.push({key:s,index:i,match:a,value:r}):a&&!s&&n.push({index:i,match:a,value:r})}};if(e.data.key){var a,l=s(e.data.key);try{for(l.s();!(a=l.n()).done;)o(a.value)}catch(e){l.e(e)}finally{l.f()}}else o()},r=0;r<e.data.store.length;r++)i(r);return n};return function(){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=e.selector,i=void 0===n?"#autoComplete":n,r=e.placeHolder,s=e.observer,o=void 0!==s&&s,a=e.data,l=a.src,u=a.key,c=a.cache,d=void 0!==c&&c,h=a.store,f=a.results,m=e.query,v=e.trigger,p=(v=void 0===v?{}:v).event,g=void 0===p?["input"]:p,b=v.condition,y=void 0!==b&&b,L=e.threshold,N=void 0===L?1:L,F=e.debounce,E=void 0===F?0:F,k=e.diacritics,w=void 0!==k&&k,I=e.searchEngine,A=void 0===I?"strict":I,O=e.feedback,C=e.resultsList,j=(C=void 0===C?{}:C).render,x=void 0===j||j,S=C.container,P=void 0!==S&&S,T=C.destination,q=C.position,H=void 0===q?"afterend":q,D=C.element,R=void 0===D?"ul":D,M=C.idName,_=void 0===M?"autoComplete_list":M,z=C.className,B=void 0===z?"autoComplete_list":z,$=C.maxResults,U=void 0===$?5:$,G=C.navigation,J=void 0!==G&&G,K=C.noResults,Q=e.resultItem,V=(Q=void 0===Q?{}:Q).content,W=void 0!==V&&V,X=Q.element,Y=void 0===X?"li":X,Z=Q.idName,ee=Q.className,te=void 0===ee?"autoComplete_result":ee,ne=Q.highlight,ie=(ne=void 0===ne?{}:ne).render,re=void 0!==ie&&ie,se=ne.className,oe=void 0===se?"autoComplete_highlighted":se,ae=Q.selected,le=(ae=void 0===ae?{}:ae).className,ue=void 0===le?"autoComplete_selected":le,ce=e.onSelection;this.selector=i,this.observer=o,this.placeHolder=r,this.data={src:l,key:u,cache:d,store:h,results:f},this.query=m,this.trigger={event:g,condition:y},this.threshold=N,this.debounce=E,this.diacritics=w,this.searchEngine=A,this.feedback=O,this.resultsList={render:x,container:P,destination:T||this.selector,position:H,element:R,idName:_,className:B,maxResults:U,navigation:J,noResults:K},this.resultItem={content:W,element:Y,idName:Z,className:te,highlight:{render:re,className:oe},selected:{className:ue}},this.onSelection=ce,this.inputField="string"==typeof this.selector?document.querySelector(this.selector):this.selector(),this.observer?this.preInit():this.init()}var n,i,r;return n=t,(i=[{key:"start",value:function(e,t){var n=this,i=this.data.results?this.data.results(d(this,t)):d(this,t),r={input:e,query:t,matches:i,results:i.slice(0,this.resultsList.maxResults)};if(o(this.inputField,r,"results"),!this.resultsList.render)return this.feedback(r);l(this,r,i),c(this,r),o(this.inputField,r,"open"),document.addEventListener("click",(function(){return a(n)}))}},{key:"dataStore",value:function(){var e=this;return new Promise((function(t,n){return e.data.cache&&e.data.store?t(null):new Promise((function(t,n){return"function"==typeof e.data.src?e.data.src().then(t,n):t(e.data.src)})).then((function(i){try{return e.data.store=i,o(e.inputField,e.data.store,"fetch"),t()}catch(e){return n(e)}}),n)}))}},{key:"compose",value:function(e){var t=this;return new Promise((function(n,i){var r,s,o,l,u;return o=t.inputField,r=o instanceof HTMLInputElement||o instanceof HTMLTextAreaElement?o.value.toLowerCase():o.innerHTML.toLowerCase(),l=r,s=(u=t).query&&u.query.manipulate?u.query.manipulate(l):u.diacritics?l.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):l,function(e,t,n){return e.trigger.condition?e.trigger.condition(t,n):n.length>=e.threshold&&n.replace(/ /g,"").length}(t,e,s)?t.dataStore().then((function(e){try{return t.start(r,s),c.call(t)}catch(e){return i(e)}}),i):(a(t),c.call(t));function c(){return n()}}))}},{key:"init",value:function(){var e,t,n,i,r=this;(e=this).inputField.setAttribute("role","combobox"),e.inputField.setAttribute("aria-haspopup",!0),e.inputField.setAttribute("aria-expanded",!1),e.inputField.setAttribute("aria-controls",e.resultsList.idName),e.inputField.setAttribute("aria-autocomplete","both"),this.placeHolder&&this.inputField.setAttribute("placeholder",this.placeHolder),this.hook=(t=function(e){r.compose(e)},n=this.debounce,function(){var e=this,r=arguments;clearTimeout(i),i=setTimeout((function(){return t.apply(e,r)}),n)}),this.trigger.event.forEach((function(e){r.inputField.removeEventListener(e,r.hook),r.inputField.addEventListener(e,r.hook)})),o(this.inputField,null,"init")}},{key:"preInit",value:function(){var e=this;new MutationObserver((function(t,n){var i,r=s(t);try{for(r.s();!(i=r.n()).done;)i.value,e.inputField&&(n.disconnect(),e.init())}catch(e){r.e(e)}finally{r.f()}})).observe(document,{childList:!0,subtree:!0})}},{key:"unInit",value:function(){this.inputField.removeEventListener("input",this.hook),o(this.inputField,null,"unInit")}}])&&e(n.prototype,i),r&&e(n,r),t}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).autoComplete=t(); | ||
var e,t;e=this,t=function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function i(e){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?n(Object(r),!0).forEach((function(n){t(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function s(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw o}}}}var o=function(e,t,n){e.dispatchEvent(new CustomEvent(n,{bubbles:!0,detail:t,cancelable:!0}))},a=function(e,t){var n=document.getElementById(e.resultsList.idName);n&&t!==e.inputField&&(n.remove(),e.inputField.removeAttribute("aria-activedescendant"),e.inputField.setAttribute("aria-expanded",!1),o(e.inputField,null,"close"))},l=function(e,t,n){var r=document.getElementById(e.resultsList.idName);if(r?r.innerHTML="":r=function(e){var t=document.createElement(e.resultsList.element);return t.setAttribute("id",e.resultsList.idName),t.setAttribute("class",e.resultsList.className),t.setAttribute("role","listbox"),e.resultsList.container&&e.resultsList.container(t),("string"==typeof e.resultsList.destination?document.querySelector(e.resultsList.destination):e.resultsList.destination()).insertAdjacentElement(e.resultsList.position,t),t}(e),e.inputField.setAttribute("aria-expanded",!0),n.length)for(var s=function(s){var o=t.results[s],a=function(e,t,n){var i=document.createElement(n.resultItem.element);return i.setAttribute("id","".concat(n.resultItem.idName,"_").concat(t)),i.setAttribute("class",n.resultItem.className),i.setAttribute("role","option"),i.innerHTML=e.match,n.resultItem.content&&n.resultItem.content(e,i),i}(o,s,e);a.addEventListener("click",(function(r){var a={event:r,matches:n,input:t.input,query:t.query,results:t.results,selection:i(i({},o),{},{index:s})};e.onSelection&&e.onSelection(a)})),r.appendChild(a)},o=0;o<t.results.length;o++)s(o);else e.resultsList.noResults?e.resultsList.noResults(r,t.query):r.remove();document.addEventListener("click",(function(t){return a(e,t.target)}))},u="keydown",c=function(e,t){var n=-1,r=function(r,a,l){r.preventDefault(),l?n++:n--,s(a),e.inputField.setAttribute("aria-activedescendant",a[n].id),o(r.srcElement,i(i({event:r},t),{},{selection:t.results[n]}),"navigate")},s=function(t){if(!t)return!1;!function(t){for(var n=0;n<t.length;n++)t[n].removeAttribute("aria-selected"),e.resultItem.selected.className&&t[n].classList.remove(e.resultItem.selected.className)}(t),n>=t.length&&(n=0),n<0&&(n=t.length-1),t[n].setAttribute("aria-selected","true"),e.resultItem.selected.className&&t[n].classList.add(e.resultItem.selected.className)},l=e.resultsList.navigation||function(t){var i=document.getElementById(e.resultsList.idName);if(i)switch(i=i.getElementsByTagName(e.resultItem.element),t.keyCode){case 40:r(t,i,!0);break;case 38:r(t,i,!1);break;case 27:e.inputField.value="",a(e);break;case 13:t.preventDefault(),i[n].click(),a(e);break;case 9:a(e)}else e.inputField.removeEventListener(u,l)};e.inputField.autoCompleteNavigate&&e.inputField.removeEventListener(u,e.inputField.autoCompleteNavigate),e.inputField.autoCompleteNavigate=l,e.inputField.addEventListener(u,l)},d=function(e,t){for(var n=[],i=function(i){var r=e.data.store[i],o=function(s){var o=(s?r[s]:r).toString();if(o){var a="function"==typeof e.searchEngine?e.searchEngine(t,o):function(e,t,n){var i=n.diacritics?t.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):t.toLowerCase();if("loose"===n.searchEngine){e=e.replace(/ /g,"");for(var r=[],s=0,o=0;o<i.length;o++){var a=t[o];s<e.length&&i[o]===e[s]&&(a=n.resultItem.highlight.render?'<span class="'.concat(n.resultItem.highlight.className,'">').concat(a,"</span>"):a,s++),r.push(a)}if(s===e.length)return r.join("")}else if(i.includes(e)){var l=new RegExp(e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i");return e=l.exec(t),n.resultItem.highlight.render?t.replace(e,'<span class="'.concat(n.resultItem.highlight.className,'">').concat(e,"</span>")):t}}(t,o,e);a&&s?n.push({key:s,index:i,match:a,value:r}):a&&!s&&n.push({index:i,match:a,value:r})}};if(e.data.key){var a,l=s(e.data.key);try{for(l.s();!(a=l.n()).done;)o(a.value)}catch(e){l.e(e)}finally{l.f()}}else o()},r=0;r<e.data.store.length;r++)i(r);return n};return function(){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=e.selector,i=void 0===n?"#autoComplete":n,r=e.placeHolder,s=e.observer,o=void 0!==s&&s,a=e.data,l=a.src,u=a.key,c=a.cache,d=void 0!==c&&c,h=a.store,f=a.results,m=e.query,p=e.trigger,v=(p=void 0===p?{}:p).event,g=void 0===v?["input"]:v,b=p.condition,y=void 0!==b&&b,L=e.threshold,F=void 0===L?1:L,N=e.debounce,E=void 0===N?0:N,k=e.diacritics,w=void 0!==k&&k,I=e.searchEngine,A=void 0===I?"strict":I,O=e.feedback,C=e.resultsList,j=(C=void 0===C?{}:C).render,x=void 0===j||j,S=C.container,P=void 0!==S&&S,T=C.destination,q=C.position,H=void 0===q?"afterend":q,D=C.element,R=void 0===D?"ul":D,M=C.idName,_=void 0===M?"autoComplete_list":M,z=C.className,B=void 0===z?"autoComplete_list":z,$=C.maxResults,U=void 0===$?5:$,G=C.navigation,J=void 0!==G&&G,K=C.noResults,Q=e.resultItem,V=(Q=void 0===Q?{}:Q).content,W=void 0!==V&&V,X=Q.element,Y=void 0===X?"li":X,Z=Q.idName,ee=Q.className,te=void 0===ee?"autoComplete_result":ee,ne=Q.highlight,ie=(ne=void 0===ne?{}:ne).render,re=void 0!==ie&&ie,se=ne.className,oe=void 0===se?"autoComplete_highlighted":se,ae=Q.selected,le=(ae=void 0===ae?{}:ae).className,ue=void 0===le?"autoComplete_selected":le,ce=e.onSelection;this.selector=i,this.observer=o,this.placeHolder=r,this.data={src:l,key:u,cache:d,store:h,results:f},this.query=m,this.trigger={event:g,condition:y},this.threshold=F,this.debounce=E,this.diacritics=w,this.searchEngine=A,this.feedback=O,this.resultsList={render:x,container:P,destination:T||this.selector,position:H,element:R,idName:_,className:B,maxResults:U,navigation:J,noResults:K},this.resultItem={content:W,element:Y,idName:Z,className:te,highlight:{render:re,className:oe},selected:{className:ue}},this.onSelection=ce,this.inputField="string"==typeof this.selector?document.querySelector(this.selector):this.selector(),this.observer?this.preInit():this.init()}var n,i,r;return n=t,(i=[{key:"start",value:function(e,t){var n=this.data.results?this.data.results(d(this,t)):d(this,t),i={input:e,query:t,matches:n,results:n.slice(0,this.resultsList.maxResults)};if(o(this.inputField,i,"results"),!this.resultsList.render)return this.feedback(i);l(this,i,n),c(this,i),o(this.inputField,i,"open")}},{key:"dataStore",value:function(){var e=this;return new Promise((function(t,n){return e.data.cache&&e.data.store?t(null):new Promise((function(t,n){return"function"==typeof e.data.src?e.data.src().then(t,n):t(e.data.src)})).then((function(i){try{return e.data.store=i,o(e.inputField,e.data.store,"fetch"),t()}catch(e){return n(e)}}),n)}))}},{key:"compose",value:function(e){var t=this;return new Promise((function(n,i){var r,s,o,l,u;return o=t.inputField,r=o instanceof HTMLInputElement||o instanceof HTMLTextAreaElement?o.value.toLowerCase():o.innerHTML.toLowerCase(),l=r,s=(u=t).query&&u.query.manipulate?u.query.manipulate(l):u.diacritics?l.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):l,function(e,t,n){return e.trigger.condition?e.trigger.condition(t,n):n.length>=e.threshold&&n.replace(/ /g,"").length}(t,e,s)?t.dataStore().then((function(e){try{return t.start(r,s),c.call(t)}catch(e){return i(e)}}),i):(a(t),c.call(t));function c(){return n()}}))}},{key:"init",value:function(){var e,t,n,i,r=this;(e=this).inputField.setAttribute("role","combobox"),e.inputField.setAttribute("aria-haspopup",!0),e.inputField.setAttribute("aria-expanded",!1),e.inputField.setAttribute("aria-controls",e.resultsList.idName),e.inputField.setAttribute("aria-autocomplete","both"),this.placeHolder&&this.inputField.setAttribute("placeholder",this.placeHolder),this.hook=(t=function(e){r.compose(e)},n=this.debounce,function(){var e=this,r=arguments;clearTimeout(i),i=setTimeout((function(){return t.apply(e,r)}),n)}),this.trigger.event.forEach((function(e){r.inputField.removeEventListener(e,r.hook),r.inputField.addEventListener(e,r.hook)})),o(this.inputField,null,"init")}},{key:"preInit",value:function(){var e=this;new MutationObserver((function(t,n){var i,r=s(t);try{for(r.s();!(i=r.n()).done;)i.value,e.inputField&&(n.disconnect(),e.init())}catch(e){r.e(e)}finally{r.f()}})).observe(document,{childList:!0,subtree:!0})}},{key:"unInit",value:function(){this.inputField.removeEventListener("input",this.hook),o(this.inputField,null,"unInit")}}])&&e(n.prototype,i),r&&e(n,r),t}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).autoComplete=t(); |
{ | ||
"name": "@tarekraafat/autocomplete.js", | ||
"version": "9.0.2", | ||
"version": "9.0.3", | ||
"description": "Simple autocomplete pure vanilla Javascript library.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
61242