autocompleter
Advanced tools
Comparing version 9.0.1 to 9.1.0
@@ -422,2 +422,4 @@ (function (global, factory) { | ||
container.addEventListener('focus', function () { return input.focus(); }); | ||
// If the custom autocomplete container is already appended to the DOM during widget initialization, detach it. | ||
detach(); | ||
/** | ||
@@ -424,0 +426,0 @@ * This function will remove DOM elements and clear event handlers |
@@ -9,3 +9,3 @@ !function(e,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()}(this,(function(){"use strict"; | ||
* MIT License | ||
*/return function(e){var t=document,n=e.container||t.createElement("div"),i=e.preventSubmit||0;n.id=n.id||"autocomplete-"+h();var r,o,a=n.style,s=e.debounceWaitMs||0,u=e.disableAutoSelect||!1,c=n.parentElement,d=[],l="",f=2,p=e.showOnFocus,v=0,m=!1,b=!1;if(void 0!==e.minLength&&(f=e.minLength),!e.input)throw new Error("input undefined");var g=e.input;function h(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}function E(){o&&window.clearTimeout(o)}function A(){return!!n.parentNode}function w(){var e;v++,d=[],l="",r=void 0,g.setAttribute("aria-activedescendant",""),g.setAttribute("aria-expanded","false"),(e=n.parentNode)&&e.removeChild(n)}function y(){n.innerHTML="",g.setAttribute("aria-activedescendant","");var i=function(e,n,i){var r=t.createElement("div");return r.textContent=e.label||"",r};e.render&&(i=e.render);var o=function(e,n){var i=t.createElement("div");return i.textContent=e,i};e.renderGroup&&(o=e.renderGroup);var s=t.createDocumentFragment(),u=h();if(d.forEach((function(t,a){if(t.group&&t.group!==u){u=t.group;var c=o(t.group,l);c&&(c.className+=" group",s.appendChild(c))}var d=i(t,l,a);d&&(d.id=n.id+"_"+a,d.setAttribute("role","option"),d.addEventListener("click",(function(n){b=!0;try{e.onSelect(t,g)}finally{b=!1}w(),n.preventDefault(),n.stopPropagation()})),t===r&&(d.className+=" selected",d.setAttribute("aria-selected","true"),g.setAttribute("aria-activedescendant",d.id)),s.appendChild(d))})),n.appendChild(s),d.length<1){if(!e.emptyMsg)return void w();var f=t.createElement("div");f.id=n.id+"_"+h(),f.className="empty",f.textContent=e.emptyMsg,n.appendChild(f),g.setAttribute("aria-activedescendant",f.id)}n.parentNode||(c||t.body).appendChild(n),function(){if(A()){g.setAttribute("aria-expanded","true"),a.height="auto",a.width=g.offsetWidth+"px";var i,r=0;o(),o(),e.customize&&i&&e.customize(g,i,n,r)}function o(){var e=t.documentElement,n=e.clientTop||t.body.clientTop||0,o=e.clientLeft||t.body.clientLeft||0,s=window.pageYOffset||e.scrollTop,u=window.pageXOffset||e.scrollLeft,c=(i=g.getBoundingClientRect()).top+g.offsetHeight+s-n,d=i.left+u-o;a.top=c+"px",a.left=d+"px",(r=window.innerHeight-(i.top+g.offsetHeight))<0&&(r=0),a.top=c+"px",a.bottom="",a.left=d+"px",a.maxHeight=r+"px"}}(),C()}function L(){A()&&y()}function x(){L()}function T(e){e.target!==n?L():e.preventDefault()}function k(){b||O(0)}function C(){var e=n.getElementsByClassName("selected");if(e.length>0){var t=e[0],i=t.previousElementSibling;if(i&&-1!==i.className.indexOf("group")&&!i.previousElementSibling&&(t=i),t.offsetTop<n.scrollTop)n.scrollTop=t.offsetTop;else{var r=t.offsetTop+t.offsetHeight,o=n.scrollTop+n.offsetHeight;r>o&&(n.scrollTop+=r-o)}}}function D(e){d.length>0&&(!function(e){var i=t.getElementById(n.id+"_"+e);i&&(i.classList.remove("selected"),i.removeAttribute("aria-selected"),g.removeAttribute("aria-activedescendant"))}(e),function(e){var i=t.getElementById(n.id+"_"+e);i&&(i.classList.add("selected"),i.setAttribute("aria-selected","true"),g.setAttribute("aria-activedescendant",i.id))}(d.indexOf(r)),C())}function N(e,t){var n,i=A();if("Escape"===t)w();else{if(!i||d.length<1)return;"ArrowUp"===t?(n=d.indexOf(r),r=-1===n?void 0:d[(n+d.length-1)%d.length],D(n)):function(){var e=d.indexOf(r);r=d.length<1?void 0:-1===e?d[0]:d[(e+1)%d.length],D(e)}()}e.preventDefault(),i&&e.stopPropagation()}function S(t){var n=t.key;switch(n){case"ArrowUp":case"ArrowDown":case"Escape":N(t,n);break;case"Enter":!function(t){if(r){2===i&&t.preventDefault(),b=!0;try{e.onSelect(r,g)}finally{b=!1}w()}1===i&&t.preventDefault()}(t)}}function H(){p&&O(1)}function O(e){g.value.length>=f||1===e?(E(),o=window.setTimeout((function(){return M(g.value,e,g.selectionStart||0)}),0===e||2===e?s:0)):w()}function M(t,n,i){if(!m){var o=++v;e.fetch(t,(function(e){v===o&&e&&(l=t,r=(d=e).length<1||u?void 0:d[0],y())}),n,i)}}function z(t){e.keyup?e.keyup({event:t,fetch:function(){return O(0)}}):A()||"ArrowDown"!==t.key||O(0)}function B(t){e.click&&e.click({event:t,fetch:function(){return O(2)}})}function _(){setTimeout((function(){t.activeElement!==g&&w()}),200)}return n.className="autocomplete "+(e.className||""),n.setAttribute("role","listbox"),g.setAttribute("role","combobox"),g.setAttribute("aria-expanded","false"),g.setAttribute("aria-autocomplete","list"),g.setAttribute("aria-controls",n.id),g.setAttribute("aria-owns",n.id),g.setAttribute("aria-activedescendant",""),g.setAttribute("aria-haspopup","listbox"),a.position="absolute",n.addEventListener("mousedown",(function(e){e.stopPropagation(),e.preventDefault()})),n.addEventListener("focus",(function(){return g.focus()})),g.addEventListener("keyup",z),g.addEventListener("click",B),g.addEventListener("keydown",S),g.addEventListener("input",k),g.addEventListener("blur",_),g.addEventListener("focus",H),window.addEventListener("resize",x),t.addEventListener("scroll",T,!0),{destroy:function(){g.removeEventListener("focus",H),g.removeEventListener("keyup",z),g.removeEventListener("click",B),g.removeEventListener("keydown",S),g.removeEventListener("input",k),g.removeEventListener("blur",_),window.removeEventListener("resize",x),t.removeEventListener("scroll",T,!0),g.removeAttribute("role"),g.removeAttribute("aria-expanded"),g.removeAttribute("aria-autocomplete"),g.removeAttribute("aria-controls"),g.removeAttribute("aria-activedescendant"),g.removeAttribute("aria-owns"),g.removeAttribute("aria-haspopup"),E(),w(),m=!0},fetch:function(){M(g.value,3,g.selectionStart||0)}}}})); | ||
*/return function(e){var t=document,n=e.container||t.createElement("div"),i=e.preventSubmit||0;n.id=n.id||"autocomplete-"+h();var r,o,a=n.style,s=e.debounceWaitMs||0,u=e.disableAutoSelect||!1,c=n.parentElement,d=[],l="",f=2,p=e.showOnFocus,v=0,m=!1,b=!1;if(void 0!==e.minLength&&(f=e.minLength),!e.input)throw new Error("input undefined");var g=e.input;function h(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}function E(){var e=n.parentNode;e&&e.removeChild(n)}function A(){o&&window.clearTimeout(o)}function w(){return!!n.parentNode}function y(){v++,d=[],l="",r=void 0,g.setAttribute("aria-activedescendant",""),g.setAttribute("aria-expanded","false"),E()}function L(){n.innerHTML="",g.setAttribute("aria-activedescendant","");var i=function(e,n,i){var r=t.createElement("div");return r.textContent=e.label||"",r};e.render&&(i=e.render);var o=function(e,n){var i=t.createElement("div");return i.textContent=e,i};e.renderGroup&&(o=e.renderGroup);var s=t.createDocumentFragment(),u=h();if(d.forEach((function(t,a){if(t.group&&t.group!==u){u=t.group;var c=o(t.group,l);c&&(c.className+=" group",s.appendChild(c))}var d=i(t,l,a);d&&(d.id=n.id+"_"+a,d.setAttribute("role","option"),d.addEventListener("click",(function(n){b=!0;try{e.onSelect(t,g)}finally{b=!1}y(),n.preventDefault(),n.stopPropagation()})),t===r&&(d.className+=" selected",d.setAttribute("aria-selected","true"),g.setAttribute("aria-activedescendant",d.id)),s.appendChild(d))})),n.appendChild(s),d.length<1){if(!e.emptyMsg)return void y();var f=t.createElement("div");f.id=n.id+"_"+h(),f.className="empty",f.textContent=e.emptyMsg,n.appendChild(f),g.setAttribute("aria-activedescendant",f.id)}n.parentNode||(c||t.body).appendChild(n),function(){if(w()){g.setAttribute("aria-expanded","true"),a.height="auto",a.width=g.offsetWidth+"px";var i,r=0;o(),o(),e.customize&&i&&e.customize(g,i,n,r)}function o(){var e=t.documentElement,n=e.clientTop||t.body.clientTop||0,o=e.clientLeft||t.body.clientLeft||0,s=window.pageYOffset||e.scrollTop,u=window.pageXOffset||e.scrollLeft,c=(i=g.getBoundingClientRect()).top+g.offsetHeight+s-n,d=i.left+u-o;a.top=c+"px",a.left=d+"px",(r=window.innerHeight-(i.top+g.offsetHeight))<0&&(r=0),a.top=c+"px",a.bottom="",a.left=d+"px",a.maxHeight=r+"px"}}(),D()}function x(){w()&&L()}function T(){x()}function k(e){e.target!==n?x():e.preventDefault()}function C(){b||M(0)}function D(){var e=n.getElementsByClassName("selected");if(e.length>0){var t=e[0],i=t.previousElementSibling;if(i&&-1!==i.className.indexOf("group")&&!i.previousElementSibling&&(t=i),t.offsetTop<n.scrollTop)n.scrollTop=t.offsetTop;else{var r=t.offsetTop+t.offsetHeight,o=n.scrollTop+n.offsetHeight;r>o&&(n.scrollTop+=r-o)}}}function N(e){d.length>0&&(!function(e){var i=t.getElementById(n.id+"_"+e);i&&(i.classList.remove("selected"),i.removeAttribute("aria-selected"),g.removeAttribute("aria-activedescendant"))}(e),function(e){var i=t.getElementById(n.id+"_"+e);i&&(i.classList.add("selected"),i.setAttribute("aria-selected","true"),g.setAttribute("aria-activedescendant",i.id))}(d.indexOf(r)),D())}function S(e,t){var n,i=w();if("Escape"===t)y();else{if(!i||d.length<1)return;"ArrowUp"===t?(n=d.indexOf(r),r=-1===n?void 0:d[(n+d.length-1)%d.length],N(n)):function(){var e=d.indexOf(r);r=d.length<1?void 0:-1===e?d[0]:d[(e+1)%d.length],N(e)}()}e.preventDefault(),i&&e.stopPropagation()}function H(t){var n=t.key;switch(n){case"ArrowUp":case"ArrowDown":case"Escape":S(t,n);break;case"Enter":!function(t){if(r){2===i&&t.preventDefault(),b=!0;try{e.onSelect(r,g)}finally{b=!1}y()}1===i&&t.preventDefault()}(t)}}function O(){p&&M(1)}function M(e){g.value.length>=f||1===e?(A(),o=window.setTimeout((function(){return z(g.value,e,g.selectionStart||0)}),0===e||2===e?s:0)):y()}function z(t,n,i){if(!m){var o=++v;e.fetch(t,(function(e){v===o&&e&&(l=t,r=(d=e).length<1||u?void 0:d[0],L())}),n,i)}}function B(t){e.keyup?e.keyup({event:t,fetch:function(){return M(0)}}):w()||"ArrowDown"!==t.key||M(0)}function _(t){e.click&&e.click({event:t,fetch:function(){return M(2)}})}function P(){setTimeout((function(){t.activeElement!==g&&y()}),200)}return n.className="autocomplete "+(e.className||""),n.setAttribute("role","listbox"),g.setAttribute("role","combobox"),g.setAttribute("aria-expanded","false"),g.setAttribute("aria-autocomplete","list"),g.setAttribute("aria-controls",n.id),g.setAttribute("aria-owns",n.id),g.setAttribute("aria-activedescendant",""),g.setAttribute("aria-haspopup","listbox"),a.position="absolute",n.addEventListener("mousedown",(function(e){e.stopPropagation(),e.preventDefault()})),n.addEventListener("focus",(function(){return g.focus()})),E(),g.addEventListener("keyup",B),g.addEventListener("click",_),g.addEventListener("keydown",H),g.addEventListener("input",C),g.addEventListener("blur",P),g.addEventListener("focus",O),window.addEventListener("resize",T),t.addEventListener("scroll",k,!0),{destroy:function(){g.removeEventListener("focus",O),g.removeEventListener("keyup",B),g.removeEventListener("click",_),g.removeEventListener("keydown",H),g.removeEventListener("input",C),g.removeEventListener("blur",P),window.removeEventListener("resize",T),t.removeEventListener("scroll",k,!0),g.removeAttribute("role"),g.removeAttribute("aria-expanded"),g.removeAttribute("aria-autocomplete"),g.removeAttribute("aria-controls"),g.removeAttribute("aria-activedescendant"),g.removeAttribute("aria-owns"),g.removeAttribute("aria-haspopup"),A(),y(),m=!0},fetch:function(){z(g.value,3,g.selectionStart||0)}}}})); | ||
//# sourceMappingURL=autocomplete.min.js.map |
@@ -635,2 +635,5 @@ /** | ||
// If the custom autocomplete container is already appended to the DOM during widget initialization, detach it. | ||
detach(); | ||
/** | ||
@@ -637,0 +640,0 @@ * This function will remove DOM elements and clear event handlers |
{ | ||
"name": "autocompleter", | ||
"version": "9.0.1", | ||
"version": "9.1.0", | ||
"description": "Blazing fast and lightweight autocomplete library without dependencies. 1KB gzipped.", | ||
@@ -5,0 +5,0 @@ "main": "autocomplete.js", |
Sorry, the diff of this file is not supported yet
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
137363
1224