aria-autocomplete
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"kTsq":[function(require,module,exports) { | ||
Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){var t=this;do{if(t.matches(e))return t;t=t.parentElement||t.parentNode}while(null!==t&&1===t.nodeType);return null}); | ||
},{}],"lTk1":[function(require,module,exports) { | ||
"use strict";function e(e){return null==e?"":(e+"").trim()}function t(t,r){var n=t,a=e(n.getAttribute&&n.getAttribute("class"));return" ".concat(a," ").indexOf(" ".concat(r," "))>-1}function r(t,r){for(var n=e(t.getAttribute&&t.getAttribute("class")),a=" "+n+" ",l="",s=0,o=r.split(" "),i=o.length;s<i;s+=1)""!==o[s]&&-1===a.indexOf(" "+o[s]+" ")&&(l+=" "+o[s]);n!==(l=e(n+l))&&t.setAttribute("class",l)}function n(t,r){for(var n=e(t.getAttribute&&t.getAttribute("class")),a=" "+n+" ",l=0,s=r.split(" "),o=s.length;l<o;l+=1)a=a.replace(" "+s[l]+" "," ");n!==(a=e(a))&&t.setAttribute("class",a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.trimString=e,exports.hasClass=t,exports.addClass=r,exports.removeClass=n,exports.cleanString=i,exports.isPrintableKey=c,exports.mergeObjects=u,exports.dispatchEvent=v,exports.setElementState=f,exports.processSourceArray=g,exports.htmlToElement=d,exports.setCss=h,exports.transferStyles=m;var a=/&/g,l=/\s\s+/g,s=/[\u2018\u2019',:\u2013-]/g,o=/[\-\[\]{}()*+?.,\\\^$|#\s]/g;function i(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return t=(t=(t=(t=e(t).toLowerCase()).replace(s,"")).replace(a,"and")).replace(l," "),r&&(t=t.replace(o,"\\$&")),t}function c(e){return e>=48&&e<=57||e>=65&&e<=90||e>=96&&e<=111||e>=186&&e<=222||32===e||8===e||46===e}function u(){for(var e={},t=0,r=arguments.length;t<r;t+=1){var n=t<0||arguments.length<=t?void 0:arguments[t];for(var a in n)n.hasOwnProperty(a)&&void 0!==n[a]&&(e[a]=n[a])}return e}function v(e,t){if("createEvent"in document){var r=document.createEvent("HTMLEvents");r.initEvent(t,!0,!0),e.dispatchEvent(r)}else e.fireEvent("on"+t)}function f(e,t,r){t=!!t,e&&("INPUT"===e.nodeName&&"boolean"==typeof e.checked&&e.checked!==t&&(e.checked=t,v(e,"change")),"OPTION"===e.nodeName&&e.selected!==t&&(e.selected=t,r.elementChangeEventTimer&&clearTimeout(r.elementChangeEventTimer),r.elementChangeEventTimer=setTimeout(function(){v(e.closest("select"),"change")},1)))}function g(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0,n=[],a=t.value,l=t.label,s=0,o=e.length;s<o;s+=1){var c={},v=e[s];if("string"==typeof v)c.value=c.label=v;else{var f=(c=u(v))[a]||c.value||c.label,g=c[l]||c.label||c.value;c.value=(f||"").toString(),c.label=(g||"").toString()}!1!==r&&(c.cleanedLabel=i(c.label)),n.push(c)}return n}var p=document.createElement("div");function d(t){return p.innerHTML=e(t),p.firstChild}function h(e,t){if(e)for(var r in t){var n="number"==typeof t[r]?t[r]+"px":t[r];e.style[r]=n+""}}function m(e,t,r){if(e&&t){var n=getComputedStyle(e),a={};if(r&&r.length)for(var l=0,s=r.length;l<s;l+=1)a[r[l]]=n[r[l]];else a=n;h(t,a)}} | ||
},{}],"MBeS":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.trimString=r,exports.hasClass=n,exports.addClass=a,exports.removeClass=o,exports.cleanString=u,exports.isPrintableKey=f,exports.mergeObjects=v,exports.dispatchEvent=p,exports.setElementState=g,exports.processSourceArray=h,exports.htmlToElement=m,exports.setCss=E,exports.transferStyles=b,exports.searchVarPropsFor=A,exports.removeDuplicatesAndLabel=y,exports.SELECTED_OPTION=exports.CLEANED_LABEL=void 0;var e="_ariaAutocompleteCleanedLabel";exports.CLEANED_LABEL=e;var t="_ariaAutocompleteSelectedOption";function r(e){return null==e?"":(e+"").trim()}function n(e,t){var n=e,a=r(n.getAttribute&&n.getAttribute("class"));return" ".concat(a," ").indexOf(" ".concat(t," "))>-1}function a(e,t){for(var n=r(e.getAttribute&&e.getAttribute("class")),a=" "+n+" ",o="",i=0,s=t.split(" "),l=s.length;i<l;i+=1)""!==s[i]&&-1===a.indexOf(" "+s[i]+" ")&&(o+=" "+s[i]);n!==(o=r(n+o))&&e.setAttribute("class",o)}function o(e,t){for(var n=r(e.getAttribute&&e.getAttribute("class")),a=" "+n+" ",o=0,i=t.split(" "),s=i.length;o<s;o+=1)a=a.replace(" "+i[o]+" "," ");n!==(a=r(a))&&e.setAttribute("class",a)}exports.SELECTED_OPTION=t;var i=/&/g,s=/\s\s+/g,l=/[\u2018\u2019',:\u2013-]/g,c=/[\-\[\]{}()*+?.,\\\^$|#\s]/g;function u(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e=r(e).toLowerCase().replace(l,"").replace(i,"and").replace(s," "),t&&(e=e.replace(c,"\\$&")),e}function f(e){return e>=48&&e<=57||e>=65&&e<=90||e>=96&&e<=111||e>=186&&e<=222||32===e||8===e||46===e}function v(){for(var e={},t=0,r=arguments.length;t<r;t+=1){var n=t<0||arguments.length<=t?void 0:arguments[t];for(var a in n)n.hasOwnProperty(a)&&void 0!==n[a]&&(e[a]=n[a])}return e}function p(e,t){if("createEvent"in document){var r=document.createEvent("HTMLEvents");r.initEvent(t,!0,!0),e.dispatchEvent(r)}else e.fireEvent("on"+t)}function g(e,t,r){t=!!t,e&&("INPUT"===e.nodeName&&"boolean"==typeof e.checked&&e.checked!==t&&(e.checked=t,p(e,"change")),"OPTION"===e.nodeName&&e.selected!==t&&(e.selected=t,r.elementChangeEventTimer&&clearTimeout(r.elementChangeEventTimer),r.elementChangeEventTimer=setTimeout(function(){p(e.closest("select"),"change")},1)))}function h(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,a=[],o=r.value,i=r.label,s=0,l=t.length;s<l;s+=1){var c={},f=t[s];if("string"==typeof f)c.value=c.label=f;else{var p=(c=v(f))[o]||c.value||c.label,g=c[i]||c.label||c.value;c.value=(p||"").toString(),c.label=(g||"").toString()}!1!==n&&(c[e]=u(c.label)),a.push(c)}return a}var d=document.createElement("div");function m(e){return d.innerHTML=r(e),d.firstChild}function E(e,t){if(e)for(var r in t){var n="number"==typeof t[r]?t[r]+"px":t[r];e.style[r]=n+""}}function b(e,t,r){if(e&&t){var n=getComputedStyle(e),a={};if(r&&r.length)for(var o=0,i=r.length;o<i;o+=1)a[r[o]]=n[r[o]];else a=n;E(t,a)}}var x=function t(r,n,a){if("string"==typeof r)return a!==e&&(r=u(r,!1)),-1!==r.search(n);if(Array.isArray(r))for(var o=0,i=r.length;o<i;o+=1)if(t(r[o],n))return!0;return!1};function A(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];for(var a in n&&(r=u(r,!0)),e)if(e.hasOwnProperty(a)){var o=!1;if("string"==typeof e[a]){for(var i=t.length;i--;)if(t[i]===a){o=!0;break}}else o=Array.isArray(e[a]);if(o&&x(e[a],r,a))return!0}return!1}function y(e){for(var t=[],n=0,a=e.length;n<a;n+=1)if("string"==typeof e[n]){for(var o=r(e[n]),i="label"!==o,s=t.length;i&&s--;)t[s]===o&&(i=!1);i&&t.push(o)}return t} | ||
},{}],"KnPF":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t,e=require("./helpers");function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function r(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t}var s=function(){function i(t){n(this,i),this.input=t,this.currentString,this.eventHandler,this.currentWidth,this.init()}return r(i,[{key:"trigger",value:function(){this.checkAndSet.call(this)}},{key:"getInputSelection",value:function(){var t={};if("selectionStart"in this.input)t.start=this.input.selectionStart,t.length=this.input.selectionEnd-t.start;else if(document.selection){this.input.focus();var e=document.selection.createRange(),n=e.text.length;e.moveStart("character",-this.input.value.length),t.start=e.text.length-n,t.length=n}return t}},{key:"measureString",value:function(n){return n?n===this.currentString?this.currentWidth:(t||(t=document.createElement("span"),(0,e.setCss)(t,{position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}),document.body.appendChild(t)),t.textContent=n,this.currentString=n,(0,e.transferStyles)(this.input,t,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]),t.offsetWidth||t.clientWidth):(this.currentString=n,0)}},{key:"checkAndSet",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!t.metaKey&&!t.altKey){var n,i=this.input.value;if(t.type&&"keydown"===t.type.toLowerCase()){var r=t.keyCode,s=46===r,a=8===r;if(s||a){var u=this.getInputSelection();u.length?i=i.substring(0,u.start)+i.substring(u.start+u.length):a&&u.start?i=i.substring(0,u.start-1)+i.substring(u.start+1):s&&void 0!==u.start&&(i=i.substring(0,u.start)+i.substring(u.start+1))}else if((0,e.isPrintableKey)(r)){var h=t.shiftKey,o=String.fromCharCode(r);i+=o=h?o.toUpperCase():o.toLowerCase()}}!i&&(n=this.input.getAttribute("placeholder"))&&(i=n);var l=this.measureString(i)+4;l!==this.currentWidth&&(this.currentWidth=l,this.input.style.width="".concat(l,"px"))}}},{key:"destroy",value:function(){this.input.removeEventListener("blur",this.eventHandler),this.input.removeEventListener("input",this.eventHandler),this.input.removeEventListener("keyup",this.eventHandler),this.input.removeEventListener("keydown",this.eventHandler),this.input=null}},{key:"init",value:function(){this.checkAndSet(),this.eventHandler=this.checkAndSet.bind(this),this.input.addEventListener("blur",this.eventHandler),this.input.addEventListener("input",this.eventHandler),this.input.addEventListener("keyup",this.eventHandler),this.input.addEventListener("keydown",this.eventHandler)}}]),i}();exports.default=s; | ||
},{"./helpers":"lTk1"}],"c8cM":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0,require("./closest-polyfill");var e=i(require("./autogrow")),t=require("./helpers");function i(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var i=0;i<t.length;i++){var s=t[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function l(e,t,i){return t&&n(e.prototype,t),i&&n(e,i),e}var r=0,o={name:"",source:"",sourceMapping:{},delay:100,minLength:1,maxResults:9999,showAllControl:!1,confirmOnBlur:!0,multiple:!1,autoGrow:!1,maxItems:9999,multipleSeparator:",",deleteOnBackspace:!1,asyncQueryParam:"q",asyncMaxResultsParam:"limit",placeholder:"",noResultsText:"No results",cssNameSpace:"aria-autocomplete",listClassName:"",inputClassName:"",wrapperClassName:"",srDeleteText:"delete",srDeletedText:"deleted",srShowAllText:"Show all",srSelectedText:"selected",srListLabelText:"Search suggestions",srAssistiveText:"When results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.",srResultsText:function(e){return"".concat(e," ").concat(1===e?"result":"results"," available.")},onAsyncPrep:void 0,onAsyncSuccess:void 0,onResponse:void 0,onSearch:void 0,onConfirm:void 0,onDelete:void 0,onReady:void 0,onClose:void 0,onOpen:void 0},a=function(){function i(e,t){if(s(this,i),e){if(e.ariaAutocomplete)return e.ariaAutocomplete;this.options,this.element,this.elementIsInput,this.elementIsSelect,this.list,this.input,this.wrapper,this.showAll,this.srAnnouncements,this.ids,this.xhr,this.term,this.async,this.source,this.menuOpen,this.multiple,this.selected,this.disabled,this.autoGrow,this.filtering,this.cssNameSpace,this.forceShowAll,this.filteredSource,this.currentListHtml,this.inputPollingValue,this.currentSelectedIndex,this.documentClick,this.documentClickBound,this.filterTimer,this.pollingTimer,this.announcementTimer,this.componentBlurTimer,this.elementChangeEventTimer,this.AutoGrowInput,this.init(e,t)}}return l(i,[{key:"triggerOptionCallback",value:function(e,t,i){if(i=void 0===i?this.api:i,"function"==typeof this.options[e])return this.options[e].apply(i,t)}},{key:"show",value:function(e){if(void 0!==e){var i="".concat(this.cssNameSpace,"--hide hide hidden");return(0,t.removeClass)(e,i),e.removeAttribute("hidden")}if(this.input.setAttribute("aria-expanded","true"),this.showAll){var s=(!!this.forceShowAll).toString();this.showAll.setAttribute("aria-expanded",s)}this.menuOpen||(this.show(this.list),this.menuOpen=!0,this.triggerOptionCallback("onOpen",[this.list]),this.documentClickBound||(this.documentClickBound=!0,document.addEventListener("click",this.documentClick)))}},{key:"hide",value:function(e){if(void 0!==e)return(0,t.addClass)(e,"".concat(this.cssNameSpace,"--hide hide hidden")),e.setAttribute("hidden","hidden");this.currentSelectedIndex=-1,this.input.setAttribute("aria-expanded","false"),this.showAll&&this.showAll.setAttribute("aria-expanded","false"),this.menuOpen&&(this.hide(this.list),this.menuOpen=!1,this.triggerOptionCallback("onClose",[this.list]))}},{key:"enable",value:function(){if(this.disabled){this.disabled=!1,this.input.disabled=!1;var e=this.cssNameSpace;(0,t.removeClass)(this.input,"".concat(e,"__input--disabled disabled")),(0,t.removeClass)(this.wrapper,"".concat(e,"__wrapper--disabled disabled")),this.showAll&&(this.showAll.setAttribute("tabindex","0"),(0,t.removeClass)(this.showAll,"".concat(e,"__show-all--disabled disabled")))}}},{key:"disable",value:function(){if(!this.disabled){this.disabled=!0,this.input.disabled=!0;var e=this.cssNameSpace;(0,t.addClass)(this.input,"".concat(e,"__input--disabled disabled")),(0,t.addClass)(this.wrapper,"".concat(e,"__wrapper--disabled disabled")),this.showAll&&(this.showAll.setAttribute("tabindex","-1"),(0,t.addClass)(this.showAll,"".concat(e,"__show-all--disabled disabled")))}}},{key:"triggerAutoGrow",value:function(){this.autoGrow&&this.AutoGrowInput&&this.AutoGrowInput.trigger()}},{key:"setInputValue",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.input.value=this.term=e,t&&(this.inputPollingValue=e)}},{key:"isQueryContainedIn",value:function(e,i,s){if(e=(0,t.trimString)(e||this.input.value).toLowerCase()){s=s||"label";for(var n=0,l=i.length;n<l;n+=1)if((0,t.trimString)(i[n][s]).toLowerCase()===e)return n}return-1}},{key:"announce",value:function(e,t){var i=this;if(e&&this.srAnnouncements){if(0===t)return this.srAnnouncements.textContent=e;t="number"==typeof t?t:400,this.announcementTimer&&clearTimeout(this.announcementTimer),this.announcementTimer=setTimeout(function(){i.srAnnouncements.textContent=e},t)}}},{key:"isSelectedElem",value:function(e){return this.multiple&&e.ariaAutocompleteSelectedOption&&(0,t.hasClass)(e,"".concat(this.cssNameSpace,"__selected"))}},{key:"getSelectedElems",value:function(){for(var e=this.wrapper.childNodes,t=[],i=0,s=e.length;i<s;i+=1)this.isSelectedElem(e[i])&&t.push(e[i]);return t}},{key:"removeEntryFromSelected",value:function(e){var i=this.selected.indexOf(e);if(-1===i)for(var s=0,n=this.selected.length;s<n;s+=1)if(this.selected[s].value===e.value){i=s;break}if(i>-1&&this.selected[i]){var l=(0,t.mergeObjects)(this.selected[i]),r=l.label;(0,t.setElementState)(l.element,!1,this),this.selected.splice(i,1),this.triggerOptionCallback("onDelete",[l]),this.buildMultiSelected(),this.announce("".concat(r," ").concat(this.options.srDeletedText),0)}}},{key:"buildMultiSelected",value:function(){if(this.multiple){this.multiple&&this.selected.length>=this.options.maxItems?this.disable():this.enable();var e=this.getSelectedElems();if(this.selected.length||e.length){for(var i=[],s=e.length;s--;){for(var n=e[s].ariaAutocompleteSelectedOption,l=this.selected.length,r=!1;l--;){var o=this.selected[l];if(o===n||o.value===n.value){r=!0;break}}r?i.push(e[s]):this.wrapper.removeChild(e[s])}for(var a=this.options.srDeleteText,c=document.createDocumentFragment(),h="".concat(this.cssNameSpace,"__selected"),u=0,d=this.selected.length;u<d;u+=1){for(var p=this.selected[u],m=i.length,f=!1;m--;){var v=i[m].ariaAutocompleteSelectedOption;if(v===p||v.value===p.value){f=!0;break}}if(!f){var g=p.label,S=(0,t.htmlToElement)('<span role="button" class="'.concat(h,'" ')+'tabindex="0" aria-label="'.concat(a," ").concat(g,'">')+"".concat(g,"</span>"));S.ariaAutocompleteSelectedOption=p,c.appendChild(S)}}c.childNodes&&c.childNodes.length&&this.wrapper.insertBefore(c,this.list);for(var b=[],y=0,A=(i=this.getSelectedElems()).length;y<A;y+=1){var w="".concat(this.ids.OPTION_SELECTED,"-").concat(y);i[y].setAttribute("id",w),b.push(w)}if(b.push(this.ids.LIST),this.input.setAttribute("aria-owns",b.join(" ")),this.autoGrow&&this.options.placeholder){var k=this.selected.length?"":this.options.placeholder;this.input.setAttribute("placeholder",k)}}}}},{key:"setInputDescription",value:function(){var e=this.input.getAttribute("aria-describedby"),i=(0,t.trimString)(e||""),s=i.replace(this.ids.SR_ASSISTANCE,"");0===this.input.value.length&&(s=s+" "+this.ids.SR_ASSISTANCE),(s=(0,t.trimString)(s))?s!==i&&this.input.setAttribute("aria-describedby",s):e&&this.input.removeAttribute("aria-describedby")}},{key:"resetOptionAttributes",value:function(){for(var e=this.cssNameSpace,i=this.list.childNodes,s=i.length;s--;)(0,t.removeClass)(i[s],"".concat(e,"__option--focused focused focus")),i[s].setAttribute("aria-selected","false")}},{key:"setOptionFocus",value:function(e,i){this.resetOptionAttributes();var s=this.list.childNodes;if(i<0||!s||!s.length)return this.currentSelectedIndex=-1,void(e&&e.target!==this.input&&this.input.focus());if(i>=s.length)return this.currentSelectedIndex=s.length-1,void this.setOptionFocus(e,this.currentSelectedIndex);var n=s[i];if(n&&"string"==typeof n.getAttribute("tabindex")){this.currentSelectedIndex=i;var l="".concat(this.cssNameSpace,"__option--focused focused focus");return(0,t.addClass)(n,l),n.setAttribute("aria-selected","true"),void n.focus()}this.currentSelectedIndex=-1}},{key:"setSourceElementValues",value:function(){for(var e=[],i=0,s=this.selected.length;i<s;i+=1){var n=this.selected[i];e.push(n.value),(0,t.setElementState)(n.element,!0,this)}if(this.elementIsInput){var l=e.join(this.options.multipleSeparator);l!==this.element.value&&(this.element.value=l,(0,t.dispatchEvent)(this.element,"change"))}!this.selected.length&&this.elementIsSelect&&(this.element.value="")}},{key:"handleOptionSelect",value:function(e,i){var s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!("number"!=typeof i||i<0||this.multiple&&this.selected.length>=this.options.maxItems)&&this.filteredSource.length&&this.filteredSource[i]){for(var n=(0,t.mergeObjects)(this.filteredSource[i]),l=this.selected.length,r=!1;l--;)if(this.selected[l].value===n.value){r=!0;break}this.setInputValue(this.multiple?"":n.label,!0),this.triggerAutoGrow(),r||this.multiple||(this.selected=[]),r||(this.selected.push(n),this.setSourceElementValues(),this.buildMultiSelected()),this.triggerOptionCallback("onConfirm",[n]),this.announce("".concat(n.label," ").concat(this.options.srSelectedText),0),this.disabled||!1===s||this.input.focus(),this.hide()}}},{key:"removeSelectedFromResults",value:function(e){if(!this.multiple||!this.selected.length)return e;var t=[];e:for(var i=0,s=e.length;i<s;i+=1){for(var n=this.selected,l=e[i],r=0,o=n.length;r<o;r+=1){if(l.label===n[r].label&&l.value===n[r].value)continue e}t.push(l)}return t}},{key:"setListOptions",value:function(e){var i=[],s=this.ids.OPTION,n=this.cssNameSpace,l=this.options.sourceMapping,r=this.removeSelectedFromResults(e),o=this.triggerOptionCallback("onResponse",r);this.filteredSource=o?(0,t.processSourceArray)(o,l):r;for(var a,c=this.filteredSource.length,h=this.forceShowAll?9999:this.options.maxResults,u=0;u<c&&u<h;u+=1)i.push('<li tabindex="-1" aria-selected="false" role="option" class="'.concat(n,'__option" ')+'id="'.concat(s,"--").concat(u,'" aria-posinset="').concat(u+1,'" ')+'aria-setsize="'.concat(c,'">').concat(this.filteredSource[u].label,"</li>"));i.length?((0,t.addClass)(this.list,"".concat(n,"__list--has-results")),(0,t.removeClass)(this.list,"".concat(n,"__list--no-results"))):((0,t.removeClass)(this.list,"".concat(n,"__list--has-results")),(0,t.addClass)(this.list,"".concat(n,"__list--no-results")));var d=this.options.noResultsText;if(!i.length&&"string"==typeof d&&d.length){a=d;var p="".concat(n,"__option");i.push('<li class="'.concat(p," ").concat(p,'--no-results">').concat(d,"</li>"))}this.cancelFilterPrep(),a||(a=this.triggerOptionCallback("srResultsText",[c])),this.announce(a);var m=i.join("");if(this.currentListHtml!==m?(this.currentListHtml=m,this.list.innerHTML=m):this.resetOptionAttributes(),!i.length)return this.hide(),void(this.forceShowAll=!1);this.show(),this.forceShowAll=!1}},{key:"handleAsync",value:function(e){var i=this,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=new XMLHttpRequest,l=encodeURIComponent,r=this.forceShowAll,o=r||s,a=this.multiple?this.selected.length:0,c=/\?/.test(this.source)?"&":"?",h=this.source+c+"".concat(l(this.options.asyncQueryParam),"=").concat(l(e),"&")+"".concat(l(this.options.asyncMaxResultsParam),"=")+"".concat(o?9999:a+this.options.maxResults);this.xhr&&this.xhr.abort();var u=s?null:this.api;h=this.triggerOptionCallback("onAsyncPrep",[h],u)||h,n.open("GET",h),n.onload=function(){if(n.readyState===n.DONE&&200===n.status){i.forceShowAll=r;var l=s?null:i.api,o=i.triggerOptionCallback("onAsyncSuccess",[e,n],l),a=i.options.sourceMapping,c=o||n.responseText,h=(0,t.processSourceArray)(c,a,!1);s?(i.prepSelectedFromArray(h),i.setInputStartingStates(!1)):i.setListOptions(h)}},s||(this.xhr=n),n.send()}},{key:"filter",value:function(e){var i=this;if("string"==typeof e){var s=this.forceShowAll,n=this.triggerOptionCallback("onSearch",[e]),l=[];if(s||"string"!=typeof n||(e=n),this.term=this.inputPollingValue=e,this.async)return this.handleAsync(e),void(this.forceShowAll=!1);if("function"!=typeof this.source){if(e||(s=!0),this.source&&this.source.length){s||(e=(0,t.cleanString)(e,!0));for(var r=0,o=this.source.length;r<o;r+=1){var a=this.source[r];(s||-1!==a.cleanedLabel.search(e))&&l.push({element:a.element,staticSourceIndex:r,label:a.label,value:a.value})}}this.setListOptions(l)}else this.source.call(this.api,this.term,function(e){var s=i.options.sourceMapping,n=(0,t.processSourceArray)(e,s);i.setListOptions(n)})}else this.cancelFilterPrep()}},{key:"cancelFilterPrep",value:function(){this.filterTimer&&clearTimeout(this.filterTimer);var e=this.cssNameSpace;(0,t.removeClass)(this.wrapper,"".concat(e,"__wrapper--loading loading")),(0,t.removeClass)(this.input,"".concat(e,"__input--loading loading")),this.filtering=!1}},{key:"filterPrep",value:function(e){var i=this,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],l=this.forceShowAll,r=l||n?0:this.options.delay;this.cancelFilterPrep(),this.filtering=!0,this.filterTimer=setTimeout(function(){var n=i.input.value;if((l||""===n||s&&!i.multiple&&i.selected.length&&(0,t.trimString)(i.selected[0].label)===(0,t.trimString)(n))&&(n=""),i.setInputDescription(),i.inputPollingValue=n,!l&&n.length<i.options.minLength)i.hide();else{var r;try{r=e&&"keydown"===e.type&&(e.altKey||e.ctrlKey||e.metaKey)}catch(e){}var o=""!==n&&n===i.term;if(!o||o&&!i.menuOpen&&!r){var a=i.cssNameSpace;(0,t.addClass)(i.wrapper,"".concat(a,"__wrapper--loading loading")),(0,t.addClass)(i.input,"".concat(a,"__input--loading loading")),i.currentSelectedIndex=-1,i.filter(n)}}},r)}},{key:"filterPrepShowAll",value:function(e){var t=this;this.disabled||(this.showAllPrepTimer&&clearTimeout(this.showAllPrepTimer),this.showAllPrepTimer=setTimeout(function(){t.componentBlurTimer&&clearTimeout(t.componentBlurTimer),e.preventDefault(),t.forceShowAll=!0,t.filterPrep(e,!1,!0)}))}},{key:"handleComponentBlur",value:function(e){var i=this,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=s?0:100;this.componentBlurTimer&&clearTimeout(this.componentBlurTimer),this.componentBlurTimer=setTimeout(function(){var e=document.activeElement;if(s||!e||i.showAll&&i.showAll===e||e.ariaAutocompleteSelectedOption||!i.wrapper.contains(e)){i.xhr&&i.xhr.abort();var n=i.isQueryContainedIn.bind(i);if(!s&&i.options.confirmOnBlur&&i.menuOpen){var l=i.currentSelectedIndex;"number"==typeof l&&-1!==l||(l=n("",i.filteredSource)),i.handleOptionSelect({},l,!1)}if(i.cancelFilterPrep(),i.hide(),!i.multiple&&-1===n("",i.selected))(i.elementIsInput||i.elementIsSelect)&&""!==i.element.value&&(i.element.value="",(0,t.dispatchEvent)(i.element,"change")),i.selected.length&&i.removeEntryFromSelected(i.selected[0]),i.setInputValue("",!0);i.multiple&&i.setInputValue("",!0),i.triggerAutoGrow(),i.documentClickBound&&(i.documentClickBound=!1,document.removeEventListener("click",i.documentClick))}},n)}},{key:"handleEnterKey",value:function(e){if(this.isSelectedElem(e.target)){var t=e.target.ariaAutocompleteSelectedOption;return this.removeEntryFromSelected(t)}this.disabled||(this.showAll&&e.target===this.showAll?this.filterPrepShowAll(e):(this.menuOpen&&(e.preventDefault(),this.currentSelectedIndex>-1&&this.handleOptionSelect(e,this.currentSelectedIndex)),e.target===this.input&&this.filterPrep(e,!1,!0)))}},{key:"handleDownArrowKey",value:function(e){if(e.preventDefault(),this.menuOpen||(this.forceShowAll=this.options.minLength<1,(this.forceShowAll||this.input.value.length>=this.options.minLength)&&this.filterPrep(e)),this.menuOpen&&!this.filtering){var t=this.currentSelectedIndex;"number"!=typeof t||t<0?this.setOptionFocus(e,0):this.setOptionFocus(e,t+1)}}},{key:"handleUpArrowKey",value:function(e){e.preventDefault(),!this.disabled&&this.menuOpen&&"number"==typeof this.currentSelectedIndex&&this.setOptionFocus(e,this.currentSelectedIndex-1)}},{key:"handleKeyDownDefault",value:function(e){var i=e.target===this.input;if(32===e.keyCode&&!i)return e.preventDefault(),this.handleEnterKey(e);if(!this.disabled){var s=this.selected&&this.selected.length;if(this.options.deleteOnBackspace&&""===this.input.value&&8===e.keyCode&&s&&i&&this.multiple)this.removeEntryFromSelected(this.selected[s-1]);else{var n=(0,t.isPrintableKey)(e.keyCode),l=!i&&n;l&&this.input.focus(),(l||i&&n)&&this.filterPrep(e)}}}},{key:"prepKeyDown",value:function(e){switch(e.keyCode){case 13:this.handleEnterKey(e);break;case 27:this.handleComponentBlur(e,!0);break;case 38:this.handleUpArrowKey(e);break;case 40:this.handleDownArrowKey(e);break;default:this.handleKeyDownDefault(e)}}},{key:"cancelPolling",value:function(){this.pollingTimer&&clearTimeout(this.pollingTimer)}},{key:"startPolling",value:function(){var e=this;this.filtering||this.input.value===this.inputPollingValue||this.filterPrep({}),this.pollingTimer=setTimeout(function(){e.startPolling()},200)}},{key:"bindEvents",value:function(){var i=this;this.wrapper.addEventListener("focusout",function(e){i.handleComponentBlur(e,!1)}),this.wrapper.addEventListener("focusin",function(e){i.list.contains(e.target)||(i.currentSelectedIndex=-1)}),this.wrapper.addEventListener("keydown",function(e){i.prepKeyDown(e)}),this.wrapper.addEventListener("click",function(e){if(e.target!==i.wrapper){if(i.isSelectedElem(e.target)){var t=e.target.ariaAutocompleteSelectedOption;i.removeEntryFromSelected(t)}}else i.input.focus()});var s="".concat(this.cssNameSpace,"__wrapper--focused focused focus"),n="".concat(this.cssNameSpace,"__input--focused focused focus");this.input.addEventListener("blur",function(){(0,t.removeClass)(i.wrapper,s),(0,t.removeClass)(i.input,n),i.cancelPolling()}),this.input.addEventListener("input",function(e){i.filterPrep(e)}),this.input.addEventListener("click",function(e){!i.menuOpen&&i.input.value.length>=i.options.minLength&&i.filterPrep(e,!0)}),this.input.addEventListener("focusin",function(){(0,t.addClass)(i.wrapper,s),(0,t.addClass)(i.input,n),i.startPolling(),i.disabled||i.menuOpen||i.filterPrep(event,!0)}),this.showAll&&this.showAll.addEventListener("click",function(e){i.filterPrepShowAll(e)}),this.list.addEventListener("mouseenter",function(e){i.resetOptionAttributes()}),this.list.addEventListener("click",function(e){if(e.target!==i.list){var t=i.list.childNodes;if(t.length){var s=[].indexOf.call(t,e.target);i.handleOptionSelect(e,s)}}}),this.autoGrow&&(this.AutoGrowInput=new e.default(this.input))}},{key:"prepListSourceCheckboxes",value:function(){this.multiple=!0,this.source=[];for(var e=this.element.querySelectorAll('input[type="checkbox"]'),i=0,s=e.length;i<s;i+=1){var n=e[i];if(n.value){var l={element:n,value:n.value},r=n.closest("label");!r&&n.id&&(r=document.querySelector('[for="'+n.id+'"]')),r&&(l.label=r.textContent),l.label||(l.label=l.value),l.cleanedLabel=(0,t.cleanString)(l.label),this.source.push(l),n.checked&&this.selected.push(l)}}}},{key:"prepListSourceDdl",value:function(){this.multiple=this.element.multiple,this.source=[];for(var e=this.element.querySelectorAll("option"),i=0,s=e.length;i<s;i+=1){var n=e[i];if(n.value){var l={element:n,value:n.value,label:n.textContent};l.cleanedLabel=(0,t.cleanString)(l.label),this.source.push(l),n.selected&&this.selected.push(l)}}}},{key:"prepSelectedFromArray",value:function(e){var t=this.elementIsInput&&this.element.value;if(t&&e&&e.length)for(var i=this.options.multiple,s=this.options.multipleSeparator,n=i?t.split(s):[t],l=0,r=n.length;l<r;l+=1){var o=n[l],a=this.isQueryContainedIn;if(!(a(o,this.selected,"value")>-1)){var c=a(o,e,"value");c>-1&&this.selected.push(e[c])}}}},{key:"prepListSourceArray",value:function(){var e=this.options.sourceMapping;this.source=(0,t.processSourceArray)(this.source,e),this.prepSelectedFromArray(this.source)}},{key:"prepListSourceAsync",value:function(){this.async=!0,this.elementIsInput&&this.element.value&&this.handleAsync(this.element.value,!0)}},{key:"prepListSourceFunction",value:function(){var e=this;this.elementIsInput&&this.element.value&&this.source.call(void 0,this.element.value,function(i){e.prepSelectedFromArray((0,t.processSourceArray)(i,e.options.sourceMapping)),e.setInputStartingStates(!1)})}},{key:"prepListSource",value:function(){return"function"==typeof this.source?this.prepListSourceFunction():"string"==typeof this.source&&this.source.length?this.prepListSourceAsync():Array.isArray(this.source)&&this.source.length?this.prepListSourceArray():this.elementIsSelect?this.prepListSourceDdl():void(this.element.querySelector('input[type="checkbox"]')&&this.prepListSourceCheckboxes())}},{key:"setInputStartingStates",value:function(){if(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]){if(this.ids.ELEMENT){var e=document.querySelector('[for="'+this.ids.ELEMENT+'"]');e&&(e.ariaAutocompleteOriginalFor=this.ids.ELEMENT,e.setAttribute("for",this.ids.INPUT))}var t=this.element.getAttribute("aria-describedby");t&&this.input.setAttribute("aria-describedby",t);var i=this.element.getAttribute("aria-labelledby");i&&this.input.setAttribute("aria-labelledby",i)}this.selected.length&&(this.multiple?this.buildMultiSelected():(this.setInputValue(this.selected[0].label||"",!0),this.triggerAutoGrow())),this.setInputDescription(),this.element.disabled&&this.disable()}},{key:"setHtml",value:function(){var e=this.options,t=this.cssNameSpace,i=e.srListLabelText,s=e.name?" ".concat(e.name):"",n=e.listClassName?" ".concat(e.listClassName):"",l=e.inputClassName?" ".concat(e.inputClassName):"",r=e.wrapperClassName?" ".concat(e.wrapperClassName):"",o=i?' aria-label="'.concat(i,'"'):"",a=['<div id="'.concat(this.ids.WRAPPER,'" class="').concat(t,"__wrapper").concat(r,'">')];a.push('<input type="text" autocomplete="off" aria-expanded="false" aria-autocomplete="list" '+'role="combobox" id="'.concat(this.ids.INPUT,'" placeholder="').concat(e.placeholder,'" ')+'aria-owns="'.concat(this.ids.LIST,'" aria-placeholder="').concat(e.placeholder,'" ')+'class="'.concat(t,"__input").concat(l,'"').concat(s," />")),e.showAllControl&&a.push('<span role="button" aria-label="'.concat(e.srShowAllText,'" class="').concat(t,'__show-all" ')+'tabindex="0" id="'.concat(this.ids.BUTTON,'" aria-expanded="false"></span>')),a.push('<ul id="'.concat(this.ids.LIST,'" class="').concat(t,"__list").concat(n,'" role="listbox" ')+'hidden="hidden"'.concat(o,"></ul>")),a.push('<span class="sr-only '.concat(t,"__sr-only ").concat(t,'__sr-assistance" ')+'id="'.concat(this.ids.SR_ASSISTANCE,'">').concat(e.srAssistiveText,"</span>")),a.push('<span class="sr-only '.concat(t,"__sr-only ").concat(t,'__sr-announcements" ')+'id="'.concat(this.ids.SR_ANNOUNCEMENTS,'" aria-live="polite" aria-atomic="true"></span>')),a.push("</div>"),this.element.insertAdjacentHTML("afterend",a.join(""))}},{key:"generateApi",value:function(){var e=this;this.api={open:function(){return e.show.call(e)},close:function(){return e.hide.call(e)},filter:function(t){return e.filter.call(t)}};for(var t=["options","refresh","destroy","enable","disable","input","wrapper","list","selected"],i=function(i,s){e.api[t[i]]="function"==typeof e[t[i]]?function(){return e[t[i]].call(e)}:e[t[i]]},s=0,n=t.length;s<n;s+=1)i(s);this.element.ariaAutocomplete=this.api}},{key:"refresh",value:function(){var e=this.element,i=(0,t.mergeObjects)(this.options);this.destroy(),this.init(e,i)}},{key:"destroy",value:function(){var e=document.querySelector('[for="'+this.ids.INPUT+'"]');for(var t in e&&e.ariaAutocompleteOriginalFor&&(e.setAttribute("for",e.ariaAutocompleteOriginalFor),delete e.ariaAutocompleteOriginalFor),this.documentClickBound&&document.removeEventListener("click",this.documentClick),this.autoGrow&&this.AutoGrowInput&&this.AutoGrowInput.destroy(),this.element.parentNode.removeChild(this.wrapper),delete this.element.ariaAutocomplete,this.show(this.element),this)this.hasOwnProperty(t)&&(this[t]=null)}},{key:"init",value:function(e,i){r+=1,this.ids={},this.ids.ELEMENT=e.id,this.ids.PREFIX="".concat(e.id||"","aria-autocomplete-").concat(r),this.ids.LIST="".concat(this.ids.PREFIX,"-list"),this.ids.INPUT="".concat(this.ids.PREFIX,"-input"),this.ids.BUTTON="".concat(this.ids.PREFIX,"-button"),this.ids.OPTION="".concat(this.ids.PREFIX,"-option"),this.ids.WRAPPER="".concat(this.ids.PREFIX,"-wrapper"),this.ids.OPTION_SELECTED="".concat(this.ids.OPTION,"-selected"),this.ids.SR_ASSISTANCE="".concat(this.ids.PREFIX,"-sr-assistance"),this.ids.SR_ANNOUNCEMENTS="".concat(this.ids.PREFIX,"-sr-announcements"),this.selected=[],this.element=e,this.elementIsInput="INPUT"===e.nodeName,this.elementIsSelect="SELECT"===e.nodeName,this.options=(0,t.mergeObjects)(o,i),this.source=this.options.source,this.multiple=this.options.multiple,this.autoGrow=this.options.autoGrow,this.cssNameSpace=this.options.cssNameSpace,this.documentClick=this.handleComponentBlur.bind(this),this.setHtml(),this.list=document.getElementById(this.ids.LIST),this.input=document.getElementById(this.ids.INPUT),this.wrapper=document.getElementById(this.ids.WRAPPER),this.showAll=document.getElementById(this.ids.BUTTON),this.srAnnouncements=document.getElementById(this.ids.SR_ANNOUNCEMENTS),this.prepListSource();var s="";this.options.showAllControl&&(s+=" ".concat(this.cssNameSpace,"__wrapper--show-all")),this.options.autoGrow&&(s+=" ".concat(this.cssNameSpace,"__wrapper--autogrow")),this.multiple&&(s+=" ".concat(this.cssNameSpace,"__wrapper--multiple")),s&&(0,t.addClass)(this.wrapper,s),this.hide(this.list),this.hide(this.element),this.generateApi(),this.setInputStartingStates(),this.bindEvents(),this.triggerOptionCallback("onReady",[this.wrapper])}}]),i}();window.AriaAutocomplete=function(e,t){return new a(e,t).api};var c=function(e,t){return new a(e,t).api};exports.default=c; | ||
},{"./closest-polyfill":"kTsq","./autogrow":"KnPF","./helpers":"lTk1"}]},{},["c8cM"], null) | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t,e=require("./autocomplete-helpers");function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function r(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t}var s=function(){function i(t){n(this,i),this.input=t,this.currentString,this.eventHandler,this.currentWidth,this.init()}return r(i,[{key:"trigger",value:function(){this.checkAndSet.call(this)}},{key:"getInputSelection",value:function(){var t={};if("selectionStart"in this.input)t.start=this.input.selectionStart,t.length=this.input.selectionEnd-t.start;else if(document.selection){this.input.focus();var e=document.selection.createRange(),n=e.text.length;e.moveStart("character",-this.input.value.length),t.start=e.text.length-n,t.length=n}return t}},{key:"measureString",value:function(n){return n?n===this.currentString?this.currentWidth:(t||(t=document.createElement("span"),(0,e.setCss)(t,{position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}),document.body.appendChild(t)),t.textContent=n,this.currentString=n,(0,e.transferStyles)(this.input,t,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]),t.offsetWidth||t.clientWidth):(this.currentString=n,0)}},{key:"checkAndSet",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!t.metaKey&&!t.altKey){var n,i=this.input.value;if(t.type&&"keydown"===t.type.toLowerCase()){var r=t.keyCode,s=46===r,a=8===r;if(s||a){var u=this.getInputSelection();u.length?i=i.substring(0,u.start)+i.substring(u.start+u.length):a&&u.start?i=i.substring(0,u.start-1)+i.substring(u.start+1):s&&void 0!==u.start&&(i=i.substring(0,u.start)+i.substring(u.start+1))}else if((0,e.isPrintableKey)(r)){var h=String.fromCharCode(r);i+=h=t.shiftKey?h.toUpperCase():h.toLowerCase()}}!i&&(n=this.input.getAttribute("placeholder"))&&(i=n);var o=this.measureString(i)+4;o!==this.currentWidth&&(this.currentWidth=o,this.input.style.width="".concat(o,"px"))}}},{key:"destroy",value:function(){this.input.removeEventListener("blur",this.eventHandler),this.input.removeEventListener("input",this.eventHandler),this.input.removeEventListener("keyup",this.eventHandler),this.input.removeEventListener("keydown",this.eventHandler),this.input=null}},{key:"init",value:function(){this.checkAndSet(),this.eventHandler=this.checkAndSet.bind(this),this.input.addEventListener("blur",this.eventHandler),this.input.addEventListener("input",this.eventHandler),this.input.addEventListener("keyup",this.eventHandler),this.input.addEventListener("keydown",this.eventHandler)}}]),i}();exports.default=s; | ||
},{"./autocomplete-helpers":"MBeS"}],"c8cM":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0,require("./closest-polyfill");var e=i(require("./autogrow")),t=require("./autocomplete-helpers");function i(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var i=0;i<t.length;i++){var s=t[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function l(e,t,i){return t&&n(e.prototype,t),i&&n(e,i),e}var r=0,o={name:"",source:"",sourceMapping:{},alsoSearchIn:[],delay:100,minLength:1,maxResults:9999,showAllControl:!1,confirmOnBlur:!0,multiple:!1,autoGrow:!1,maxItems:9999,multipleSeparator:",",deleteOnBackspace:!1,asyncQueryParam:"q",asyncMaxResultsParam:"limit",placeholder:"",noResultsText:"No results",cssNameSpace:"aria-autocomplete",listClassName:"",inputClassName:"",wrapperClassName:"",srDeleteText:"delete",srDeletedText:"deleted",srShowAllText:"Show all",srSelectedText:"selected",srListLabelText:"Search suggestions",srAssistiveText:"When results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.",srResultsText:function(e){return"".concat(e," ").concat(1===e?"result":"results"," available.")},onSearch:void 0,onAsyncPrep:void 0,onAsyncSuccess:void 0,onResponse:void 0,onItemRender:void 0,onConfirm:void 0,onDelete:void 0,onReady:void 0,onClose:void 0,onOpen:void 0},a=function(){function i(e,t){if(s(this,i),e){if(e.ariaAutocomplete&&e.ariaAutocomplete.open)return{api:e.ariaAutocomplete};this.options,this.element,this.elementIsInput,this.elementIsSelect,this.list,this.input,this.wrapper,this.showAll,this.srAnnouncements,this.ids,this.xhr,this.term,this.async,this.source,this.menuOpen,this.multiple,this.selected,this.disabled,this.autoGrow,this.filtering,this.cssNameSpace,this.forceShowAll,this.filteredSource,this.currentListHtml,this.inputPollingValue,this.currentSelectedIndex,this.documentClick,this.documentClickBound,this.filterTimer,this.pollingTimer,this.announcementTimer,this.componentBlurTimer,this.elementChangeEventTimer,this.AutoGrowInput,this.init(e,t)}}return l(i,[{key:"triggerOptionCallback",value:function(e,t,i){if(i=void 0===i?this.api:i,"function"==typeof this.options[e])return this.options[e].apply(i,t)}},{key:"show",value:function(e){if(void 0!==e){var i="".concat(this.cssNameSpace,"--hide hide hidden");return(0,t.removeClass)(e,i),e.removeAttribute("hidden")}if(this.input.setAttribute("aria-expanded","true"),this.showAll){var s=(!!this.forceShowAll).toString();this.showAll.setAttribute("aria-expanded",s)}this.menuOpen||(this.show(this.list),this.menuOpen=!0,this.triggerOptionCallback("onOpen",[this.list]),this.documentClickBound||(this.documentClickBound=!0,document.addEventListener("click",this.documentClick)))}},{key:"hide",value:function(e){if(void 0!==e)return(0,t.addClass)(e,"".concat(this.cssNameSpace,"--hide hide hidden")),e.setAttribute("hidden","hidden");this.currentSelectedIndex=-1,this.input.setAttribute("aria-expanded","false"),this.showAll&&this.showAll.setAttribute("aria-expanded","false"),this.menuOpen&&(this.hide(this.list),this.menuOpen=!1,this.triggerOptionCallback("onClose",[this.list]))}},{key:"enable",value:function(){if(this.disabled){this.disabled=!1,this.input.disabled=!1;var e=this.cssNameSpace;(0,t.removeClass)(this.input,"".concat(e,"__input--disabled disabled")),(0,t.removeClass)(this.wrapper,"".concat(e,"__wrapper--disabled disabled")),this.showAll&&(this.showAll.setAttribute("tabindex","0"),(0,t.removeClass)(this.showAll,"".concat(e,"__show-all--disabled disabled")))}}},{key:"disable",value:function(){if(!this.disabled){this.disabled=!0,this.input.disabled=!0;var e=this.cssNameSpace;(0,t.addClass)(this.input,"".concat(e,"__input--disabled disabled")),(0,t.addClass)(this.wrapper,"".concat(e,"__wrapper--disabled disabled")),this.showAll&&(this.showAll.setAttribute("tabindex","-1"),(0,t.addClass)(this.showAll,"".concat(e,"__show-all--disabled disabled")))}}},{key:"triggerAutoGrow",value:function(){this.autoGrow&&this.AutoGrowInput&&this.AutoGrowInput.trigger()}},{key:"setInputValue",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.input.value=this.term=e,t&&(this.inputPollingValue=e)}},{key:"indexOfQueryIn",value:function(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.input.value,s=arguments.length>2?arguments[2]:void 0;if(i=(0,t.trimString)(i).toLowerCase()){s=s||"label";for(var n=0,l=e.length;n<l;n+=1)if((0,t.trimString)(e[n][s]).toLowerCase()===i)return n}return-1}},{key:"announce",value:function(e,t){var i=this;if(e&&this.srAnnouncements){if(0===t)return this.srAnnouncements.textContent=e;t="number"==typeof t?t:400,this.announcementTimer&&clearTimeout(this.announcementTimer),this.announcementTimer=setTimeout(function(){i.srAnnouncements.textContent=e},t)}}},{key:"isSelectedElem",value:function(e){return this.multiple&&e[t.SELECTED_OPTION]&&(0,t.hasClass)(e,"".concat(this.cssNameSpace,"__selected"))}},{key:"getSelectedElems",value:function(){for(var e=this.wrapper.childNodes,t=[],i=0,s=e.length;i<s;i+=1)this.isSelectedElem(e[i])&&t.push(e[i]);return t}},{key:"removeEntryFromSelected",value:function(e){var i=this.selected.indexOf(e);if(-1===i)for(var s=0,n=this.selected.length;s<n;s+=1)if(this.selected[s].value===e.value){i=s;break}if(i>-1&&this.selected[i]){var l=(0,t.mergeObjects)(this.selected[i]),r=l.label;(0,t.setElementState)(l.element,!1,this),this.selected.splice(i,1),this.triggerOptionCallback("onDelete",[l]),this.buildMultiSelected(),this.announce("".concat(r," ").concat(this.options.srDeletedText),0)}}},{key:"buildMultiSelected",value:function(){if(this.multiple){this.multiple&&this.selected.length>=this.options.maxItems?this.disable():this.enable();var e=this.getSelectedElems();if(this.selected.length||e.length){for(var i=[],s=e.length;s--;){for(var n=e[s][t.SELECTED_OPTION],l=this.selected.length,r=!1;l--;){var o=this.selected[l];if(o===n||o.value===n.value){r=!0;break}}r?i.push(e[s]):this.wrapper.removeChild(e[s])}for(var a=this.options.srDeleteText,c=document.createDocumentFragment(),h="".concat(this.cssNameSpace,"__selected"),u=0,d=this.selected.length;u<d;u+=1){for(var p=this.selected[u],m=i.length,f=!1;m--;){var v=i[m][t.SELECTED_OPTION];if(v===p||v.value===p.value){f=!0;break}}if(!f){var g=p.label,S=(0,t.htmlToElement)('<span role="button" class="'.concat(h,'" ')+'tabindex="0" aria-label="'.concat(a," ").concat(g,'">')+"".concat(g,"</span>"));S[t.SELECTED_OPTION]=p,c.appendChild(S)}}c.childNodes&&c.childNodes.length&&this.wrapper.insertBefore(c,this.list);for(var y=[],b=this.getSelectedElems(),A=0,w=b.length;A<w;A+=1){var E="".concat(this.ids.OPTION_SELECTED,"-").concat(A);b[A].setAttribute("id",E),y.push(E)}if(y.push(this.ids.LIST),this.input.setAttribute("aria-owns",y.join(" ")),this.autoGrow&&this.options.placeholder){var T=this.selected.length?"":this.options.placeholder;this.input.setAttribute("placeholder",T)}}}}},{key:"setInputDescription",value:function(){var e=this.input.getAttribute("aria-describedby"),i=(0,t.trimString)(e||""),s=i.replace(this.ids.SR_ASSISTANCE,"");0===this.input.value.length&&(s=s+" "+this.ids.SR_ASSISTANCE),(s=(0,t.trimString)(s))?s!==i&&this.input.setAttribute("aria-describedby",s):e&&this.input.removeAttribute("aria-describedby")}},{key:"resetOptionAttributes",value:function(){for(var e=this.cssNameSpace,i=this.list.childNodes,s=i.length;s--;)(0,t.removeClass)(i[s],"".concat(e,"__option--focused focused focus")),i[s].setAttribute("aria-selected","false")}},{key:"setOptionFocus",value:function(e,i){this.resetOptionAttributes();var s=this.list.childNodes;if(i<0||!s||!s.length)return this.currentSelectedIndex=-1,void(e&&e.target!==this.input&&this.input.focus());if(i>=s.length)return this.currentSelectedIndex=s.length-1,void this.setOptionFocus(e,this.currentSelectedIndex);var n=s[i];if(n&&"string"==typeof n.getAttribute("tabindex")){this.currentSelectedIndex=i;var l="".concat(this.cssNameSpace,"__option--focused focused focus");return(0,t.addClass)(n,l),n.setAttribute("aria-selected","true"),void n.focus()}this.currentSelectedIndex=-1}},{key:"setSourceElementValues",value:function(){for(var e=[],i=0,s=this.selected.length;i<s;i+=1){var n=this.selected[i];e.push(n.value),(0,t.setElementState)(n.element,!0,this)}if(this.elementIsInput){var l=e.join(this.options.multipleSeparator);l!==this.element.value&&(this.element.value=l,(0,t.dispatchEvent)(this.element,"change"))}!this.selected.length&&this.elementIsSelect&&(this.element.value="")}},{key:"handleOptionSelect",value:function(e,i){var s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!("number"!=typeof i||i<0||this.multiple&&this.selected.length>=this.options.maxItems)&&this.filteredSource.length&&this.filteredSource[i]){for(var n=(0,t.mergeObjects)(this.filteredSource[i]),l=this.selected.length,r=!1;l--;)if(this.selected[l].value===n.value){r=!0;break}this.setInputValue(this.multiple?"":n.label,!0),this.triggerAutoGrow(),r||this.multiple||(this.selected=[]),r||(this.selected.push(n),this.setSourceElementValues(),this.buildMultiSelected()),this.triggerOptionCallback("onConfirm",[n]),this.announce("".concat(n.label," ").concat(this.options.srSelectedText),0),this.disabled||!1===s||this.input.focus(),this.hide()}}},{key:"removeSelectedFromResults",value:function(e){if(!this.multiple||!this.selected.length)return e;var t=[];e:for(var i=0,s=e.length;i<s;i+=1){for(var n=this.selected,l=e[i],r=0,o=n.length;r<o;r+=1){if(l.label===n[r].label&&l.value===n[r].value)continue e}t.push(l)}return t}},{key:"setListOptions",value:function(e){var i=[],s=this.options.sourceMapping,n=this.removeSelectedFromResults(e),l=this.triggerOptionCallback("onResponse",n);this.filteredSource=l?(0,t.processSourceArray)(l,s):n;for(var r,o=this.ids.OPTION,a=this.cssNameSpace,c=this.filteredSource.length,h="function"==typeof this.options.onItemRender,u=this.forceShowAll?9999:this.options.maxResults,d=0;d<c&&d<u;d+=1){var p=this.filteredSource[d],m=h&&this.triggerOptionCallback("onItemRender",[p])||p.label;i.push('<li tabindex="-1" aria-selected="false" role="option" class="'.concat(a,'__option" ')+'id="'.concat(o,"--").concat(d,'" aria-posinset="').concat(d+1,'" ')+'aria-setsize="'.concat(c,'">').concat(m,"</li>"))}i.length?((0,t.addClass)(this.list,"".concat(a,"__list--has-results")),(0,t.removeClass)(this.list,"".concat(a,"__list--no-results"))):((0,t.removeClass)(this.list,"".concat(a,"__list--has-results")),(0,t.addClass)(this.list,"".concat(a,"__list--no-results")));var f=this.options.noResultsText;if(!i.length&&"string"==typeof f&&f.length){r=f;var v="".concat(a,"__option");i.push('<li class="'.concat(v," ").concat(v,'--no-results">').concat(f,"</li>"))}this.cancelFilterPrep(),r||(r=this.triggerOptionCallback("srResultsText",[c])),this.announce(r);var g=i.join("");if(this.currentListHtml!==g?(this.currentListHtml=g,this.list.innerHTML=g):this.resetOptionAttributes(),!i.length)return this.hide(),void(this.forceShowAll=!1);this.show(),this.forceShowAll=!1}},{key:"handleAsync",value:function(e){var i=this,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.xhr&&this.xhr.abort();var n=new XMLHttpRequest,l=encodeURIComponent,r=this.forceShowAll,o=r||s,a=s?null:this.api,c=this.multiple?this.selected.length:0,h=/\?/.test(this.source)?"&":"?",u=this.source+h+"".concat(l(this.options.asyncQueryParam),"=").concat(l(e),"&")+"".concat(l(this.options.asyncMaxResultsParam),"=")+"".concat(o?9999:c+this.options.maxResults);u=this.triggerOptionCallback("onAsyncPrep",[u],a)||u,n.open("GET",u),n.onload=function(){if(n.readyState===n.DONE&&200===n.status){i.forceShowAll=r;var l=i.triggerOptionCallback("onAsyncSuccess",[e,n],a),o=i.options.sourceMapping,c=l||n.responseText,h=(0,t.processSourceArray)(c,o,!1);s?(i.prepSelectedFromArray(h),i.setInputStartingStates(!1)):i.setListOptions(h)}},s||(this.xhr=n),n.send()}},{key:"filter",value:function(e){var i=this;if("string"==typeof e){var s=this.forceShowAll,n=this.triggerOptionCallback("onSearch",[e]);if(s||"string"!=typeof n||(e=n),this.term=this.inputPollingValue=e,this.async)return this.handleAsync(e),void(this.forceShowAll=!1);if("function"!=typeof this.source){e||(s=!0);var l=[];if(this.source&&this.source.length){var r=[t.CLEANED_LABEL];if(!s){e=(0,t.cleanString)(e,!0);var o=this.options.alsoSearchIn;Array.isArray(o)&&o.length&&(r=(0,t.removeDuplicatesAndLabel)(r.concat(o)))}for(var a=0,c=this.source.length;a<c;a+=1){var h=this.source[a];(s||(0,t.searchVarPropsFor)(h,r,e))&&l.push(h)}}this.setListOptions(l)}else this.source.call(this.api,this.term,function(e){var s=i.options.sourceMapping,n=(0,t.processSourceArray)(e,s);i.setListOptions(n)})}else this.cancelFilterPrep()}},{key:"cancelFilterPrep",value:function(){this.filterTimer&&clearTimeout(this.filterTimer);var e=this.cssNameSpace;(0,t.removeClass)(this.wrapper,"".concat(e,"__wrapper--loading loading")),(0,t.removeClass)(this.input,"".concat(e,"__input--loading loading")),this.filtering=!1}},{key:"filterPrep",value:function(e){var i=this,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],l=this.forceShowAll,r=l||n?0:this.options.delay;this.cancelFilterPrep(),this.filtering=!0,this.filterTimer=setTimeout(function(){var n=i.input.value;if((l||""===n||s&&!i.multiple&&i.selected.length&&(0,t.trimString)(i.selected[0].label)===(0,t.trimString)(n))&&(n=""),i.setInputDescription(),i.inputPollingValue=n,!l&&n.length<i.options.minLength)i.hide();else{var r;try{r=e&&"keydown"===e.type&&(e.altKey||e.ctrlKey||e.metaKey)}catch(e){}var o=""!==n&&n===i.term;if(!o||o&&!i.menuOpen&&!r){var a=i.cssNameSpace;(0,t.addClass)(i.wrapper,"".concat(a,"__wrapper--loading loading")),(0,t.addClass)(i.input,"".concat(a,"__input--loading loading")),i.currentSelectedIndex=-1,i.filter(n)}}},r)}},{key:"filterPrepShowAll",value:function(e){var t=this;this.disabled||(this.showAllPrepTimer&&clearTimeout(this.showAllPrepTimer),this.showAllPrepTimer=setTimeout(function(){t.componentBlurTimer&&clearTimeout(t.componentBlurTimer),e.preventDefault(),t.forceShowAll=!0,t.filterPrep(e,!1,!0)}))}},{key:"handleComponentBlur",value:function(e){var i=this,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.componentBlurTimer&&clearTimeout(this.componentBlurTimer);var n=s?0:100;this.componentBlurTimer=setTimeout(function(){var e=document.activeElement;if(s||!e||i.showAll&&i.showAll===e||e[t.SELECTED_OPTION]||!i.wrapper.contains(e)){i.xhr&&i.xhr.abort();var n=i.indexOfQueryIn.bind(i);if(!s&&i.options.confirmOnBlur&&i.menuOpen){var l=i.currentSelectedIndex;"number"==typeof l&&-1!==l||(l=n(i.filteredSource)),i.handleOptionSelect({},l,!1)}if(i.cancelFilterPrep(),i.hide(),!i.multiple&&-1===n(i.selected))(i.elementIsInput||i.elementIsSelect)&&""!==i.element.value&&(i.element.value="",(0,t.dispatchEvent)(i.element,"change")),i.selected.length&&i.removeEntryFromSelected(i.selected[0]),i.setInputValue("",!0);i.multiple&&i.setInputValue("",!0),i.triggerAutoGrow(),i.documentClickBound&&(i.documentClickBound=!1,document.removeEventListener("click",i.documentClick))}},n)}},{key:"handleEnterKey",value:function(e){if(this.isSelectedElem(e.target)){var i=e.target[t.SELECTED_OPTION];return this.removeEntryFromSelected(i)}this.disabled||(this.showAll&&e.target===this.showAll?this.filterPrepShowAll(e):(this.menuOpen&&(e.preventDefault(),this.currentSelectedIndex>-1&&this.handleOptionSelect(e,this.currentSelectedIndex)),e.target===this.input&&this.filterPrep(e,!1,!0)))}},{key:"handleDownArrowKey",value:function(e){if(e.preventDefault(),this.menuOpen||(this.forceShowAll=this.options.minLength<1,(this.forceShowAll||this.input.value.length>=this.options.minLength)&&this.filterPrep(e)),this.menuOpen&&!this.filtering){var t=this.currentSelectedIndex;"number"!=typeof t||t<0?this.setOptionFocus(e,0):this.setOptionFocus(e,t+1)}}},{key:"handleUpArrowKey",value:function(e){e.preventDefault(),!this.disabled&&this.menuOpen&&"number"==typeof this.currentSelectedIndex&&this.setOptionFocus(e,this.currentSelectedIndex-1)}},{key:"handleKeyDownDefault",value:function(e){var i=e.target===this.input;if(32===e.keyCode&&!i)return e.preventDefault(),this.handleEnterKey(e);if(!this.disabled){var s=this.selected&&this.selected.length;if(this.options.deleteOnBackspace&&""===this.input.value&&8===e.keyCode&&s&&i&&this.multiple)this.removeEntryFromSelected(this.selected[s-1]);else{var n=(0,t.isPrintableKey)(e.keyCode),l=!i&&n;l&&this.input.focus(),(l||i&&n)&&this.filterPrep(e)}}}},{key:"prepKeyDown",value:function(e){switch(e.keyCode){case 13:this.handleEnterKey(e);break;case 27:this.handleComponentBlur(e,!0);break;case 38:this.handleUpArrowKey(e);break;case 40:this.handleDownArrowKey(e);break;default:this.handleKeyDownDefault(e)}}},{key:"cancelPolling",value:function(){this.pollingTimer&&clearTimeout(this.pollingTimer)}},{key:"startPolling",value:function(){var e=this;this.filtering||this.input.value===this.inputPollingValue||this.filterPrep({}),this.pollingTimer=setTimeout(function(){e.startPolling()},200)}},{key:"bindEvents",value:function(){var i=this;this.wrapper.addEventListener("focusout",function(e){i.handleComponentBlur(e,!1)}),this.wrapper.addEventListener("focusin",function(e){i.list.contains(e.target)||(i.currentSelectedIndex=-1)}),this.wrapper.addEventListener("keydown",function(e){i.prepKeyDown(e)}),this.wrapper.addEventListener("click",function(e){if(e.target!==i.wrapper){if(i.isSelectedElem(e.target)){var s=e.target[t.SELECTED_OPTION];i.removeEntryFromSelected(s)}}else i.input.focus()});var s="".concat(this.cssNameSpace,"__wrapper--focused focused focus"),n="".concat(this.cssNameSpace,"__input--focused focused focus");this.input.addEventListener("blur",function(){(0,t.removeClass)(i.wrapper,s),(0,t.removeClass)(i.input,n),i.cancelPolling()}),this.input.addEventListener("input",function(e){i.filterPrep(e)}),this.input.addEventListener("click",function(e){!i.menuOpen&&i.input.value.length>=i.options.minLength&&i.filterPrep(e,!0)}),this.input.addEventListener("focusin",function(){(0,t.addClass)(i.wrapper,s),(0,t.addClass)(i.input,n),i.startPolling(),i.disabled||i.menuOpen||i.filterPrep(event,!0)}),this.showAll&&this.showAll.addEventListener("click",function(e){i.filterPrepShowAll(e)}),this.list.addEventListener("mouseenter",function(e){i.resetOptionAttributes()}),this.list.addEventListener("click",function(e){if(e.target!==i.list){var t=i.list.childNodes;if(t.length){var s=[].indexOf.call(t,e.target);i.handleOptionSelect(e,s)}}}),this.autoGrow&&(this.AutoGrowInput=new e.default(this.input))}},{key:"prepListSourceCheckboxes",value:function(){this.multiple=!0,this.source=[];for(var e=this.element.querySelectorAll('input[type="checkbox"]'),i=0,s=e.length;i<s;i+=1){var n=e[i];if(n.value){var l={element:n,value:n.value},r=n.closest("label");!r&&n.id&&(r=document.querySelector('[for="'+n.id+'"]')),r&&(l.label=r.textContent),l.label||(l.label=l.value),l[t.CLEANED_LABEL]=(0,t.cleanString)(l.label),this.source.push(l),n.checked&&this.selected.push(l)}}}},{key:"prepListSourceDdl",value:function(){this.multiple=this.element.multiple,this.source=[];for(var e=this.element.querySelectorAll("option"),i=0,s=e.length;i<s;i+=1){var n=e[i];if(n.value){var l={element:n,value:n.value,label:n.textContent};l[t.CLEANED_LABEL]=(0,t.cleanString)(l.label),this.source.push(l),n.selected&&this.selected.push(l)}}}},{key:"prepSelectedFromArray",value:function(e){var t=this.elementIsInput&&this.element.value;if(t&&e&&e.length)for(var i=this.options.multiple,s=this.options.multipleSeparator,n=i?t.split(s):[t],l=0,r=n.length;l<r;l+=1){var o=n[l],a=this.indexOfQueryIn;if(!(a(this.selected,o,"value")>-1)){var c=a(e,o,"value");c>-1&&this.selected.push(e[c])}}}},{key:"prepListSourceArray",value:function(){var e=this.options.sourceMapping;this.source=(0,t.processSourceArray)(this.source,e),this.prepSelectedFromArray(this.source)}},{key:"prepListSourceAsync",value:function(){this.async=!0,this.elementIsInput&&this.element.value&&this.handleAsync(this.element.value,!0)}},{key:"prepListSourceFunction",value:function(){var e=this;this.elementIsInput&&this.element.value&&this.source.call(void 0,this.element.value,function(i){e.prepSelectedFromArray((0,t.processSourceArray)(i,e.options.sourceMapping)),e.setInputStartingStates(!1)})}},{key:"prepListSource",value:function(){return"function"==typeof this.source?this.prepListSourceFunction():"string"==typeof this.source&&this.source.length?this.prepListSourceAsync():Array.isArray(this.source)&&this.source.length?this.prepListSourceArray():this.elementIsSelect?this.prepListSourceDdl():void(this.element.querySelector('input[type="checkbox"]')&&this.prepListSourceCheckboxes())}},{key:"setInputStartingStates",value:function(){if(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]){if(this.ids.ELEMENT){var e=document.querySelector('[for="'+this.ids.ELEMENT+'"]');e&&(e.ariaAutocompleteOriginalFor=this.ids.ELEMENT,e.setAttribute("for",this.ids.INPUT))}var t=this.element.getAttribute("aria-describedby");t&&this.input.setAttribute("aria-describedby",t);var i=this.element.getAttribute("aria-labelledby");i&&this.input.setAttribute("aria-labelledby",i)}this.selected.length&&(this.multiple?this.buildMultiSelected():(this.setInputValue(this.selected[0].label||"",!0),this.triggerAutoGrow())),this.setInputDescription(),this.element.disabled&&this.disable()}},{key:"setHtml",value:function(){var e=this.options,t=this.cssNameSpace,i=e.wrapperClassName?" ".concat(e.wrapperClassName):"",s=['<div id="'.concat(this.ids.WRAPPER,'" class="').concat(t,"__wrapper").concat(i,'">')],n=e.name?" ".concat(e.name):"",l=e.inputClassName?" ".concat(e.inputClassName):"";s.push('<input type="text" autocomplete="off" aria-expanded="false" aria-autocomplete="list" '+'role="combobox" id="'.concat(this.ids.INPUT,'" placeholder="').concat(e.placeholder,'" ')+'aria-owns="'.concat(this.ids.LIST,'" aria-placeholder="').concat(e.placeholder,'" ')+'class="'.concat(t,"__input").concat(l,'"').concat(n," />")),e.showAllControl&&s.push('<span role="button" aria-label="'.concat(e.srShowAllText,'" class="').concat(t,'__show-all" ')+'tabindex="0" id="'.concat(this.ids.BUTTON,'" aria-expanded="false"></span>'));var r=e.srListLabelText,o=e.listClassName?" ".concat(e.listClassName):"",a=r?' aria-label="'.concat(r,'"'):"";s.push('<ul id="'.concat(this.ids.LIST,'" class="').concat(t,"__list").concat(o,'" role="listbox" ')+'hidden="hidden"'.concat(a,"></ul>")),s.push('<span class="sr-only '.concat(t,"__sr-only ").concat(t,'__sr-assistance" ')+'id="'.concat(this.ids.SR_ASSISTANCE,'">').concat(e.srAssistiveText,"</span>")),s.push('<span class="sr-only '.concat(t,"__sr-only ").concat(t,'__sr-announcements" ')+'id="'.concat(this.ids.SR_ANNOUNCEMENTS,'" aria-live="polite" aria-atomic="true"></span>')),s.push("</div>"),this.element.insertAdjacentHTML("afterend",s.join(""))}},{key:"generateApi",value:function(){var e=this;this.api={open:function(){return e.show.call(e)},close:function(){return e.hide.call(e)},filter:function(t){return e.filter.call(t)}};for(var t=["options","destroy","enable","disable","input","wrapper","list","selected"],i=function(i,s){e.api[t[i]]="function"==typeof e[t[i]]?function(){return e[t[i]].call(e)}:e[t[i]]},s=0,n=t.length;s<n;s+=1)i(s);this.element.ariaAutocomplete=this.api}},{key:"destroy",value:function(){var e=document.querySelector('[for="'+this.ids.INPUT+'"]');for(var t in e&&e.ariaAutocompleteOriginalFor&&(e.setAttribute("for",e.ariaAutocompleteOriginalFor),delete e.ariaAutocompleteOriginalFor),this.documentClickBound&&document.removeEventListener("click",this.documentClick),this.autoGrow&&this.AutoGrowInput&&this.AutoGrowInput.destroy(),this.element.parentNode.removeChild(this.wrapper),delete this.element.ariaAutocomplete,this.show(this.element),this)this.hasOwnProperty(t)&&(this[t]=null)}},{key:"init",value:function(e,i){r+=1,this.ids={},this.ids.ELEMENT=e.id,this.ids.PREFIX="".concat(e.id||"","aria-autocomplete-").concat(r),this.ids.LIST="".concat(this.ids.PREFIX,"-list"),this.ids.INPUT="".concat(this.ids.PREFIX,"-input"),this.ids.BUTTON="".concat(this.ids.PREFIX,"-button"),this.ids.OPTION="".concat(this.ids.PREFIX,"-option"),this.ids.WRAPPER="".concat(this.ids.PREFIX,"-wrapper"),this.ids.OPTION_SELECTED="".concat(this.ids.OPTION,"-selected"),this.ids.SR_ASSISTANCE="".concat(this.ids.PREFIX,"-sr-assistance"),this.ids.SR_ANNOUNCEMENTS="".concat(this.ids.PREFIX,"-sr-announcements"),this.selected=[],this.element=e,this.elementIsInput="INPUT"===e.nodeName,this.elementIsSelect="SELECT"===e.nodeName,this.options=(0,t.mergeObjects)(o,i),this.source=this.options.source,this.multiple=this.options.multiple,this.autoGrow=this.options.autoGrow,this.cssNameSpace=this.options.cssNameSpace,this.documentClick=this.handleComponentBlur.bind(this),this.setHtml(),this.list=document.getElementById(this.ids.LIST),this.input=document.getElementById(this.ids.INPUT),this.wrapper=document.getElementById(this.ids.WRAPPER),this.showAll=document.getElementById(this.ids.BUTTON),this.srAnnouncements=document.getElementById(this.ids.SR_ANNOUNCEMENTS),this.prepListSource();var s="";this.options.showAllControl&&(s+=" ".concat(this.cssNameSpace,"__wrapper--show-all")),this.autoGrow&&(s+=" ".concat(this.cssNameSpace,"__wrapper--autogrow")),this.multiple&&(s+=" ".concat(this.cssNameSpace,"__wrapper--multiple")),s&&(0,t.addClass)(this.wrapper,s),this.hide(this.list),this.hide(this.element),this.generateApi(),this.setInputStartingStates(),this.bindEvents(),this.triggerOptionCallback("onReady",[this.wrapper])}}]),i}();window.AriaAutocomplete=function(e,t){return new a(e,t).api};var c=function(e,t){return new a(e,t).api};exports.default=c; | ||
},{"./closest-polyfill":"kTsq","./autogrow":"KnPF","./autocomplete-helpers":"MBeS"}]},{},["c8cM"], null) | ||
//# sourceMappingURL=/aria-autocomplete.min.js.map |
{ | ||
"name": "aria-autocomplete", | ||
"version": "1.0.0-beta.1", | ||
"description": "Accessible, extensible, dependency-free JavaScript autocomplete", | ||
"version": "1.0.0-beta.2", | ||
"description": "Accessible, extensible, dependency-free JavaScript autocomplete with multi-select", | ||
"main": "src/aria-autocomplete.js", | ||
@@ -18,5 +18,14 @@ "scripts": { | ||
"typeahead", | ||
"autosuggest", | ||
"a11y", | ||
"ARIA", | ||
"WAI-ARIA", | ||
"accessible", | ||
"accessibility" | ||
"accessibility", | ||
"dropdown", | ||
"enhanced input", | ||
"select", | ||
"combobox", | ||
"multiselect", | ||
"multiple selection" | ||
], | ||
@@ -23,0 +32,0 @@ "author": "Leon Slater (https://www.mynamesleon.com)", |
# Aria Autocomplete | ||
[![npm version](https://img.shields.io/npm/v/aria-autocomplete.svg)](http://npm.im/aria-autocomplete) | ||
[![gzip size](http://img.badgesize.io/https://unpkg.com/aria-autocomplete/dist/aria-autocomplete.min.js?compression=gzip)](https://unpkg.com/aria-autocomplete/dist/aria-autocomplete.min.js) | ||
Accessible, extensible, dependency-free autocomplete with multi-select. | ||
I've used a lot of autocomplete plugins, but the combination of **accessibility**, **performance**, and **functionality** that I needed wasn't out there. So I've tried to build on the [brilliant accessibility of GOV.UK's accessible-autocomplete](https://accessibility.blog.gov.uk/2018/05/15/what-we-learned-from-getting-our-autocomplete-tested-for-accessibility/), but with more functionality and (in my testing) better performance. | ||
I've used a lot of autocomplete plugins, but the combination of **accessibility**, **performance**, and **functionality** that I needed wasn't out there. So I've written this from the ground up for that purpose, building on the [brilliant accessibility of GOV.UK's accessible-autocomplete](https://accessibility.blog.gov.uk/2018/05/15/what-we-learned-from-getting-our-autocomplete-tested-for-accessibility/) - with more functionality, a smaller file size, and (in my testing) better performance. | ||
@@ -15,3 +18,3 @@ [Try out the examples](https://mynamesleon.github.io/aria-autocomplete/examples/) | ||
- **accessibility**: Use of ARIA attributes, custom screen reader announcements, and testing with assistive technologies | ||
- **compatibility**: Broad browser and device support (e.g. IE9+) | ||
- **compatibility**: Broad browser and device support (IE9+) | ||
- **starting values**: Automatic selection based on starting values, including for checkboxes, `select` options, and for async handling. | ||
@@ -55,5 +58,11 @@ | ||
## Performance | ||
I wrote this from the ground up partly because I needed an autocomplete with better performance than others I'd tried. I've optimised the JavaScript where I can, but it's the actual list _rendering_ that's a hit to performance. In my testing, modern browsers can render huge lists (1000+ items) just fine (on my laptop, averaging 40ms in Chrome, and under 20ms in Firefox). | ||
As we all know however, Internet Explorer _sucks_. If you need to support IE11 (or earlier), I suggest either setting the `maxResults` option to 200 or less, or using a sensible combination for the `delay` and `minLength` options. Testing on my laptop, the list rendering in IE11 would take on average: 55ms for 250 items, 300ms for 650 items, and over 600ms for 1000 items. | ||
## API Documentation | ||
At its core, the autocomplete requires only an element, and a source. When the element is an input, its value will be set using the user's selection(s). If a source isn't provided however, and the element is either a `<select>`, or is an element with child checkboxes, those will be used to build up the source. | ||
At its core, the autocomplete requires only an element, and a `source`. When the element is an input, its value will be set using the user's selection(s). If a `source` option isn't provided however (is falsy, or an empty Array), and the element is either a `<select>`, or has child checkboxes, those will be used to build up the `source`. | ||
@@ -80,5 +89,5 @@ ```javascript | ||
* @description Give the autocomplete a name to be included in form submissions | ||
* (Instead of using this option, I would advise initialising the autocomplete | ||
* on an existing input that will be submitted; this approach is compatible | ||
* with the control in multiple mode) | ||
* (Instead of using this option, I would advise initialising the autocomplete on | ||
* an existing input that will be submitted, to also use any existing validation; | ||
* this approach is also compatible with the control in multiple mode) | ||
*/ | ||
@@ -102,2 +111,9 @@ name: '', | ||
/** | ||
* @type {String[]} | ||
* @description Additional properties to use when searching for a match. | ||
* `label` will always be used | ||
*/ | ||
alsoSearchIn: [], | ||
/** | ||
* @description Input delay after typing before running a search | ||
@@ -129,3 +145,2 @@ */ | ||
/** | ||
@@ -246,2 +261,8 @@ * @description Allow multiple items to be selected | ||
/** | ||
* @description Callback before a search is performed - receives the input value. | ||
* Can be used to alter the search value by returning a String | ||
*/ | ||
onSearch: query => query, | ||
/** | ||
* @description Callback before async call is made - receives the URL. | ||
@@ -265,6 +286,6 @@ * Can be used to format the endpoint URL by returning a String | ||
/** | ||
* @description Callback before a search is performed - receives the input value. | ||
* Can be used to alter the search value by returning a String | ||
* @description Callback when rendering items in the list. | ||
* Can be used to format the <li> content by returning a String | ||
*/ | ||
onSearch: query => query, | ||
onItemRender: itemData => itemData.label, | ||
@@ -300,1 +321,3 @@ /** | ||
``` | ||
Calling `new AriaAutocomplete(element, options);` returns the API object, which can also be accessed on the element via `element.ariaAutocomplete`. |
@@ -1,2 +0,2 @@ | ||
import { isPrintableKey, setCss, transferStyles } from './helpers'; | ||
import { isPrintableKey, setCss, transferStyles } from './autocomplete-helpers'; | ||
@@ -32,3 +32,3 @@ /** | ||
getInputSelection() { | ||
let result = {}; | ||
const result = {}; | ||
if ('selectionStart' in this.input) { | ||
@@ -39,4 +39,4 @@ result.start = this.input.selectionStart; | ||
this.input.focus(); | ||
let selection = document.selection.createRange(); | ||
let selectionLength = selection.text.length; | ||
const selection = document.selection.createRange(); | ||
const selectionLength = selection.text.length; | ||
selection.moveStart('character', -this.input.value.length); | ||
@@ -104,9 +104,9 @@ result.start = selection.text.length - selectionLength; | ||
if (event.type && event.type.toLowerCase() === 'keydown') { | ||
let keyCode = event.keyCode; | ||
let keyCodeIsDelete = keyCode === 46; | ||
let keyCodeIsBackspace = keyCode === 8; | ||
const keyCode = event.keyCode; | ||
const keyCodeIsDelete = keyCode === 46; | ||
const keyCodeIsBackspace = keyCode === 8; | ||
// delete or backspace | ||
if (keyCodeIsDelete || keyCodeIsBackspace) { | ||
let selection = this.getInputSelection(); | ||
const selection = this.getInputSelection(); | ||
if (selection.length) { | ||
@@ -129,5 +129,4 @@ value = | ||
else if (isPrintableKey(keyCode)) { | ||
let shift = event.shiftKey; | ||
let character = String.fromCharCode(keyCode); | ||
if (shift) { | ||
if (event.shiftKey) { | ||
character = character.toUpperCase(); | ||
@@ -146,3 +145,3 @@ } else { | ||
let width = this.measureString(value) + 4; | ||
const width = this.measureString(value) + 4; | ||
if (width !== this.currentWidth) { | ||
@@ -149,0 +148,0 @@ this.currentWidth = width; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
659913
4734
316