From 71596808dd866a39346c12241b685cf7d29989d8 Mon Sep 17 00:00:00 2001 From: Grzegorz Tomicki Date: Fri, 4 Mar 2022 14:10:26 +0100 Subject: [PATCH] perf: new functions, smaller builds --- dist/js/autocomplete.esm.js | 114 +++++++++++++++++--------------- dist/js/autocomplete.esm.js.map | 2 +- dist/js/autocomplete.esm.min.js | 2 +- dist/js/autocomplete.ie.min.js | 2 +- dist/js/autocomplete.js | 114 +++++++++++++++++--------------- dist/js/autocomplete.js.map | 2 +- dist/js/autocomplete.min.js | 2 +- dist/js/autocomplete.umd.js | 114 +++++++++++++++++--------------- dist/js/autocomplete.umd.js.map | 2 +- dist/js/autocomplete.umd.min.js | 2 +- docs/js/autocomplete.min.js | 2 +- docs/js/autocomplete.min.js.map | 2 +- sources/js/script.js | 111 +++++++++++++++---------------- sources/js/utils/function.js | 72 ++++++++++++++------ 14 files changed, 293 insertions(+), 250 deletions(-) diff --git a/dist/js/autocomplete.esm.js b/dist/js/autocomplete.esm.js index b0d47c5..35b24c0 100644 --- a/dist/js/autocomplete.esm.js +++ b/dist/js/autocomplete.esm.js @@ -3,17 +3,15 @@ const isPromise = value => Boolean(value && typeof value.then === "function"); const setAttributes = (el, object) => { for (let key in object) { if (key === "addClass") { - el.classList.add(object[key]); + classList(el, "add", object[key]); } else if (key === "removeClass") { - el.classList.remove(object[key]); + classList(el, "remove", object[key]); } else { el.setAttribute(key, object[key]); } } }; -const getFirstElement = element => element.firstElementChild || element; -const getFirstElementFromLiAndAddToInput = (element, root) => -root.value = getFirstElement(element).textContent.trim(); +const getFirstElement = element => (element.firstElementChild || element).textContent.trim(); const scrollResultsToTop = (resultList, resultWrap) => { resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight; }; @@ -33,16 +31,19 @@ const showBtnToClearData = function (clearButton, destroy) { clearButton = false; } if (!clearButton) return; - clearButton.classList.remove("hidden"); - clearButton.addEventListener("click", destroy); + classList(clearButton, "remove", "hidden"); + onEvent(clearButton, "click", destroy); }; +const classList = (element, action, className) => element.classList[action](className); const setAriaActivedescendant = (root, type) => { - root.setAttribute("aria-activedescendant", type || ""); + setAttributes(root, { + "aria-activedescendant": type || "" + }); }; const getClassGroupHeight = (outputUl, classGroup) => { - const allLi = document.querySelectorAll("#" + outputUl + " > li:not(." + classGroup + ")"); + const allLiElements = document.querySelectorAll("#" + outputUl + " > li:not(." + classGroup + ")"); let height = 0; - [].slice.call(allLi).map(el => height += el.offsetHeight); + [].slice.call(allLiElements).map(el => height += el.offsetHeight); return height; }; const followActiveElement = (target, outputUl, classGroup, resultList) => { @@ -74,6 +75,13 @@ const output = (root, resultList, outputUl, resultWrap, prefix) => { root.parentNode.insertBefore(resultWrap, root.nextSibling); }; const createElement = type => document.createElement(type); +const select = element => document.querySelector(element); +const onEvent = (element, action, callback) => { + element.addEventListener(action, callback); +}; +const offEvent = (element, action, callback) => { + element.removeEventListener(action, callback); +}; const keyCodes = { ESC: 27, @@ -111,8 +119,8 @@ class Autocomplete { this._initial = () => { this._clearbutton(); output(this._root, this._resultList, this._outputUl, this._resultWrap, this._prefix); - this._root.addEventListener("input", this._handleInput); - this._showAll && this._root.addEventListener("click", this._handleInput); + onEvent(this._root, "input", this._handleInput); + this._showAll && onEvent(this._root, "click", this._handleInput); this._onRender({ element: this._root, results: this._resultList @@ -145,7 +153,6 @@ class Autocomplete { }, delay); }; this._reset = () => { - var _this$_matches; setAttributes(this._root, { "aria-owns": this._id + "-list", "aria-expanded": "false", @@ -154,19 +161,16 @@ class Autocomplete { role: "combobox", removeClass: "auto-expanded" }); - this._resultWrap.classList.remove(this._isActive); - if (((_this$_matches = this._matches) == null ? void 0 : _this$_matches.length) == 0 && !this._toInput || this._showAll) { - this._resultList.innerHTML = ""; - } + classList(this._resultWrap, "remove", this._isActive); this._index = this._selectFirst ? 0 : -1; this._onClose(); }; this._searchItem = value => { this._value = value; this._onLoading(true); - showBtnToClearData(this._cBtn, this.destroy); + showBtnToClearData(this._clearBtn, this.destroy); if (value.length == 0 && this._clearButton) { - this._cBtn.classList.add("hidden"); + classList(this._clearBtn, "add", "hidden"); } if (this._characters > value.length && !this._showAll) { this._onLoading(); @@ -178,14 +182,14 @@ class Autocomplete { }).then(result => { const rootValueLength = this._root.value.length; const resultLength = result.length; - this._matches = Array.isArray(result) ? [...result] : JSON.parse(JSON.stringify(result)); + this._matches = Array.isArray(result) ? result : JSON.parse(JSON.stringify(result)); this._onLoading(); this._error(); if (resultLength == 0 && rootValueLength == 0) { - this._cBtn.classList.add("hidden"); + classList(this._clearBtn, "add", "hidden"); } if (resultLength == 0 && rootValueLength) { - this._root.classList.remove("auto-expanded"); + classList(this._root, "remove", "auto-expanded"); this._reset(); this._noResults({ element: this._root, @@ -204,21 +208,22 @@ class Autocomplete { }); }; this._onLoading = type => this._root.parentNode.classList[type ? "add" : "remove"](this._isLoading); - this._error = () => this._root.classList.remove(this._err); + this._error = () => classList(this._root, "remove", this._err); this._events = () => { - this._root.addEventListener("keydown", this._handleKeys); - this._root.addEventListener("click", this._handleShowItems); + onEvent(this._root, "keydown", this._handleKeys); + onEvent(this._root, "click", this._handleShowItems); ["mousemove", "click"].map(eventType => { - this._resultList.addEventListener(eventType, this._handleMouse); + onEvent(this._resultList, eventType, this._handleMouse); }); - document.addEventListener("click", this._handleDocClick); + onEvent(document, "click", this._handleDocClick); }; this._results = template => { setAttributes(this._root, { "aria-expanded": "true", addClass: this._prefix + "-expanded" }); - this._resultList.innerHTML = this._matches.length === 0 ? this._onResults({ + this._resultList.textContent = ""; + const dataResults = this._matches.length === 0 ? this._onResults({ currentValue: this._value, matches: 0, template @@ -227,7 +232,8 @@ class Autocomplete { matches: this._matches, classGroup: this._classGroup }); - this._resultWrap.classList.add(this._isActive); + this._resultList.insertAdjacentHTML("afterbegin", dataResults); + classList(this._resultWrap, "add", this._isActive); const checkIfClassGroupExist = this._classGroup ? ":not(." + this._classGroup + ")" : ""; this._itemsLi = document.querySelectorAll("#" + this._outputUl + " > li" + checkIfClassGroupExist); addAriaToAllLiElements(this._itemsLi); @@ -236,7 +242,7 @@ class Autocomplete { element: this._root, results: this._resultList }); - this._selectFirstEl(); + this._selectFirstElement(); scrollResultsToTop(this._resultList, this._resultWrap); }; this._handleDocClick = _ref3 => { @@ -253,8 +259,8 @@ class Autocomplete { return; } }; - this._selectFirstEl = () => { - this._remAria(document.querySelector("." + this._activeList)); + this._selectFirstElement = () => { + this._removeAria(select("." + this._activeList)); if (!this._selectFirst) { return; } @@ -275,14 +281,14 @@ class Autocomplete { setAriaActivedescendant(this._root, this._selectedOption + "-0"); }; this._handleShowItems = () => { - if (this._resultList.textContent.length > 0 && !this._resultWrap.classList.contains(this._isActive)) { + if (this._resultList.textContent.length > 0 && !classList(this._resultWrap, "contains", this._isActive)) { setAttributes(this._root, { "aria-expanded": "true", addClass: this._prefix + "-expanded" }); - this._resultWrap.classList.add(this._isActive); + classList(this._resultWrap, "add", this._isActive); scrollResultsToTop(this._resultList, this._resultWrap); - this._selectFirstEl(); + this._selectFirstElement(); this._onOpened({ type: "showItems", element: this._root, @@ -299,15 +305,15 @@ class Autocomplete { const targetClosest = target.closest("li"); const targetClosestRole = targetClosest == null ? void 0 : targetClosest.hasAttribute("role"); const activeClass = this._activeList; - const activeClassElement = document.querySelector("." + activeClass); + const activeClassElement = select("." + activeClass); if (!targetClosest || !targetClosestRole) { return; } if (type === "click") { this._getTextFromLi(targetClosest); } - if (type === "mousemove" && !targetClosest.classList.contains(activeClass)) { - this._remAria(activeClassElement); + if (type === "mousemove" && !classList(targetClosest, "contains", activeClass)) { + this._removeAria(activeClassElement); this._setAria(targetClosest); this._index = this._indexLiSelected(targetClosest); this._onSelected({ @@ -322,7 +328,7 @@ class Autocomplete { !this._disable && this._reset(); return; } - getFirstElementFromLiAndAddToInput(element, this._root); + this._root.value = getFirstElement(element); this._onSubmit({ index: this._index, element: this._root, @@ -330,10 +336,10 @@ class Autocomplete { results: this._resultList }); if (!this._disable) { - this._remAria(element); + this._removeAria(element); this._reset(); } - this._clearButton && this._cBtn.classList.remove("hidden"); + this._clearButton && classList(this._clearBtn, "remove", "hidden"); this._cacheAct("remove"); }; this._indexLiSelected = target => @@ -342,9 +348,9 @@ class Autocomplete { const { keyCode } = event; - const resultList = this._resultWrap.classList.contains(this._isActive); + const resultList = classList(this._resultWrap, "contains", this._isActive); const matchesLength = this._matches.length + 1; - this._selectedLi = document.querySelector("." + this._activeList); + this._selectedLi = select("." + this._activeList); switch (keyCode) { case keyCodes.UP: case keyCodes.DOWN: @@ -363,10 +369,10 @@ class Autocomplete { this._index = 0; } } - this._remAria(this._selectedLi); - if (matchesLength > 0 && this._index >= 0 && this._index < matchesLength - 1) { + this._removeAria(this._selectedLi); + if (this._index >= 0 && this._index < matchesLength - 1) { if (this._toInput && resultList) { - getFirstElementFromLiAndAddToInput(this._itemsLi[this._index], this._root); + this._root.value = getFirstElement(this._itemsLi[this._index]); } this._onSelected({ index: this._index, @@ -404,7 +410,7 @@ class Autocomplete { setAriaActivedescendant(this._root, selectedOption); followActiveElement(target, this._outputUl, this._classGroup, this._resultList); }; - this._remAria = element => { + this._removeAria = element => { if (!element) return; setAttributes(element, { id: "", @@ -414,25 +420,25 @@ class Autocomplete { }; this._clearbutton = () => { if (!this._clearButton) return; - setAttributes(this._cBtn, { + setAttributes(this._clearBtn, { class: this._prefix + "-clear hidden", type: "button", title: this._clearBtnAriLabel, "aria-label": this._clearBtnAriLabel }); - this._root.insertAdjacentElement("afterend", this._cBtn); + this._root.insertAdjacentElement("afterend", this._clearBtn); }; this.destroy = () => { - this._clearButton && this._cBtn.classList.add("hidden"); + this._clearButton && classList(this._clearBtn, "add", "hidden"); this._root.value = ""; this._root.focus(); this._resultList.textContent = ""; this._reset(); this._error(); this._onReset(this._root); - this._root.removeEventListener("keydown", this._handleKeys); - this._root.removeEventListener("click", this._handleShowItems); - document.removeEventListener("click", this._handleDocClick); + offEvent(this._root, "keydown", this._handleKeys); + offEvent(this._root, "click", this._handleShowItems); + offEvent(document, "click", this._handleDocClick); }; this._id = _element; this._root = document.getElementById(_element); @@ -477,7 +483,7 @@ class Autocomplete { this._timeout = null; this._resultWrap = createElement("div"); this._resultList = createElement("ul"); - this._cBtn = createElement("button"); + this._clearBtn = createElement("button"); this._initial(); } } diff --git a/dist/js/autocomplete.esm.js.map b/dist/js/autocomplete.esm.js.map index 8fdd381..1906df8 100644 --- a/dist/js/autocomplete.esm.js.map +++ b/dist/js/autocomplete.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"autocomplete.esm.js","sources":["../../sources/js/utils/function.js","../../sources/js/utils/keyCodes.js","../../sources/js/script.js"],"sourcesContent":["/**\r\n * Check is a Object\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isObject = (value) =>\r\n value && typeof value === \"object\" && value.constructor === Object;\r\n\r\n/**\r\n * Check if is a Promise\r\n * https://stackoverflow.com/a/53955664/10424385\r\n *\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isPromise = (value) => Boolean(value && typeof value.then === \"function\");\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n if (key === \"addClass\") {\r\n el.classList.add(object[key]);\r\n } else if (key === \"removeClass\") {\r\n el.classList.remove(object[key]);\r\n } else {\r\n el.setAttribute(key, object[key]);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Get first element from child\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {HTMLELement}\r\n */\r\nconst getFirstElement = (element) => element.firstElementChild || element;\r\n\r\n/**\r\n * Set data from li to input\r\n *\r\n * @param {String} element\r\n * @param {HTMLElement} root\r\n * @returns {String}\r\n */\r\nconst getFirstElementFromLiAndAddToInput = (element, root) =>\r\n // get first element from li and add to input\r\n (root.value = getFirstElement(element).textContent.trim());\r\n\r\n/**\r\n * Scroll to top result-list\r\n * @param {HTMLElement} resultList\r\n * @param {HTMLElement} resultWrap\r\n */\r\nconst scrollResultsToTop = (resultList, resultWrap) => {\r\n // if there is an overflow of ul element, after\r\n // opening we always move ul to the top of the results\r\n resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight;\r\n};\r\n\r\n/**\r\n * Adding role, tabindex, aria and call handleMouse\r\n *\r\n * @param {HTMLElement} itemsLi\r\n */\r\nconst addAriaToAllLiElements = (itemsLi) => {\r\n // add role to all li elements\r\n for (let i = 0; i < itemsLi.length; i++) {\r\n setAttributes(itemsLi[i], {\r\n role: \"option\",\r\n tabindex: \"-1\",\r\n \"aria-selected\": \"false\",\r\n \"aria-setsize\": itemsLi.length,\r\n \"aria-posinset\": i,\r\n });\r\n }\r\n};\r\n\r\n/**\r\n * Show btn to clear data\r\n *\r\n * @param {HTMLElement} clearButton - button to clear data\r\n * @param {Function} destroy - destroy function\r\n */\r\nconst showBtnToClearData = (clearButton = false, destroy) => {\r\n if (!clearButton) return;\r\n\r\n clearButton.classList.remove(\"hidden\");\r\n // add event to clear button\r\n clearButton.addEventListener(\"click\", destroy);\r\n};\r\n\r\n/**\r\n * Set aria-activedescendant\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {String} type\r\n */\r\nconst setAriaActivedescendant = (root, type) => {\r\n root.setAttribute(\"aria-activedescendant\", type || \"\");\r\n};\r\n\r\n/**\r\n * Get height of ul without group class\r\n *\r\n * @param {String} outputUl\r\n * @param {String} classGroup\r\n * @returns {Number}\r\n */\r\nconst getClassGroupHeight = (outputUl, classGroup) => {\r\n // get height of ul without group class\r\n const allLi = document.querySelectorAll(\r\n `#${outputUl} > li:not(.${classGroup})`\r\n );\r\n let height = 0;\r\n [].slice.call(allLi).map((el) => (height += el.offsetHeight));\r\n\r\n // return height\r\n return height;\r\n};\r\n\r\n/**\r\n * Scroll into view when press up/down arrows\r\n *\r\n * @param {HTMLElement} target\r\n * @param {HTMLElement} outputUl\r\n * @param {String} classGroup\r\n * @param {HTMLElement} resultList\r\n */\r\nconst followActiveElement = (target, outputUl, classGroup, resultList) => {\r\n const previusElement = resultList.previousSibling;\r\n\r\n const previusElementHeight = previusElement ? previusElement.offsetHeight : 0;\r\n\r\n if (target.getAttribute(\"aria-posinset\") == \"0\") {\r\n resultList.scrollTop =\r\n target.offsetTop - getClassGroupHeight(outputUl, classGroup);\r\n }\r\n\r\n if (target.offsetTop - previusElementHeight < resultList.scrollTop) {\r\n resultList.scrollTop = target.offsetTop - previusElementHeight;\r\n } else {\r\n const offsetBottom =\r\n target.offsetTop + target.offsetHeight - previusElementHeight;\r\n const scrollBottom = resultList.scrollTop + resultList.offsetHeight;\r\n if (offsetBottom > scrollBottom) {\r\n resultList.scrollTop = offsetBottom - resultList.offsetHeight;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Create output-list and put after search input\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {HTMLElement} resultList - output-list ul\r\n * @param {String} outputUl - id name of output-list\r\n * @param {HTMLElement} resultWrap - wrapper ul element\r\n * @param {String} prefix - add prefix to all class auto\r\n */\r\nconst output = (root, resultList, outputUl, resultWrap, prefix) => {\r\n // set attribute to results-list\r\n setAttributes(resultList, {\r\n id: outputUl,\r\n tabIndex: \"0\",\r\n role: \"listbox\",\r\n });\r\n\r\n // add class to wrap element\r\n setAttributes(resultWrap, {\r\n addClass: `${prefix}-results-wrapper`,\r\n });\r\n\r\n // insert the results into the wrap element\r\n resultWrap.insertAdjacentElement(\"beforeend\", resultList);\r\n\r\n // insert the wrap element after the search input\r\n root.parentNode.insertBefore(resultWrap, root.nextSibling);\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLDivElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport {\r\n addAriaToAllLiElements,\r\n createElement,\r\n followActiveElement,\r\n getFirstElementFromLiAndAddToInput,\r\n isObject,\r\n isPromise,\r\n output,\r\n scrollResultsToTop,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n};\r\n","/**\r\n * Key codes\r\n */\r\nconst keyCodes = {\r\n ESC: 27,\r\n ENTER: 13,\r\n UP: 38,\r\n DOWN: 40,\r\n TAB: 9,\r\n};\r\n\r\nexport default keyCodes;\r\n","import {\r\n addAriaToAllLiElements,\r\n createElement,\r\n followActiveElement,\r\n getFirstElementFromLiAndAddToInput,\r\n isObject,\r\n isPromise,\r\n output,\r\n scrollResultsToTop,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n} from \"./utils/function\";\r\n\r\nimport keyCodes from \"./utils/keyCodes\";\r\n\r\n/**\r\n * @class Autocomplete\r\n */\r\nexport default class Autocomplete {\r\n /**\r\n * Constructor\r\n *\r\n * @param {String} element\r\n * @param {Object} object\r\n */\r\n constructor(\r\n element,\r\n {\r\n delay = 500,\r\n clearButton = true,\r\n howManyCharacters = 1,\r\n selectFirst = false,\r\n insertToInput = false,\r\n showAllValues = false,\r\n cache = false,\r\n disableCloseOnSelect = false,\r\n classGroup,\r\n classPreventClosing,\r\n classPrefix,\r\n ariaLabelClear,\r\n onSearch,\r\n onResults = () => {},\r\n onSubmit = () => {},\r\n onOpened = () => {},\r\n onReset = () => {},\r\n onRender = () => {},\r\n onClose = () => {},\r\n noResults = () => {},\r\n onSelectedItem = () => {},\r\n }\r\n ) {\r\n this._id = element;\r\n this._root = document.getElementById(element);\r\n this._onSearch = isPromise(onSearch)\r\n ? onSearch\r\n : ({ currentValue, element }) =>\r\n Promise.resolve(onSearch({ currentValue, element }));\r\n this._onResults = onResults;\r\n this._onRender = onRender;\r\n this._onSubmit = onSubmit;\r\n this._onSelected = onSelectedItem;\r\n this._onOpened = onOpened;\r\n this._onReset = onReset;\r\n this._noResults = noResults;\r\n this._onClose = onClose;\r\n\r\n this._delay = delay;\r\n this._characters = howManyCharacters;\r\n this._clearButton = clearButton;\r\n this._selectFirst = selectFirst;\r\n this._toInput = insertToInput;\r\n this._showAll = showAllValues;\r\n this._classGroup = classGroup;\r\n this._prevClosing = classPreventClosing;\r\n this._clearBtnAriLabel = ariaLabelClear\r\n ? ariaLabelClear\r\n : \"clear the search query\";\r\n this._prefix = classPrefix ? `${classPrefix}-auto` : \"auto\";\r\n this._disable = disableCloseOnSelect;\r\n\r\n // default config\r\n this._cache = cache;\r\n this._outputUl = `${this._prefix}-${this._id}-results`;\r\n this._cacheData = `data-cache-auto-${this._id}`;\r\n this._isLoading = `${this._prefix}-is-loading`;\r\n this._isActive = `${this._prefix}-is-active`;\r\n this._activeList = `${this._prefix}-selected`;\r\n this._selectedOption = `${this._prefix}-selected-option`;\r\n this._err = `${this._prefix}-error`;\r\n this._regex = /[|\\\\{}()[\\]^$+*?.]/g;\r\n this._timeout = null;\r\n\r\n this._resultWrap = createElement(\"div\");\r\n this._resultList = createElement(\"ul\");\r\n this._cBtn = createElement(\"button\");\r\n\r\n this._initial();\r\n }\r\n\r\n /**\r\n * Initial function\r\n */\r\n _initial = () => {\r\n this._clearbutton();\r\n\r\n output(\r\n this._root,\r\n this._resultList,\r\n this._outputUl,\r\n this._resultWrap,\r\n this._prefix\r\n );\r\n\r\n // default aria\r\n // this.reset();\r\n this._root.addEventListener(\"input\", this._handleInput);\r\n\r\n // show all values on click root input\r\n this._showAll && this._root.addEventListener(\"click\", this._handleInput);\r\n\r\n // calback functions\r\n this._onRender({\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n };\r\n\r\n /**\r\n * Actions on input\r\n *\r\n * @param {String} type - set attribute depending on type\r\n * @param {String} target\r\n */\r\n _cacheAct = (type, target) => {\r\n if (!this._cache) return;\r\n\r\n if (type === \"update\") {\r\n this._root.setAttribute(this._cacheData, target.value);\r\n } else if (type === \"remove\") {\r\n this._root.removeAttribute(this._cacheData);\r\n } else {\r\n this._root.value = this._root.getAttribute(this._cacheData);\r\n }\r\n };\r\n\r\n /**\r\n * Handle input\r\n *\r\n * @param {Event} object\r\n */\r\n _handleInput = ({ target, type }) => {\r\n if (\r\n this._root.getAttribute(\"aria-expanded\") === \"true\" &&\r\n type === \"click\"\r\n ) {\r\n return;\r\n }\r\n\r\n // replace all special characters\r\n const regex = target.value.replace(this._regex, \"\\\\$&\");\r\n\r\n // update data attribute cache\r\n this._cacheAct(\"update\", target);\r\n\r\n const delay = this._showAll ? 0 : this._delay;\r\n // clear timeout\r\n clearTimeout(this._timeout);\r\n this._timeout = setTimeout(() => {\r\n this._searchItem(regex.trim());\r\n }, delay);\r\n };\r\n\r\n /**\r\n * Default aria\r\n */\r\n _reset = () => {\r\n // set attributes to root - input\r\n setAttributes(this._root, {\r\n \"aria-owns\": `${this._id}-list`,\r\n \"aria-expanded\": \"false\",\r\n \"aria-autocomplete\": \"list\",\r\n \"aria-activedescendant\": \"\",\r\n role: \"combobox\",\r\n removeClass: \"auto-expanded\",\r\n });\r\n\r\n // remove class isActive\r\n this._resultWrap.classList.remove(this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n // scrollResultsToTop(this.resultList, this.resultWrap);\r\n\r\n // remove result when lengh = 0 and insertToInput is false\r\n if ((this._matches?.length == 0 && !this._toInput) || this._showAll) {\r\n this._resultList.innerHTML = \"\";\r\n }\r\n\r\n // set index\r\n this._index = this._selectFirst ? 0 : -1;\r\n\r\n // callback function\r\n this._onClose();\r\n };\r\n\r\n /**\r\n * The async function gets the text from the search\r\n * and returns the matching array\r\n *\r\n * @param {String} value\r\n */\r\n _searchItem = (value) => {\r\n this._value = value;\r\n\r\n // if searching show loading icon\r\n this._onLoading(true);\r\n\r\n // hide button clear\r\n showBtnToClearData(this._cBtn, this.destroy);\r\n\r\n // if there is no value and clearButton is true\r\n if (value.length == 0 && this._clearButton) {\r\n this._cBtn.classList.add(\"hidden\");\r\n }\r\n\r\n // if declare characters more then value.len and showAll is false\r\n // remove class isActive\r\n if (this._characters > value.length && !this._showAll) {\r\n this._onLoading();\r\n return;\r\n }\r\n\r\n // callblack function onSearch\r\n this._onSearch({ currentValue: value, element: this._root })\r\n .then((result) => {\r\n const rootValueLength = this._root.value.length;\r\n const resultLength = result.length;\r\n // set no result\r\n this._matches = Array.isArray(result)\r\n ? [...result]\r\n : JSON.parse(JSON.stringify(result));\r\n\r\n this._onLoading();\r\n this._error();\r\n\r\n // if use destroy() method\r\n if (resultLength == 0 && rootValueLength == 0) {\r\n this._cBtn.classList.add(\"hidden\");\r\n }\r\n\r\n if (resultLength == 0 && rootValueLength) {\r\n this._root.classList.remove(\"auto-expanded\");\r\n this._reset();\r\n this._noResults({\r\n element: this._root,\r\n currentValue: value,\r\n template: this._results,\r\n });\r\n this._events();\r\n } else if (resultLength > 0 || isObject(result)) {\r\n this._index = this._selectFirst ? 0 : -1;\r\n this._results();\r\n this._events();\r\n }\r\n })\r\n .catch(() => {\r\n this._onLoading();\r\n this._reset();\r\n });\r\n };\r\n\r\n /**\r\n * Set or remove loading class\r\n *\r\n * @param {Boolean} type\r\n */\r\n _onLoading = (type) =>\r\n this._root.parentNode.classList[type ? \"add\" : \"remove\"](this._isLoading);\r\n\r\n /**\r\n * Set error class to the root element\r\n */\r\n _error = () => this._root.classList.remove(this._err);\r\n\r\n /**\r\n * Events\r\n */\r\n _events = () => {\r\n // handle click on keydown [up, down, enter, tab, esc]\r\n this._root.addEventListener(\"keydown\", this._handleKeys);\r\n\r\n //\r\n this._root.addEventListener(\"click\", this._handleShowItems);\r\n\r\n // temporarily disabled mouseleave\r\n [\"mousemove\", \"click\"].map((eventType) => {\r\n this._resultList.addEventListener(eventType, this._handleMouse);\r\n });\r\n\r\n // close expanded items\r\n document.addEventListener(\"click\", this._handleDocClick);\r\n };\r\n\r\n /**\r\n * Results\r\n *\r\n * @param {HTMLElement|String} template - html or string returned from the function,\r\n * look at the example - https://github.com/tomik23/autocomplete/blob/master/docs/js/examples/no-results.js#L30\r\n */\r\n _results = (template) => {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add all found records to otput ul\r\n this._resultList.innerHTML =\r\n this._matches.length === 0\r\n ? this._onResults({\r\n currentValue: this._value,\r\n matches: 0,\r\n template,\r\n })\r\n : this._onResults({\r\n currentValue: this._value,\r\n matches: this._matches,\r\n classGroup: this._classGroup,\r\n });\r\n\r\n this._resultWrap.classList.add(this._isActive);\r\n\r\n const checkIfClassGroupExist = this._classGroup\r\n ? `:not(.${this._classGroup})`\r\n : \"\";\r\n\r\n this._itemsLi = document.querySelectorAll(\r\n `#${this._outputUl} > li${checkIfClassGroupExist}`\r\n );\r\n\r\n // adding role, tabindex and aria\r\n addAriaToAllLiElements(this._itemsLi);\r\n\r\n // action on open results\r\n this._onOpened({\r\n type: \"results\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n\r\n // select first element\r\n this._selectFirstEl();\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n };\r\n\r\n /**\r\n * Hangle click on document\r\n *\r\n * @param {Event} object\r\n */\r\n _handleDocClick = ({ target }) => {\r\n let disableClose = null;\r\n\r\n // if 'target' is a ul and 'disableCloseOnSelect'\r\n // is a 'true' set 'disableClose' on true\r\n if (\r\n (target.closest(\"ul\") && this._disable) ||\r\n // when class classDisableClose\r\n // then do not not close results\r\n target.closest(`.${this._prevClosing}`)\r\n ) {\r\n disableClose = true;\r\n }\r\n\r\n if (target.id !== this._id && !disableClose) {\r\n this._reset();\r\n return;\r\n }\r\n };\r\n\r\n /**\r\n * Select first element\r\n */\r\n _selectFirstEl = () => {\r\n this._remAria(document.querySelector(`.${this._activeList}`));\r\n\r\n if (!this._selectFirst) {\r\n return;\r\n }\r\n\r\n const { firstElementChild } = this._resultList;\r\n\r\n const classSelectFirst =\r\n this._classGroup && this._matches.length > 0 && this._selectFirst\r\n ? firstElementChild.nextElementSibling\r\n : firstElementChild;\r\n\r\n // calback function onSelect when first element is true\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set attribute to first element\r\n setAttributes(classSelectFirst, {\r\n id: `${this._selectedOption}-0`,\r\n addClass: this._activeList,\r\n \"aria-selected\": \"true\",\r\n });\r\n\r\n // set aria active descendant\r\n setAriaActivedescendant(this._root, `${this._selectedOption}-0`);\r\n };\r\n\r\n /**\r\n * show items when items.length > 0 and is not empty\r\n */\r\n _handleShowItems = () => {\r\n // if resultWrap is not active and resultList is not empty\r\n if (\r\n this._resultList.textContent.length > 0 &&\r\n !this._resultWrap.classList.contains(this._isActive)\r\n ) {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add isActive class to resultWrap\r\n this._resultWrap.classList.add(this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n\r\n // select first element\r\n this._selectFirstEl();\r\n\r\n // callback function\r\n this._onOpened({\r\n type: \"showItems\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Adding text from the list when li is clicking\r\n * or adding aria-selected to li elements\r\n *\r\n * @param {Event} event\r\n */\r\n _handleMouse = (event) => {\r\n event.preventDefault();\r\n\r\n const { target, type } = event;\r\n const targetClosest = target.closest(\"li\");\r\n const targetClosestRole = targetClosest?.hasAttribute(\"role\");\r\n const activeClass = this._activeList;\r\n const activeClassElement = document.querySelector(`.${activeClass}`);\r\n\r\n if (!targetClosest || !targetClosestRole) {\r\n return;\r\n }\r\n\r\n // click on li get element\r\n if (type === \"click\") {\r\n // get text from clicked li\r\n this._getTextFromLi(targetClosest);\r\n }\r\n\r\n if (\r\n type === \"mousemove\" &&\r\n !targetClosest.classList.contains(activeClass)\r\n ) {\r\n this._remAria(activeClassElement);\r\n\r\n // add aria to li\r\n this._setAria(targetClosest);\r\n this._index = this._indexLiSelected(targetClosest);\r\n\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Get text from li on enter or click\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _getTextFromLi = (element) => {\r\n if (!element || this._matches.length === 0) {\r\n // set default settings\r\n !this._disable && this._reset();\r\n\r\n return;\r\n }\r\n\r\n // get first element from li and set it to root\r\n getFirstElementFromLiAndAddToInput(element, this._root);\r\n\r\n // onSubmit passing text to function\r\n this._onSubmit({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n results: this._resultList,\r\n });\r\n\r\n // set default settings\r\n if (!this._disable) {\r\n this._remAria(element);\r\n this._reset();\r\n }\r\n\r\n // show clearBtn when select element\r\n this._clearButton && this._cBtn.classList.remove(\"hidden\");\r\n\r\n // remove cache\r\n this._cacheAct(\"remove\");\r\n };\r\n\r\n /**\r\n * Return which li element was selected\r\n * by hovering the mouse over\r\n *\r\n * @param {HTMLElement} target\r\n * @returns {Number}\r\n */\r\n _indexLiSelected = (target) =>\r\n // get index of li element\r\n Array.prototype.indexOf.call(this._itemsLi, target);\r\n\r\n /**\r\n * Navigating the elements li and enter\r\n *\r\n * @param {Event} event\r\n */\r\n _handleKeys = (event) => {\r\n const { keyCode } = event;\r\n\r\n const resultList = this._resultWrap.classList.contains(this._isActive);\r\n\r\n const matchesLength = this._matches.length + 1;\r\n this._selectedLi = document.querySelector(`.${this._activeList}`);\r\n\r\n // switch between keys\r\n switch (keyCode) {\r\n case keyCodes.UP:\r\n case keyCodes.DOWN:\r\n // Wrong cursor position in the input field #62\r\n // Prevents the cursor from moving to the beginning\r\n // of input as the cursor hovers over the results.\r\n event.preventDefault();\r\n\r\n if ((matchesLength <= 1 && this._selectFirst) || !resultList) {\r\n return;\r\n }\r\n\r\n // if keyCode is up\r\n if (keyCode === keyCodes.UP) {\r\n if (this._index < 0) {\r\n this._index = matchesLength - 1;\r\n }\r\n this._index -= 1;\r\n } else {\r\n this._index += 1;\r\n if (this._index >= matchesLength) {\r\n this._index = 0;\r\n }\r\n }\r\n\r\n // remove aria-selected\r\n this._remAria(this._selectedLi);\r\n\r\n if (\r\n matchesLength > 0 &&\r\n this._index >= 0 &&\r\n this._index < matchesLength - 1\r\n ) {\r\n if (this._toInput && resultList) {\r\n getFirstElementFromLiAndAddToInput(\r\n this._itemsLi[this._index],\r\n this._root\r\n );\r\n }\r\n\r\n // callback function\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set aria-selected\r\n this._setAria(this._itemsLi[this._index]);\r\n } else {\r\n // catch action\r\n this._cacheAct();\r\n setAriaActivedescendant(this._root);\r\n\r\n this._onSelected({\r\n index: null,\r\n element: this._root,\r\n object: null,\r\n });\r\n }\r\n\r\n break;\r\n // keycode enter\r\n case keyCodes.ENTER:\r\n this._getTextFromLi(this._selectedLi);\r\n break;\r\n\r\n // keycode escape and keycode tab\r\n case keyCodes.TAB:\r\n case keyCodes.ESC:\r\n event.stopPropagation(); // #120\r\n this._reset();\r\n\r\n break;\r\n default:\r\n break;\r\n }\r\n };\r\n\r\n /**\r\n * Set aria label on item li\r\n *\r\n * @param {HTMLElement} target\r\n */\r\n _setAria = (target) => {\r\n const selectedOption = `${this._selectedOption}-${this._indexLiSelected(\r\n target\r\n )}`;\r\n\r\n // set aria to li\r\n setAttributes(target, {\r\n id: selectedOption,\r\n \"aria-selected\": \"true\",\r\n addClass: this._activeList,\r\n });\r\n\r\n setAriaActivedescendant(this._root, selectedOption);\r\n\r\n // scrollIntoView when press up/down arrows\r\n followActiveElement(\r\n target,\r\n this._outputUl,\r\n this._classGroup,\r\n this._resultList\r\n );\r\n };\r\n\r\n /**\r\n * Remove aria label from item li\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _remAria = (element) => {\r\n if (!element) return;\r\n\r\n // remove aria from li\r\n setAttributes(element, {\r\n id: \"\",\r\n removeClass: this._activeList,\r\n \"aria-selected\": \"false\",\r\n });\r\n };\r\n\r\n /**\r\n * Create clear button and\r\n * removing text from the input field\r\n */\r\n _clearbutton = () => {\r\n // stop when clear button is disabled\r\n if (!this._clearButton) return;\r\n\r\n // add aria to clear button\r\n setAttributes(this._cBtn, {\r\n class: `${this._prefix}-clear hidden`,\r\n type: \"button\",\r\n title: this._clearBtnAriLabel,\r\n \"aria-label\": this._clearBtnAriLabel,\r\n });\r\n\r\n // insert clear button after input - root\r\n this._root.insertAdjacentElement(\"afterend\", this._cBtn);\r\n };\r\n\r\n /**\r\n * Clicking on the clear button\r\n * publick destroy method\r\n */\r\n destroy = () => {\r\n // if clear button is true then add class hidden\r\n this._clearButton && this._cBtn.classList.add(\"hidden\");\r\n // clear value searchId\r\n this._root.value = \"\";\r\n // set focus\r\n this._root.focus();\r\n // remove li from ul\r\n this._resultList.textContent = \"\";\r\n // set default aria\r\n this._reset();\r\n // remove error if exist\r\n this._error();\r\n\r\n // callback function\r\n this._onReset(this._root);\r\n\r\n // remove listener\r\n this._root.removeEventListener(\"keydown\", this._handleKeys);\r\n this._root.removeEventListener(\"click\", this._handleShowItems);\r\n // remove listener on click on document\r\n document.removeEventListener(\"click\", this._handleDocClick);\r\n };\r\n}\r\n"],"names":["isObject","value","constructor","Object","isPromise","Boolean","then","setAttributes","el","object","key","classList","add","remove","setAttribute","getFirstElement","element","firstElementChild","getFirstElementFromLiAndAddToInput","root","textContent","trim","scrollResultsToTop","resultList","resultWrap","scrollTop","offsetTop","offsetHeight","addAriaToAllLiElements","itemsLi","i","length","role","tabindex","showBtnToClearData","clearButton","destroy","addEventListener","setAriaActivedescendant","type","getClassGroupHeight","outputUl","classGroup","allLi","document","querySelectorAll","height","slice","call","map","followActiveElement","target","previusElement","previousSibling","previusElementHeight","getAttribute","offsetBottom","scrollBottom","output","prefix","id","tabIndex","addClass","insertAdjacentElement","parentNode","insertBefore","nextSibling","createElement","keyCodes","ESC","ENTER","UP","DOWN","TAB","Autocomplete","delay","howManyCharacters","selectFirst","insertToInput","showAllValues","cache","disableCloseOnSelect","classPreventClosing","classPrefix","ariaLabelClear","onSearch","onResults","onSubmit","onOpened","onReset","onRender","onClose","noResults","onSelectedItem","_initial","_clearbutton","_root","_resultList","_outputUl","_resultWrap","_prefix","_handleInput","_showAll","_onRender","results","_cacheAct","_cache","_cacheData","removeAttribute","regex","replace","_regex","_delay","clearTimeout","_timeout","setTimeout","_searchItem","_reset","_id","removeClass","_isActive","_matches","_toInput","innerHTML","_index","_selectFirst","_onClose","_value","_onLoading","_cBtn","_clearButton","_characters","_onSearch","currentValue","result","rootValueLength","resultLength","Array","isArray","JSON","parse","stringify","_error","_noResults","template","_results","_events","catch","_isLoading","_err","_handleKeys","_handleShowItems","eventType","_handleMouse","_handleDocClick","_onResults","matches","_classGroup","checkIfClassGroupExist","_itemsLi","_onOpened","_selectFirstEl","disableClose","closest","_disable","_prevClosing","_remAria","querySelector","_activeList","classSelectFirst","nextElementSibling","_onSelected","index","_selectedOption","contains","event","preventDefault","targetClosest","targetClosestRole","hasAttribute","activeClass","activeClassElement","_getTextFromLi","_setAria","_indexLiSelected","_onSubmit","prototype","indexOf","keyCode","matchesLength","_selectedLi","stopPropagation","selectedOption","class","title","_clearBtnAriLabel","focus","_onReset","removeEventListener","getElementById","Promise","resolve"],"mappings":"AAKA,MAAMA,QAAQ,GAAIC,KAAD,IACfA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAA1B,IAAsCA,KAAK,CAACC,WAAN,KAAsBC,MAD9D;AAUA,MAAMC,SAAS,GAAIH,KAAD,IAAWI,OAAO,CAACJ,KAAK,IAAI,OAAOA,KAAK,CAACK,IAAb,KAAsB,UAAhC,CAApC;AAQA,MAAMC,aAAa,GAAG,CAACC,EAAD,EAAKC,MAAL,KAAgB;AACpC,OAAK,IAAIC,GAAT,IAAgBD,MAAhB,EAAwB;AACtB,QAAIC,GAAG,KAAK,UAAZ,EAAwB;AACtBF,MAAAA,EAAE,CAACG,SAAH,CAAaC,GAAb,CAAiBH,MAAM,CAACC,GAAD,CAAvB;AACD,KAFD,MAEO,IAAIA,GAAG,KAAK,aAAZ,EA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AACA,SAAKsD,YAAL,GAAoB/F,WAApB;AACA,SAAK0F,YAAL,GAAoBhD,WAApB;AACA,SAAK6C,QAAL,GAAgB5C,aAAhB;AACA,SAAKwB,QAAL,GAAgBvB,aAAhB;AACA,SAAK8E,WAAL,GAAmBnH,UAAnB;AACA,SAAK2H,YAAL,GAAoBnF,mBAApB;AACA,SAAKiH,iBAAL,GAAyB/G,cAAc,GACnCA,cADmC,GAEnC,wBAFJ;AAGA,SAAKgB,OAAL,GAAejB,WAAW,GAAMA,WAAN,aAA2B,MAArD;AACA,SAAKiF,QAAL,GAAgBnF,oBAAhB,CA5BA;AA+BA,SAAKyB,MAAL,GAAc1B,KAAd;AACA,SAAKkB,SAAL,GAAoB,KAAKE,OAAzB,SAAoC,KAAKkB,GAAzC;AACA,SAAKX,UAAL,wBAAqC,KAAKW,GAA1C;AACA,SAAK8B,UAAL,GAAqB,KAAKhD,OAA1B;AACA,SAAKoB,SAAL,GAAoB,KAAKpB,OAAzB;AACA,SAAKoE,WAAL,GAAsB,KAAKpE,OAA3B;AACA,SAAKyE,eAAL,GAA0B,KAAKzE,OAA/B;AACA,SAAKiD,IAAL,GAAe,KAAKjD,OAApB;AACA,SAAKW,MAAL,GAAc,qBAAd;AACA,SAAKG,QAAL,GAAgB,IAAhB;AAEA,SAAKf,WAAL,GAAmBhC,aAAa,CAAC,KAAD,CAAhC;AACA,SAAK8B,WAAL,GAAmB9B,aAAa,CAAC,IAAD,CAAhC;AACA,SAAK8D,KAAL,GAAa9D,aAAa,CAAC,QAAD,CAA1B;AAEA,SAAK2B,QAAL;AACD;AA/E+B;;;;"} \ No newline at end of file +{"version":3,"file":"autocomplete.esm.js","sources":["../../sources/js/utils/function.js","../../sources/js/utils/keyCodes.js","../../sources/js/script.js"],"sourcesContent":["/**\r\n * Check is a Object\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isObject = (value) =>\r\n value && typeof value === \"object\" && value.constructor === Object;\r\n\r\n/**\r\n * Check if is a Promise\r\n * https://stackoverflow.com/a/53955664/10424385\r\n *\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isPromise = (value) => Boolean(value && typeof value.then === \"function\");\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n if (key === \"addClass\") {\r\n classList(el, \"add\", object[key]);\r\n } else if (key === \"removeClass\") {\r\n classList(el, \"remove\", object[key]);\r\n } else {\r\n el.setAttribute(key, object[key]);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Get first element from child\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {HTMLELement}\r\n */\r\nconst getFirstElement = (element) =>\r\n (element.firstElementChild || element).textContent.trim();\r\n\r\n/**\r\n * Scroll to top result-list\r\n * @param {HTMLElement} resultList\r\n * @param {HTMLElement} resultWrap\r\n */\r\nconst scrollResultsToTop = (resultList, resultWrap) => {\r\n // if there is an overflow of ul element, after\r\n // opening we always move ul to the top of the results\r\n resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight;\r\n};\r\n\r\n/**\r\n * Adding role, tabindex, aria and call handleMouse\r\n *\r\n * @param {HTMLElement} itemsLi\r\n */\r\nconst addAriaToAllLiElements = (itemsLi) => {\r\n // add role to all li elements\r\n for (let i = 0; i < itemsLi.length; i++) {\r\n setAttributes(itemsLi[i], {\r\n role: \"option\",\r\n tabindex: \"-1\",\r\n \"aria-selected\": \"false\",\r\n \"aria-setsize\": itemsLi.length,\r\n \"aria-posinset\": i,\r\n });\r\n }\r\n};\r\n\r\n/**\r\n * Show btn to clear data\r\n *\r\n * @param {HTMLElement} clearButton - button to clear data\r\n * @param {Function} destroy - destroy function\r\n */\r\nconst showBtnToClearData = (clearButton = false, destroy) => {\r\n if (!clearButton) return;\r\n\r\n classList(clearButton, \"remove\", \"hidden\");\r\n // add event to clear button\r\n onEvent(clearButton, \"click\", destroy);\r\n};\r\n\r\n/**\r\n * ClassList add/remove/contains\r\n *\r\n * @param {HTMLElement} element - html element\r\n * @param {String} action - add/remove/contains\r\n * @param {String} className - class name\r\n */\r\nconst classList = (element, action, className) =>\r\n element.classList[action](className);\r\n\r\n/**\r\n * Set aria-activedescendant\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {String} type\r\n */\r\nconst setAriaActivedescendant = (root, type) => {\r\n setAttributes(root, {\r\n \"aria-activedescendant\": type || \"\",\r\n });\r\n};\r\n\r\n/**\r\n * Get height of ul without group class\r\n *\r\n * @param {String} outputUl\r\n * @param {String} classGroup\r\n * @returns {Number}\r\n */\r\nconst getClassGroupHeight = (outputUl, classGroup) => {\r\n // get height of ul without group class\r\n const allLiElements = document.querySelectorAll(\r\n `#${outputUl} > li:not(.${classGroup})`\r\n );\r\n let height = 0;\r\n [].slice.call(allLiElements).map((el) => (height += el.offsetHeight));\r\n\r\n // return height\r\n return height;\r\n};\r\n\r\n/**\r\n * Scroll into view when press up/down arrows\r\n *\r\n * @param {HTMLElement} target\r\n * @param {HTMLElement} outputUl\r\n * @param {String} classGroup\r\n * @param {HTMLElement} resultList\r\n */\r\nconst followActiveElement = (target, outputUl, classGroup, resultList) => {\r\n const previusElement = resultList.previousSibling;\r\n\r\n const previusElementHeight = previusElement ? previusElement.offsetHeight : 0;\r\n\r\n if (target.getAttribute(\"aria-posinset\") == \"0\") {\r\n resultList.scrollTop =\r\n target.offsetTop - getClassGroupHeight(outputUl, classGroup);\r\n }\r\n\r\n if (target.offsetTop - previusElementHeight < resultList.scrollTop) {\r\n resultList.scrollTop = target.offsetTop - previusElementHeight;\r\n } else {\r\n const offsetBottom =\r\n target.offsetTop + target.offsetHeight - previusElementHeight;\r\n const scrollBottom = resultList.scrollTop + resultList.offsetHeight;\r\n if (offsetBottom > scrollBottom) {\r\n resultList.scrollTop = offsetBottom - resultList.offsetHeight;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Create output-list and put after search input\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {HTMLElement} resultList - output-list ul\r\n * @param {String} outputUl - id name of output-list\r\n * @param {HTMLElement} resultWrap - wrapper ul element\r\n * @param {String} prefix - add prefix to all class auto\r\n */\r\nconst output = (root, resultList, outputUl, resultWrap, prefix) => {\r\n // set attribute to results-list\r\n setAttributes(resultList, {\r\n id: outputUl,\r\n tabIndex: \"0\",\r\n role: \"listbox\",\r\n });\r\n\r\n // add class to wrap element\r\n setAttributes(resultWrap, {\r\n addClass: `${prefix}-results-wrapper`,\r\n });\r\n\r\n // insert the results into the wrap element\r\n resultWrap.insertAdjacentElement(\"beforeend\", resultList);\r\n\r\n // insert the wrap element after the search input\r\n root.parentNode.insertBefore(resultWrap, root.nextSibling);\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLDivElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\n/**\r\n * Get element\r\n *\r\n * @param {String} element\r\n * @returns {HTMLElement}\r\n */\r\nconst select = (element) => document.querySelector(element);\r\n\r\n/**\r\n * Event listeners\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} action\r\n * @param {Function} callback\r\n */\r\nconst onEvent = (element, action, callback) => {\r\n element.addEventListener(action, callback);\r\n};\r\n\r\n/**\r\n * Remove event listeners\r\n */\r\nconst offEvent = (element, action, callback) => {\r\n element.removeEventListener(action, callback);\r\n};\r\n\r\nexport {\r\n addAriaToAllLiElements,\r\n classList,\r\n createElement,\r\n followActiveElement,\r\n getFirstElement,\r\n isObject,\r\n isPromise,\r\n offEvent,\r\n onEvent,\r\n output,\r\n scrollResultsToTop,\r\n select,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n};\r\n","/**\r\n * Key codes\r\n */\r\nconst keyCodes = {\r\n ESC: 27,\r\n ENTER: 13,\r\n UP: 38,\r\n DOWN: 40,\r\n TAB: 9,\r\n};\r\n\r\nexport default keyCodes;\r\n","import {\r\n addAriaToAllLiElements,\r\n classList,\r\n createElement,\r\n followActiveElement,\r\n getFirstElement,\r\n isObject,\r\n isPromise,\r\n offEvent,\r\n onEvent,\r\n output,\r\n scrollResultsToTop,\r\n select,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n} from \"./utils/function\";\r\n\r\nimport keyCodes from \"./utils/keyCodes\";\r\n\r\n/**\r\n * @class Autocomplete\r\n */\r\nexport default class Autocomplete {\r\n /**\r\n * Constructor\r\n *\r\n * @param {String} element\r\n * @param {Object} object\r\n */\r\n constructor(\r\n element,\r\n {\r\n delay = 500,\r\n clearButton = true,\r\n howManyCharacters = 1,\r\n selectFirst = false,\r\n insertToInput = false,\r\n showAllValues = false,\r\n cache = false,\r\n disableCloseOnSelect = false,\r\n classGroup,\r\n classPreventClosing,\r\n classPrefix,\r\n ariaLabelClear,\r\n onSearch,\r\n onResults = () => {},\r\n onSubmit = () => {},\r\n onOpened = () => {},\r\n onReset = () => {},\r\n onRender = () => {},\r\n onClose = () => {},\r\n noResults = () => {},\r\n onSelectedItem = () => {},\r\n }\r\n ) {\r\n this._id = element;\r\n this._root = document.getElementById(element);\r\n this._onSearch = isPromise(onSearch)\r\n ? onSearch\r\n : ({ currentValue, element }) =>\r\n Promise.resolve(onSearch({ currentValue, element }));\r\n this._onResults = onResults;\r\n this._onRender = onRender;\r\n this._onSubmit = onSubmit;\r\n this._onSelected = onSelectedItem;\r\n this._onOpened = onOpened;\r\n this._onReset = onReset;\r\n this._noResults = noResults;\r\n this._onClose = onClose;\r\n\r\n this._delay = delay;\r\n this._characters = howManyCharacters;\r\n this._clearButton = clearButton;\r\n this._selectFirst = selectFirst;\r\n this._toInput = insertToInput;\r\n this._showAll = showAllValues;\r\n this._classGroup = classGroup;\r\n this._prevClosing = classPreventClosing;\r\n this._clearBtnAriLabel = ariaLabelClear\r\n ? ariaLabelClear\r\n : \"clear the search query\";\r\n this._prefix = classPrefix ? `${classPrefix}-auto` : \"auto\";\r\n this._disable = disableCloseOnSelect;\r\n\r\n // default config\r\n this._cache = cache;\r\n this._outputUl = `${this._prefix}-${this._id}-results`;\r\n this._cacheData = `data-cache-auto-${this._id}`;\r\n this._isLoading = `${this._prefix}-is-loading`;\r\n this._isActive = `${this._prefix}-is-active`;\r\n this._activeList = `${this._prefix}-selected`;\r\n this._selectedOption = `${this._prefix}-selected-option`;\r\n this._err = `${this._prefix}-error`;\r\n this._regex = /[|\\\\{}()[\\]^$+*?.]/g;\r\n this._timeout = null;\r\n\r\n this._resultWrap = createElement(\"div\");\r\n this._resultList = createElement(\"ul\");\r\n this._clearBtn = createElement(\"button\");\r\n\r\n this._initial();\r\n }\r\n\r\n /**\r\n * Initial function\r\n */\r\n _initial = () => {\r\n this._clearbutton();\r\n\r\n output(\r\n this._root,\r\n this._resultList,\r\n this._outputUl,\r\n this._resultWrap,\r\n this._prefix\r\n );\r\n\r\n // default aria\r\n onEvent(this._root, \"input\", this._handleInput);\r\n\r\n // show all values on click root input\r\n this._showAll && onEvent(this._root, \"click\", this._handleInput);\r\n\r\n // calback functions\r\n this._onRender({\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n };\r\n\r\n /**\r\n * Actions on input\r\n *\r\n * @param {String} type - set attribute depending on type\r\n * @param {String} target\r\n */\r\n _cacheAct = (type, target) => {\r\n if (!this._cache) return;\r\n\r\n if (type === \"update\") {\r\n this._root.setAttribute(this._cacheData, target.value);\r\n } else if (type === \"remove\") {\r\n this._root.removeAttribute(this._cacheData);\r\n } else {\r\n this._root.value = this._root.getAttribute(this._cacheData);\r\n }\r\n };\r\n\r\n /**\r\n * Handle input\r\n *\r\n * @param {Event} object\r\n */\r\n _handleInput = ({ target, type }) => {\r\n if (\r\n this._root.getAttribute(\"aria-expanded\") === \"true\" &&\r\n type === \"click\"\r\n ) {\r\n return;\r\n }\r\n\r\n // replace all special characters\r\n const regex = target.value.replace(this._regex, \"\\\\$&\");\r\n\r\n // update data attribute cache\r\n this._cacheAct(\"update\", target);\r\n\r\n const delay = this._showAll ? 0 : this._delay;\r\n // clear timeout\r\n clearTimeout(this._timeout);\r\n this._timeout = setTimeout(() => {\r\n this._searchItem(regex.trim());\r\n }, delay);\r\n };\r\n\r\n /**\r\n * Default aria\r\n */\r\n _reset = () => {\r\n // set attributes to root - input\r\n setAttributes(this._root, {\r\n \"aria-owns\": `${this._id}-list`,\r\n \"aria-expanded\": \"false\",\r\n \"aria-autocomplete\": \"list\",\r\n \"aria-activedescendant\": \"\",\r\n role: \"combobox\",\r\n removeClass: \"auto-expanded\",\r\n });\r\n\r\n // remove class isActive\r\n classList(this._resultWrap, \"remove\", this._isActive);\r\n\r\n // set index\r\n this._index = this._selectFirst ? 0 : -1;\r\n\r\n // callback function\r\n this._onClose();\r\n };\r\n\r\n /**\r\n * The async function gets the text from the search\r\n * and returns the matching array\r\n *\r\n * @param {String} value\r\n */\r\n _searchItem = (value) => {\r\n this._value = value;\r\n\r\n // if searching show loading icon\r\n this._onLoading(true);\r\n\r\n // hide button clear\r\n showBtnToClearData(this._clearBtn, this.destroy);\r\n\r\n // if there is no value and clearButton is true\r\n if (value.length == 0 && this._clearButton) {\r\n classList(this._clearBtn, \"add\", \"hidden\");\r\n }\r\n\r\n // if declare characters more then value.len and showAll is false\r\n // remove class isActive\r\n if (this._characters > value.length && !this._showAll) {\r\n this._onLoading();\r\n return;\r\n }\r\n\r\n // callblack function onSearch\r\n this._onSearch({ currentValue: value, element: this._root })\r\n .then((result) => {\r\n const rootValueLength = this._root.value.length;\r\n const resultLength = result.length;\r\n // set no result\r\n this._matches = Array.isArray(result)\r\n ? result\r\n : JSON.parse(JSON.stringify(result));\r\n\r\n this._onLoading();\r\n this._error();\r\n\r\n // if use destroy() method\r\n if (resultLength == 0 && rootValueLength == 0) {\r\n classList(this._clearBtn, \"add\", \"hidden\");\r\n }\r\n\r\n if (resultLength == 0 && rootValueLength) {\r\n classList(this._root, \"remove\", \"auto-expanded\");\r\n this._reset();\r\n this._noResults({\r\n element: this._root,\r\n currentValue: value,\r\n template: this._results,\r\n });\r\n this._events();\r\n } else if (resultLength > 0 || isObject(result)) {\r\n this._index = this._selectFirst ? 0 : -1;\r\n this._results();\r\n this._events();\r\n }\r\n })\r\n .catch(() => {\r\n this._onLoading();\r\n this._reset();\r\n });\r\n };\r\n\r\n /**\r\n * Set or remove loading class\r\n *\r\n * @param {Boolean} type\r\n */\r\n _onLoading = (type) =>\r\n this._root.parentNode.classList[type ? \"add\" : \"remove\"](this._isLoading);\r\n\r\n /**\r\n * Set error class to the root element\r\n */\r\n _error = () => classList(this._root, \"remove\", this._err);\r\n\r\n /**\r\n * Events\r\n */\r\n _events = () => {\r\n // handle click on keydown [up, down, enter, tab, esc]\r\n onEvent(this._root, \"keydown\", this._handleKeys);\r\n\r\n onEvent(this._root, \"click\", this._handleShowItems);\r\n\r\n // temporarily disabled mouseleave\r\n [\"mousemove\", \"click\"].map((eventType) => {\r\n onEvent(this._resultList, eventType, this._handleMouse);\r\n });\r\n\r\n // close expanded items\r\n onEvent(document, \"click\", this._handleDocClick);\r\n };\r\n\r\n /**\r\n * Results\r\n *\r\n * @param {HTMLElement|String} template - html or string returned from the function,\r\n * look at the example - https://github.com/tomik23/autocomplete/blob/master/docs/js/examples/no-results.js#L30\r\n */\r\n _results = (template) => {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // clear result list\r\n this._resultList.textContent = \"\";\r\n\r\n // add all found records to otput ul\r\n const dataResults =\r\n this._matches.length === 0\r\n ? this._onResults({\r\n currentValue: this._value,\r\n matches: 0,\r\n template,\r\n })\r\n : this._onResults({\r\n currentValue: this._value,\r\n matches: this._matches,\r\n classGroup: this._classGroup,\r\n });\r\n\r\n // add data to ul\r\n this._resultList.insertAdjacentHTML(\"afterbegin\", dataResults);\r\n\r\n // add class isActive\r\n classList(this._resultWrap, \"add\", this._isActive);\r\n\r\n const checkIfClassGroupExist = this._classGroup\r\n ? `:not(.${this._classGroup})`\r\n : \"\";\r\n\r\n this._itemsLi = document.querySelectorAll(\r\n `#${this._outputUl} > li${checkIfClassGroupExist}`\r\n );\r\n\r\n // adding role, tabindex and aria\r\n addAriaToAllLiElements(this._itemsLi);\r\n\r\n // action on open results\r\n this._onOpened({\r\n type: \"results\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n\r\n // select first element\r\n this._selectFirstElement();\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n };\r\n\r\n /**\r\n * Hangle click on document\r\n *\r\n * @param {Event} object\r\n */\r\n _handleDocClick = ({ target }) => {\r\n let disableClose = null;\r\n\r\n // if 'target' is a ul and 'disableCloseOnSelect'\r\n // is a 'true' set 'disableClose' on true\r\n if (\r\n (target.closest(\"ul\") && this._disable) ||\r\n // when class classDisableClose\r\n // then do not not close results\r\n target.closest(`.${this._prevClosing}`)\r\n ) {\r\n disableClose = true;\r\n }\r\n\r\n if (target.id !== this._id && !disableClose) {\r\n this._reset();\r\n return;\r\n }\r\n };\r\n\r\n /**\r\n * Select first element\r\n */\r\n _selectFirstElement = () => {\r\n this._removeAria(select(`.${this._activeList}`));\r\n\r\n if (!this._selectFirst) {\r\n return;\r\n }\r\n\r\n const { firstElementChild } = this._resultList;\r\n\r\n const classSelectFirst =\r\n this._classGroup && this._matches.length > 0 && this._selectFirst\r\n ? firstElementChild.nextElementSibling\r\n : firstElementChild;\r\n\r\n // calback function onSelect when first element is true\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set attribute to first element\r\n setAttributes(classSelectFirst, {\r\n id: `${this._selectedOption}-0`,\r\n addClass: this._activeList,\r\n \"aria-selected\": \"true\",\r\n });\r\n\r\n // set aria active descendant\r\n setAriaActivedescendant(this._root, `${this._selectedOption}-0`);\r\n };\r\n\r\n /**\r\n * show items when items.length > 0 and is not empty\r\n */\r\n _handleShowItems = () => {\r\n // if resultWrap is not active and resultList is not empty\r\n if (\r\n this._resultList.textContent.length > 0 &&\r\n !classList(this._resultWrap, \"contains\", this._isActive)\r\n ) {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add isActive class to resultWrap\r\n classList(this._resultWrap, \"add\", this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n\r\n // select first element\r\n this._selectFirstElement();\r\n\r\n // callback function\r\n this._onOpened({\r\n type: \"showItems\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Adding text from the list when li is clicking\r\n * or adding aria-selected to li elements\r\n *\r\n * @param {Event} event\r\n */\r\n _handleMouse = (event) => {\r\n event.preventDefault();\r\n\r\n const { target, type } = event;\r\n const targetClosest = target.closest(\"li\");\r\n const targetClosestRole = targetClosest?.hasAttribute(\"role\");\r\n const activeClass = this._activeList;\r\n const activeClassElement = select(`.${activeClass}`);\r\n\r\n if (!targetClosest || !targetClosestRole) {\r\n return;\r\n }\r\n\r\n // click on li get element\r\n if (type === \"click\") {\r\n // get text from clicked li\r\n this._getTextFromLi(targetClosest);\r\n }\r\n\r\n if (\r\n type === \"mousemove\" &&\r\n !classList(targetClosest, \"contains\", activeClass)\r\n ) {\r\n this._removeAria(activeClassElement);\r\n\r\n // add aria to li\r\n this._setAria(targetClosest);\r\n this._index = this._indexLiSelected(targetClosest);\r\n\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Get text from li on enter or click\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _getTextFromLi = (element) => {\r\n if (!element || this._matches.length === 0) {\r\n // set default settings\r\n !this._disable && this._reset();\r\n\r\n return;\r\n }\r\n\r\n // get first element from li and set it to root\r\n this._root.value = getFirstElement(element);\r\n\r\n // onSubmit passing text to function\r\n this._onSubmit({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n results: this._resultList,\r\n });\r\n\r\n // set default settings\r\n if (!this._disable) {\r\n this._removeAria(element);\r\n this._reset();\r\n }\r\n\r\n // show clearBtn when select element\r\n this._clearButton && classList(this._clearBtn, \"remove\", \"hidden\");\r\n\r\n // remove cache\r\n this._cacheAct(\"remove\");\r\n };\r\n\r\n /**\r\n * Return which li element was selected\r\n * by hovering the mouse over\r\n *\r\n * @param {HTMLElement} target\r\n * @returns {Number}\r\n */\r\n _indexLiSelected = (target) =>\r\n // get index of li element\r\n Array.prototype.indexOf.call(this._itemsLi, target);\r\n\r\n /**\r\n * Navigating the elements li and enter\r\n *\r\n * @param {Event} event\r\n */\r\n _handleKeys = (event) => {\r\n const { keyCode } = event;\r\n\r\n const resultList = classList(this._resultWrap, \"contains\", this._isActive);\r\n\r\n const matchesLength = this._matches.length + 1;\r\n this._selectedLi = select(`.${this._activeList}`);\r\n\r\n // switch between keys\r\n switch (keyCode) {\r\n case keyCodes.UP:\r\n case keyCodes.DOWN:\r\n // Wrong cursor position in the input field #62\r\n // Prevents the cursor from moving to the beginning\r\n // of input as the cursor hovers over the results.\r\n event.preventDefault();\r\n\r\n if ((matchesLength <= 1 && this._selectFirst) || !resultList) {\r\n return;\r\n }\r\n\r\n // if keyCode is up\r\n if (keyCode === keyCodes.UP) {\r\n if (this._index < 0) {\r\n this._index = matchesLength - 1;\r\n }\r\n this._index -= 1;\r\n } else {\r\n this._index += 1;\r\n if (this._index >= matchesLength) {\r\n this._index = 0;\r\n }\r\n }\r\n\r\n // remove aria-selected\r\n this._removeAria(this._selectedLi);\r\n\r\n if (this._index >= 0 && this._index < matchesLength - 1) {\r\n if (this._toInput && resultList) {\r\n this._root.value = getFirstElement(this._itemsLi[this._index]);\r\n }\r\n\r\n // callback function\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set aria-selected\r\n this._setAria(this._itemsLi[this._index]);\r\n } else {\r\n // catch action\r\n this._cacheAct();\r\n setAriaActivedescendant(this._root);\r\n\r\n this._onSelected({\r\n index: null,\r\n element: this._root,\r\n object: null,\r\n });\r\n }\r\n\r\n break;\r\n // keycode enter\r\n case keyCodes.ENTER:\r\n this._getTextFromLi(this._selectedLi);\r\n break;\r\n\r\n // keycode escape and keycode tab\r\n case keyCodes.TAB:\r\n case keyCodes.ESC:\r\n event.stopPropagation(); // #120\r\n this._reset();\r\n\r\n break;\r\n default:\r\n break;\r\n }\r\n };\r\n\r\n /**\r\n * Set aria label on item li\r\n *\r\n * @param {HTMLElement} target\r\n */\r\n _setAria = (target) => {\r\n const selectedOption = `${this._selectedOption}-${this._indexLiSelected(\r\n target\r\n )}`;\r\n\r\n // set aria to li\r\n setAttributes(target, {\r\n id: selectedOption,\r\n \"aria-selected\": \"true\",\r\n addClass: this._activeList,\r\n });\r\n\r\n setAriaActivedescendant(this._root, selectedOption);\r\n\r\n // scrollIntoView when press up/down arrows\r\n followActiveElement(\r\n target,\r\n this._outputUl,\r\n this._classGroup,\r\n this._resultList\r\n );\r\n };\r\n\r\n /**\r\n * Remove aria label from item li\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _removeAria = (element) => {\r\n if (!element) return;\r\n\r\n // remove aria from li\r\n setAttributes(element, {\r\n id: \"\",\r\n removeClass: this._activeList,\r\n \"aria-selected\": \"false\",\r\n });\r\n };\r\n\r\n /**\r\n * Create clear button and\r\n * removing text from the input field\r\n */\r\n _clearbutton = () => {\r\n // stop when clear button is disabled\r\n if (!this._clearButton) return;\r\n\r\n // add aria to clear button\r\n setAttributes(this._clearBtn, {\r\n class: `${this._prefix}-clear hidden`,\r\n type: \"button\",\r\n title: this._clearBtnAriLabel,\r\n \"aria-label\": this._clearBtnAriLabel,\r\n });\r\n\r\n // insert clear button after input - root\r\n this._root.insertAdjacentElement(\"afterend\", this._clearBtn);\r\n };\r\n\r\n /**\r\n * Clicking on the clear button\r\n * publick destroy method\r\n */\r\n destroy = () => {\r\n // if clear button is true then add class hidden\r\n this._clearButton && classList(this._clearBtn, \"add\", \"hidden\");\r\n // clear value searchId\r\n this._root.value = \"\";\r\n // set focus\r\n this._root.focus();\r\n // remove li from ul\r\n this._resultList.textContent = \"\";\r\n // set default aria\r\n this._reset();\r\n // remove error if exist\r\n this._error();\r\n\r\n // callback function\r\n this._onReset(this._root);\r\n\r\n // remove listener\r\n offEvent(this._root, \"keydown\", this._handleKeys);\r\n offEvent(this._root, \"click\", this._handleShowItems);\r\n // remove listener on click on document\r\n offEvent(document, \"click\", this._handleDocClick);\r\n };\r\n}\r\n"],"names":["isObject","value","constructor","Object","isPromise","Boolean","then","setAttributes","el","object","key","classList","setAttribute","getFirstElement","element","firstElementChild","textContent","trim","scrollResultsToTop","resultList","resultWrap","scrollTop","offsetTop","offsetHeight","addAriaToAllLiElements","itemsLi","i","length","role","tabindex","showBtnToClearData","clearButton","destroy","onEvent","action","className","setAriaActivedescendant","root","type","getClassGroupHeight","outputUl","classGroup","allLiElements","document","querySelectorAll","height","slice","call","map","followActiveElement","target","previusElement","previousSibling","previusElementHeight","getAttribute","offsetBottom","scrollBottom","output","prefix","id","tabIndex","addClass","insertAdjacentElement","parentNode","insertBefore","nextSibling","createElement","select","querySelector","callback","addEventListener","offEvent","removeEventListener","keyCodes","ESC","ENTER","UP","DOWN","TAB","Autocomplete","delay","howManyCharacters","selectFirst","insertToInput","showAllValues","cache","disableCloseOnSelect","classPreventClosing","classPrefix","ariaLabelClear","onSearch","onResults","onSubmit","onOpened","onReset","onRender","onClose","noResults","onSelectedItem","_initial","_clearbutton","_root","_resultList","_outputUl","_resultWrap","_prefix","_handleInput","_showAll","_onRender","results","_cacheAct","_cache","_cacheData","removeAttribute","regex","replace","_regex","_delay","clearTimeout","_timeout","setTimeout","_searchItem","_reset","_id","removeClass","_isActive","_index","_selectFirst","_onClose","_value","_onLoading","_clearBtn","_clearButton","_characters","_onSearch","currentValue","result","rootValueLength","resultLength","_matches","Array","isArray","JSON","parse","stringify","_error","_noResults","template","_results","_events","catch","_isLoading","_err","_handleKeys","_handleShowItems","eventType","_handleMouse","_handleDocClick","dataResults","_onResults","matches","_classGroup","insertAdjacentHTML","checkIfClassGroupExist","_itemsLi","_onOpened","_selectFirstElement","disableClose","closest","_disable","_prevClosing","_removeAria","_activeList","classSelectFirst","nextElementSibling","_onSelected","index","_selectedOption","event","preventDefault","targetClosest","targetClosestRole","hasAttribute","activeClass","activeClassElement","_getTextFromLi","_setAria","_indexLiSelected","_onSubmit","prototype","indexOf","keyCode","matchesLength","_selectedLi","_toInput","stopPropagation","selectedOption","class","title","_clearBtnAriLabel","focus","_onReset","getElementById","Promise","resolve"],"mappings":"AAKA,MAAMA,QAAQ,GAAIC,KAAD,IACfA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAA1B,IAAsCA,KAAK,CAACC,WAAN,KAAsBC,MAD9D;AAUA,MAAMC,SAAS,GAAIH,KAAD,IAAWI,OAAO,CAACJ,KAAK,IAAI,OAAOA,KAAK,CAACK,IAAb,KAAsB,UAAhC,CAApC;AAQA,MAAMC,aAAa,GAAG,CAACC,EAAD,EAAKC,MAAL,KAAgB;AACpC,OAAK,IAAIC,GAAT,IAAgBD,MAAhB,EAAwB;AACtB,QAAIC,GAAG,KAAK,UAAZ,EAAwB;AACtBC,MAAAA,SAAS,CAACH,EAAD,EAAK,KAAL,EAAYC,MAAM,CAACC,GAAD,CAAlB,CAAT;AACD,KAFD,MAEO,IAAIA,GAAG,KAAK,aAAZ,EAA2B;AAChCC,MAAAA,SAAS,CAACH,EAAD,EAAK,QAAL,EAAeC,MAAM,CAACC,GAAD,CAArB,CAAT;AACD,KAFM,MAEA;AACLF,MAAAA,EAAE,CAACI,YAAH,CAAgBF,GAAhB,EAAqBD,MAAM,CAACC,GAAD,CAA3B;AACD;AACF;AACF,CAVD;AAkBA,MAAMG,eAAe,GAAIC,OAAD,IACtB,CAACA,OAAO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ocomplete.esm.min.js b/dist/js/autocomplete.esm.min.js index 65663b4..f83242c 100644 --- a/dist/js/autocomplete.esm.min.js +++ b/dist/js/autocomplete.esm.min.js @@ -1 +1 @@ -const t=(t,s)=>{for(let i in s)"addClass"===i?t.classList.add(s[i]):"removeClass"===i?t.classList.remove(s[i]):t.setAttribute(i,s[i])},s=(t,s)=>s.value=(t=>t.firstElementChild||t)(t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=(t,s)=>{t.setAttribute("aria-activedescendant",s||"")},e=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll("#"+t+" > li:not(."+s+")");let h=0;return[].slice.call(i).map(t=>h+=t.offsetHeight),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},a=t=>document.createElement(t),l=27,n=13,o=38,r=40,c=9;class d{constructor(d,u){let{delay:m=500,clearButton:p=!0,howManyCharacters:b=1,selectFirst:x=!1,insertToInput:f=!1,showAllValues:v=!1,cache:C=!1,disableCloseOnSelect:y=!1,classGroup:k,classPreventClosing:w,classPrefix:j,ariaLabelClear:V,onSearch:g,onResults:S=(()=>{}),onSubmit:O=(()=>{}),onOpened:I=(()=>{}),onReset:R=(()=>{}),onRender:A=(()=>{}),onClose:P=(()=>{}),noResults:T=(()=>{}),onSelectedItem:B=(()=>{})}=u;var G;this.t=()=>{var s,i,h,e,a;this.s(),s=this.i,i=this.h,h=this.l,e=this.o,a=this.u,t(i,{id:h,tabIndex:"0",role:"listbox"}),t(e,{addClass:a+"-results-wrapper"}),e.insertAdjacentElement("beforeend",i),s.parentNode.insertBefore(e,s.nextSibling),this.i.addEventListener("input",this.m),this.p&&this.i.addEventListener("click",this.m),this.v({element:this.i,results:this.h})},this.C=(t,s)=>{this.k&&("update"===t?this.i.setAttribute(this.j,s.value):"remove"===t?this.i.removeAttribute(this.j):this.i.value=this.i.getAttribute(this.j))},this.m=t=>{let{target:s,type:i}=t;if("true"===this.i.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.V,"\\$&");this.C("update",s);const e=this.p?0:this.g;clearTimeout(this.S),this.S=setTimeout(()=>{this.O(h.trim())},e)},this.I=()=>{var s;t(this.i,{"aria-owns":this.R+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),this.o.classList.remove(this.A),(0==(null==(s=this.P)?void 0:s.length)&&!this.T||this.p)&&(this.h.innerHTML=""),this.B=this.G?0:-1,this.J()},this.O=t=>{this.N=t,this.$(!0),function(t,s){void 0===t&&(t=!1),t&&(t.classList.remove("hidden"),t.addEventListener("click",s))}(this.q,this.destroy),0==t.length&&this.F&&this.q.classList.add("hidden"),this.L>t.length&&!this.p?this.$():this.M({currentValue:t,element:this.i}).then(s=>{const i=this.i.value.length,h=s.length;this.P=Array.isArray(s)?[...s]:JSON.parse(JSON.stringify(s)),this.$(),this.D(),0==h&&0==i&&this.q.classList.add("hidden"),0==h&&i?(this.i.classList.remove("auto-expanded"),this.I(),this.H({element:this.i,currentValue:t,template:this.K}),this.U()):(h>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.B=this.G?0:-1,this.K(),this.U())}).catch(()=>{this.$(),this.I()})},this.$=t=>this.i.parentNode.classList[t?"add":"remove"](this.W),this.D=()=>this.i.classList.remove(this.X),this.U=()=>{this.i.addEventListener("keydown",this.Y),this.i.addEventListener("click",this.Z),["mousemove","click"].map(t=>{this.h.addEventListener(t,this._)}),document.addEventListener("click",this.tt)},this.K=s=>{t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.h.innerHTML=0===this.P.length?this.st({currentValue:this.N,matches:0,template:s}):this.st({currentValue:this.N,matches:this.P,classGroup:this.it}),this.o.classList.add(this.A);const h=this.it?":not(."+this.it+")":"";this.ht=document.querySelectorAll("#"+this.l+" > li"+h),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.lt||s.closest("."+this.nt))&&(i=!0),s.id===this.R||i||this.I()},this.at=()=>{if(this.ot(document.querySelector("."+this.rt)),!this.G)return;const{firstElementChild:s}=this.h,i=this.it&&this.P.length>0&&this.G?s.nextElementSibling:s;this.ct({index:this.B,element:this.i,object:this.P[this.B]}),t(i,{id:this.dt+"-0",addClass:this.rt,"aria-selected":"true"}),h(this.i,this.dt+"-0")},this.Z=()=>{this.h.textContent.length>0&&!this.o.classList.contains(this.A)&&(t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.o.classList.add(this.A),i(this.h,this.o),this.at(),this.et({type:"showItems",element:this.i,results:this.h}))},this._=t=>{t.preventDefault();const{target:s,type:i}=t,h=s.closest("li"),e=null==h?void 0:h.hasAttribute("role"),a=this.rt,l=document.querySelector("."+a);h&&e&&("click"===i&&this.ut(h),"mousemove"!==i||h.classList.contains(a)||(this.ot(l),this.pt(h),this.B=this.bt(h),this.ct({index:this.B,element:this.i,object:this.P[this.B]})))},this.ut=t=>{t&&0!==this.P.length?(s(t,this.i),this.xt({index:this.B,element:this.i,object:this.P[this.B],results:this.h}),this.lt||(this.ot(t),this.I()),this.F&&this.q.classList.remove("hidden"),this.C("remove")):!this.lt&&this.I()},this.bt=t=>Array.prototype.indexOf.call(this.ht,t),this.Y=t=>{const{keyCode:i}=t,e=this.o.classList.contains(this.A),a=this.P.length+1;switch(this.ft=document.querySelector("."+this.rt),i){case o:case r:if(t.preventDefault(),a<=1&&this.G||!e)return;i===o?(this.B<0&&(this.B=a-1),this.B-=1):(this.B+=1,this.B>=a&&(this.B=0)),this.ot(this.ft),a>0&&this.B>=0&&this.B{const i=this.dt+"-"+this.bt(s);t(s,{id:i,"aria-selected":"true",addClass:this.rt}),h(this.i,i),e(s,this.l,this.it,this.h)},this.ot=s=>{s&&t(s,{id:"",removeClass:this.rt,"aria-selected":"false"})},this.s=()=>{this.F&&(t(this.q,{class:this.u+"-clear hidden",type:"button",title:this.vt,"aria-label":this.vt}),this.i.insertAdjacentElement("afterend",this.q))},this.destroy=()=>{this.F&&this.q.classList.add("hidden"),this.i.value="",this.i.focus(),this.h.textContent="",this.I(),this.D(),this.Ct(this.i),this.i.removeEventListener("keydown",this.Y),this.i.removeEventListener("click",this.Z),document.removeEventListener("click",this.tt)},this.R=d,this.i=document.getElementById(d),this.M=(G=g,Boolean(G&&"function"==typeof G.then)?g:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(g({currentValue:s,element:i}))}),this.st=S,this.v=A,this.xt=O,this.ct=B,this.et=I,this.Ct=R,this.H=T,this.J=P,this.g=m,this.L=b,this.F=p,this.G=x,this.T=f,this.p=v,this.it=k,this.nt=w,this.vt=V||"clear the search query",this.u=j?j+"-auto":"auto",this.lt=y,this.k=C,this.l=this.u+"-"+this.R+"-results",this.j="data-cache-auto-"+this.R,this.W=this.u+"-is-loading",this.A=this.u+"-is-active",this.rt=this.u+"-selected",this.dt=this.u+"-selected-option",this.X=this.u+"-error",this.V=/[|\\{}()[\]^$+*?.]/g,this.S=null,this.o=a("div"),this.h=a("ul"),this.q=a("button"),this.t()}}export{d as default}; +const t=(t,s)=>{for(let i in s)"addClass"===i?h(t,"add",s[i]):"removeClass"===i?h(t,"remove",s[i]):t.setAttribute(i,s[i])},s=t=>(t.firstElementChild||t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=(t,s,i)=>t.classList[s](i),e=(s,i)=>{t(s,{"aria-activedescendant":i||""})},a=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll("#"+t+" > li:not(."+s+")");let h=0;return[].slice.call(i).map(t=>h+=t.offsetHeight),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},n=t=>document.createElement(t),l=t=>document.querySelector(t),o=(t,s,i)=>{t.addEventListener(s,i)},r=(t,s,i)=>{t.removeEventListener(s,i)},c=27,d=13,u=38,m=40,p=9;class b{constructor(b,v){let{delay:f=500,clearButton:x=!0,howManyCharacters:C=1,selectFirst:y=!1,insertToInput:k=!1,showAllValues:w=!1,cache:g=!1,disableCloseOnSelect:j=!1,classGroup:V,classPreventClosing:S,classPrefix:O,ariaLabelClear:I,onSearch:R,onResults:A=(()=>{}),onSubmit:P=(()=>{}),onOpened:T=(()=>{}),onReset:B=(()=>{}),onRender:G=(()=>{}),onClose:J=(()=>{}),noResults:N=(()=>{}),onSelectedItem:$=(()=>{})}=v;var q;this.t=()=>{var s,i,h,e,a;this.s(),s=this.i,i=this.h,h=this.l,e=this.o,a=this.u,t(i,{id:h,tabIndex:"0",role:"listbox"}),t(e,{addClass:a+"-results-wrapper"}),e.insertAdjacentElement("beforeend",i),s.parentNode.insertBefore(e,s.nextSibling),o(this.i,"input",this.m),this.p&&o(this.i,"click",this.m),this.v({element:this.i,results:this.h})},this.C=(t,s)=>{this.k&&("update"===t?this.i.setAttribute(this.g,s.value):"remove"===t?this.i.removeAttribute(this.g):this.i.value=this.i.getAttribute(this.g))},this.m=t=>{let{target:s,type:i}=t;if("true"===this.i.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.j,"\\$&");this.C("update",s);const e=this.p?0:this.V;clearTimeout(this.S),this.S=setTimeout(()=>{this.O(h.trim())},e)},this.I=()=>{t(this.i,{"aria-owns":this.R+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),h(this.o,"remove",this.A),this.P=this.T?0:-1,this.B()},this.O=t=>{this.G=t,this.J(!0),function(t,s){void 0===t&&(t=!1),t&&(h(t,"remove","hidden"),o(t,"click",s))}(this.N,this.destroy),0==t.length&&this.$&&h(this.N,"add","hidden"),this.q>t.length&&!this.p?this.J():this.F({currentValue:t,element:this.i}).then(s=>{const i=this.i.value.length,e=s.length;this.L=Array.isArray(s)?s:JSON.parse(JSON.stringify(s)),this.J(),this.M(),0==e&&0==i&&h(this.N,"add","hidden"),0==e&&i?(h(this.i,"remove","auto-expanded"),this.I(),this.D({element:this.i,currentValue:t,template:this.H}),this.K()):(e>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.P=this.T?0:-1,this.H(),this.K())}).catch(()=>{this.J(),this.I()})},this.J=t=>this.i.parentNode.classList[t?"add":"remove"](this.U),this.M=()=>h(this.i,"remove",this.W),this.K=()=>{o(this.i,"keydown",this.X),o(this.i,"click",this.Y),["mousemove","click"].map(t=>{o(this.h,t,this.Z)}),o(document,"click",this._)},this.H=s=>{t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.h.textContent="";const e=0===this.L.length?this.tt({currentValue:this.G,matches:0,template:s}):this.tt({currentValue:this.G,matches:this.L,classGroup:this.st});this.h.insertAdjacentHTML("afterbegin",e),h(this.o,"add",this.A);const a=this.st?":not(."+this.st+")":"";this.it=document.querySelectorAll("#"+this.l+" > li"+a),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.at||s.closest("."+this.nt))&&(i=!0),s.id===this.R||i||this.I()},this.et=()=>{if(this.lt(l("."+this.ot)),!this.T)return;const{firstElementChild:s}=this.h,i=this.st&&this.L.length>0&&this.T?s.nextElementSibling:s;this.rt({index:this.P,element:this.i,object:this.L[this.P]}),t(i,{id:this.ct+"-0",addClass:this.ot,"aria-selected":"true"}),e(this.i,this.ct+"-0")},this.Y=()=>{this.h.textContent.length>0&&!h(this.o,"contains",this.A)&&(t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),h(this.o,"add",this.A),i(this.h,this.o),this.et(),this.ht({type:"showItems",element:this.i,results:this.h}))},this.Z=t=>{t.preventDefault();const{target:s,type:i}=t,e=s.closest("li"),a=null==e?void 0:e.hasAttribute("role"),n=this.ot,o=l("."+n);e&&a&&("click"===i&&this.dt(e),"mousemove"!==i||h(e,"contains",n)||(this.lt(o),this.ut(e),this.P=this.pt(e),this.rt({index:this.P,element:this.i,object:this.L[this.P]})))},this.dt=t=>{t&&0!==this.L.length?(this.i.value=s(t),this.bt({index:this.P,element:this.i,object:this.L[this.P],results:this.h}),this.at||(this.lt(t),this.I()),this.$&&h(this.N,"remove","hidden"),this.C("remove")):!this.at&&this.I()},this.pt=t=>Array.prototype.indexOf.call(this.it,t),this.X=t=>{const{keyCode:i}=t,a=h(this.o,"contains",this.A),n=this.L.length+1;switch(this.vt=l("."+this.ot),i){case u:case m:if(t.preventDefault(),n<=1&&this.T||!a)return;i===u?(this.P<0&&(this.P=n-1),this.P-=1):(this.P+=1,this.P>=n&&(this.P=0)),this.lt(this.vt),this.P>=0&&this.P{const i=this.ct+"-"+this.pt(s);t(s,{id:i,"aria-selected":"true",addClass:this.ot}),e(this.i,i),a(s,this.l,this.st,this.h)},this.lt=s=>{s&&t(s,{id:"",removeClass:this.ot,"aria-selected":"false"})},this.s=()=>{this.$&&(t(this.N,{class:this.u+"-clear hidden",type:"button",title:this.xt,"aria-label":this.xt}),this.i.insertAdjacentElement("afterend",this.N))},this.destroy=()=>{this.$&&h(this.N,"add","hidden"),this.i.value="",this.i.focus(),this.h.textContent="",this.I(),this.M(),this.Ct(this.i),r(this.i,"keydown",this.X),r(this.i,"click",this.Y),r(document,"click",this._)},this.R=b,this.i=document.getElementById(b),this.F=(q=R,Boolean(q&&"function"==typeof q.then)?R:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(R({currentValue:s,element:i}))}),this.tt=A,this.v=G,this.bt=P,this.rt=$,this.ht=T,this.Ct=B,this.D=N,this.B=J,this.V=f,this.q=C,this.$=x,this.T=y,this.ft=k,this.p=w,this.st=V,this.nt=S,this.xt=I||"clear the search query",this.u=O?O+"-auto":"auto",this.at=j,this.k=g,this.l=this.u+"-"+this.R+"-results",this.g="data-cache-auto-"+this.R,this.U=this.u+"-is-loading",this.A=this.u+"-is-active",this.ot=this.u+"-selected",this.ct=this.u+"-selected-option",this.W=this.u+"-error",this.j=/[|\\{}()[\]^$+*?.]/g,this.S=null,this.o=n("div"),this.h=n("ul"),this.N=n("button"),this.t()}}export{b as default}; diff --git a/dist/js/autocomplete.ie.min.js b/dist/js/autocomplete.ie.min.js index 217348b..b5df76c 100644 --- a/dist/js/autocomplete.ie.min.js +++ b/dist/js/autocomplete.ie.min.js @@ -1 +1 @@ -var Autocomplete=function(){"use strict";var t=function(t,e){for(var i in e)"addClass"===i?t.classList.add(e[i]):"removeClass"===i?t.classList.remove(e[i]):t.setAttribute(i,e[i])},e=function(t,e){return e.value=function(t){return t.firstElementChild||t}(t).textContent.trim()},i=function(t,e){t.scrollTop=t.offsetTop-e.offsetHeight},n=function(t,e){t.setAttribute("aria-activedescendant",e||"")},s=function(t,e,i,n){var s=n.previousSibling,o=s?s.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(n.scrollTop=t.offsetTop-function(t,e){var i=document.querySelectorAll("#"+t+" > li:not(."+e+")"),n=0;return[].slice.call(i).map((function(t){return n+=t.offsetHeight})),n}(e,i)),t.offsetTop-on.scrollTop+n.offsetHeight&&(n.scrollTop=a-n.offsetHeight)}},o=function(t){return document.createElement(t)},a=27,c=13,u=38,r=40,d=9;return function(l,h){var f,v=this,m=h.delay,p=void 0===m?500:m,b=h.clearButton,x=void 0===b||b,k=h.howManyCharacters,y=void 0===k?1:k,C=h.selectFirst,j=void 0!==C&&C,w=h.insertToInput,V=void 0!==w&&w,A=h.showAllValues,O=void 0!==A&&A,g=h.cache,I=void 0!==g&&g,J=h.disableCloseOnSelect,N=void 0!==J&&J,S=h.classGroup,T=h.classPreventClosing,$=h.classPrefix,q=h.ariaLabelClear,z=h.onSearch,B=h.onResults,G=void 0===B?function(){}:B,P=h.onSubmit,D=void 0===P?function(){}:P,E=h.onOpened,F=void 0===E?function(){}:E,H=h.onReset,K=void 0===H?function(){}:H,L=h.onRender,M=void 0===L?function(){}:L,Q=h.onClose,R=void 0===Q?function(){}:Q,U=h.noResults,W=void 0===U?function(){}:U,X=h.onSelectedItem,Y=void 0===X?function(){}:X;this.t=function(){var e,i,n,s,o;v.i(),e=v.s,i=v.o,n=v.u,s=v.l,o=v.h,t(i,{id:n,tabIndex:"0",role:"listbox"}),t(s,{addClass:o+"-results-wrapper"}),s.insertAdjacentElement("beforeend",i),e.parentNode.insertBefore(s,e.nextSibling),v.s.addEventListener("input",v.v),v.m&&v.s.addEventListener("click",v.v),v.p({element:v.s,results:v.o})},this.k=function(t,e){v.C&&("update"===t?v.s.setAttribute(v.j,e.value):"remove"===t?v.s.removeAttribute(v.j):v.s.value=v.s.getAttribute(v.j))},this.v=function(t){var e=t.target,i=t.type;if("true"!==v.s.getAttribute("aria-expanded")||"click"!==i){var n=e.value.replace(v.V,"\\$&");v.k("update",e);var s=v.m?0:v.A;clearTimeout(v.O),v.O=setTimeout((function(){v.g(n.trim())}),s)}},this.I=function(){var e;t(v.s,{"aria-owns":v.J+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),v.l.classList.remove(v.N),(0==(null==(e=v.S)?void 0:e.length)&&!v.T||v.m)&&(v.o.innerHTML=""),v.$=v.q?0:-1,v.B()},this.g=function(t){v.G=t,v.P(!0),function(t,e){void 0===t&&(t=!1),t&&(t.classList.remove("hidden"),t.addEventListener("click",e))}(v.D,v.destroy),0==t.length&&v.F&&v.D.classList.add("hidden"),v.H>t.length&&!v.m?v.P():v.K({currentValue:t,element:v.s}).then((function(e){var i=v.s.value.length,n=e.length;v.S=Array.isArray(e)?[].concat(e):JSON.parse(JSON.stringify(e)),v.P(),v.L(),0==n&&0==i&&v.D.classList.add("hidden"),0==n&&i?(v.s.classList.remove("auto-expanded"),v.I(),v.M({element:v.s,currentValue:t,template:v.R}),v.U()):(n>0||function(t){return t&&"object"==typeof t&&t.constructor===Object}(e))&&(v.$=v.q?0:-1,v.R(),v.U())})).catch((function(){v.P(),v.I()}))},this.P=function(t){return v.s.parentNode.classList[t?"add":"remove"](v.W)},this.L=function(){return v.s.classList.remove(v.X)},this.U=function(){v.s.addEventListener("keydown",v.Y),v.s.addEventListener("click",v.Z),["mousemove","click"].map((function(t){v.o.addEventListener(t,v._)})),document.addEventListener("click",v.tt)},this.R=function(e){t(v.s,{"aria-expanded":"true",addClass:v.h+"-expanded"}),v.o.innerHTML=0===v.S.length?v.et({currentValue:v.G,matches:0,template:e}):v.et({currentValue:v.G,matches:v.S,classGroup:v.it}),v.l.classList.add(v.N);var n=v.it?":not(."+v.it+")":"";v.nt=document.querySelectorAll("#"+v.u+" > li"+n),function(e){for(var i=0;i0&&v.q?e.nextElementSibling:e;v.dt({index:v.$,element:v.s,object:v.S[v.$]}),t(i,{id:v.lt+"-0",addClass:v.rt,"aria-selected":"true"}),n(v.s,v.lt+"-0")}},this.Z=function(){v.o.textContent.length>0&&!v.l.classList.contains(v.N)&&(t(v.s,{"aria-expanded":"true",addClass:v.h+"-expanded"}),v.l.classList.add(v.N),i(v.o,v.l),v.ot(),v.st({type:"showItems",element:v.s,results:v.o}))},this._=function(t){t.preventDefault();var e=t.target,i=t.type,n=e.closest("li"),s=null==n?void 0:n.hasAttribute("role"),o=v.rt,a=document.querySelector("."+o);n&&s&&("click"===i&&v.ht(n),"mousemove"!==i||n.classList.contains(o)||(v.ut(a),v.ft(n),v.$=v.vt(n),v.dt({index:v.$,element:v.s,object:v.S[v.$]})))},this.ht=function(t){t&&0!==v.S.length?(e(t,v.s),v.pt({index:v.$,element:v.s,object:v.S[v.$],results:v.o}),v.at||(v.ut(t),v.I()),v.F&&v.D.classList.remove("hidden"),v.k("remove")):!v.at&&v.I()},this.vt=function(t){return Array.prototype.indexOf.call(v.nt,t)},this.Y=function(t){var i=t.keyCode,s=v.l.classList.contains(v.N),o=v.S.length+1;switch(v.bt=document.querySelector("."+v.rt),i){case u:case r:if(t.preventDefault(),o<=1&&v.q||!s)return;i===u?(v.$<0&&(v.$=o-1),v.$-=1):(v.$+=1,v.$>=o&&(v.$=0)),v.ut(v.bt),o>0&&v.$>=0&&v.$ li:not(."+e+")"),n=0;return[].slice.call(i).map((function(t){return n+=t.offsetHeight})),n}(e,i)),t.offsetTop-on.scrollTop+n.offsetHeight&&(n.scrollTop=a-n.offsetHeight)}},a=function(t){return document.createElement(t)},r=function(t){return document.querySelector(t)},c=function(t,e,i){t.addEventListener(e,i)},u=function(t,e,i){t.removeEventListener(e,i)},d=27,l=13,h=38,f=40,v=9;return function(m,p){var b,x=this,k=p.delay,y=void 0===k?500:k,C=p.clearButton,j=void 0===C||C,w=p.howManyCharacters,V=void 0===w?1:w,g=p.selectFirst,A=void 0!==g&&g,O=p.insertToInput,I=void 0!==O&&O,J=p.showAllValues,N=void 0!==J&&J,S=p.cache,T=void 0!==S&&S,$=p.disableCloseOnSelect,q=void 0!==$&&$,z=p.classGroup,B=p.classPreventClosing,G=p.classPrefix,P=p.ariaLabelClear,D=p.onSearch,E=p.onResults,F=void 0===E?function(){}:E,H=p.onSubmit,K=void 0===H?function(){}:H,L=p.onOpened,M=void 0===L?function(){}:L,Q=p.onReset,R=void 0===Q?function(){}:Q,U=p.onRender,W=void 0===U?function(){}:U,X=p.onClose,Y=void 0===X?function(){}:X,Z=p.noResults,_=void 0===Z?function(){}:Z,tt=p.onSelectedItem,et=void 0===tt?function(){}:tt;this.t=function(){var e,i,n,s,o;x.i(),e=x.s,i=x.o,n=x.u,s=x.l,o=x.h,t(i,{id:n,tabIndex:"0",role:"listbox"}),t(s,{addClass:o+"-results-wrapper"}),s.insertAdjacentElement("beforeend",i),e.parentNode.insertBefore(s,e.nextSibling),c(x.s,"input",x.v),x.m&&c(x.s,"click",x.v),x.p({element:x.s,results:x.o})},this.k=function(t,e){x.C&&("update"===t?x.s.setAttribute(x.j,e.value):"remove"===t?x.s.removeAttribute(x.j):x.s.value=x.s.getAttribute(x.j))},this.v=function(t){var e=t.target,i=t.type;if("true"!==x.s.getAttribute("aria-expanded")||"click"!==i){var n=e.value.replace(x.V,"\\$&");x.k("update",e);var s=x.m?0:x.g;clearTimeout(x.A),x.A=setTimeout((function(){x.O(n.trim())}),s)}},this.I=function(){t(x.s,{"aria-owns":x.J+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),n(x.l,"remove",x.N),x.S=x.T?0:-1,x.$()},this.O=function(t){x.q=t,x.B(!0),function(t,e){void 0===t&&(t=!1),t&&(n(t,"remove","hidden"),c(t,"click",e))}(x.G,x.destroy),0==t.length&&x.P&&n(x.G,"add","hidden"),x.D>t.length&&!x.m?x.B():x.F({currentValue:t,element:x.s}).then((function(e){var i=x.s.value.length,s=e.length;x.H=Array.isArray(e)?e:JSON.parse(JSON.stringify(e)),x.B(),x.K(),0==s&&0==i&&n(x.G,"add","hidden"),0==s&&i?(n(x.s,"remove","auto-expanded"),x.I(),x.L({element:x.s,currentValue:t,template:x.M}),x.R()):(s>0||function(t){return t&&"object"==typeof t&&t.constructor===Object}(e))&&(x.S=x.T?0:-1,x.M(),x.R())})).catch((function(){x.B(),x.I()}))},this.B=function(t){return x.s.parentNode.classList[t?"add":"remove"](x.U)},this.K=function(){return n(x.s,"remove",x.W)},this.R=function(){c(x.s,"keydown",x.X),c(x.s,"click",x.Y),["mousemove","click"].map((function(t){c(x.o,t,x.Z)})),c(document,"click",x._)},this.M=function(e){t(x.s,{"aria-expanded":"true",addClass:x.h+"-expanded"}),x.o.textContent="";var s=0===x.H.length?x.tt({currentValue:x.q,matches:0,template:e}):x.tt({currentValue:x.q,matches:x.H,classGroup:x.et});x.o.insertAdjacentHTML("afterbegin",s),n(x.l,"add",x.N);var o=x.et?":not(."+x.et+")":"";x.it=document.querySelectorAll("#"+x.u+" > li"+o),function(e){for(var i=0;i0&&x.T?e.nextElementSibling:e;x.ut({index:x.S,element:x.s,object:x.H[x.S]}),t(i,{id:x.dt+"-0",addClass:x.ct,"aria-selected":"true"}),s(x.s,x.dt+"-0")}},this.Y=function(){x.o.textContent.length>0&&!n(x.l,"contains",x.N)&&(t(x.s,{"aria-expanded":"true",addClass:x.h+"-expanded"}),n(x.l,"add",x.N),i(x.o,x.l),x.st(),x.nt({type:"showItems",element:x.s,results:x.o}))},this.Z=function(t){t.preventDefault();var e=t.target,i=t.type,s=e.closest("li"),o=null==s?void 0:s.hasAttribute("role"),a=x.ct,c=r("."+a);s&&o&&("click"===i&&x.lt(s),"mousemove"!==i||n(s,"contains",a)||(x.rt(c),x.ht(s),x.S=x.ft(s),x.ut({index:x.S,element:x.s,object:x.H[x.S]})))},this.lt=function(t){t&&0!==x.H.length?(x.s.value=e(t),x.vt({index:x.S,element:x.s,object:x.H[x.S],results:x.o}),x.ot||(x.rt(t),x.I()),x.P&&n(x.G,"remove","hidden"),x.k("remove")):!x.ot&&x.I()},this.ft=function(t){return Array.prototype.indexOf.call(x.it,t)},this.X=function(t){var i=t.keyCode,o=n(x.l,"contains",x.N),a=x.H.length+1;switch(x.pt=r("."+x.ct),i){case h:case f:if(t.preventDefault(),a<=1&&x.T||!o)return;i===h?(x.S<0&&(x.S=a-1),x.S-=1):(x.S+=1,x.S>=a&&(x.S=0)),x.rt(x.pt),x.S>=0&&x.S { for (let key in object) { if (key === "addClass") { - el.classList.add(object[key]); + classList(el, "add", object[key]); } else if (key === "removeClass") { - el.classList.remove(object[key]); + classList(el, "remove", object[key]); } else { el.setAttribute(key, object[key]); } } }; - const getFirstElement = element => element.firstElementChild || element; - const getFirstElementFromLiAndAddToInput = (element, root) => - root.value = getFirstElement(element).textContent.trim(); + const getFirstElement = element => (element.firstElementChild || element).textContent.trim(); const scrollResultsToTop = (resultList, resultWrap) => { resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight; }; @@ -36,16 +34,19 @@ var Autocomplete = (function () { clearButton = false; } if (!clearButton) return; - clearButton.classList.remove("hidden"); - clearButton.addEventListener("click", destroy); + classList(clearButton, "remove", "hidden"); + onEvent(clearButton, "click", destroy); }; + const classList = (element, action, className) => element.classList[action](className); const setAriaActivedescendant = (root, type) => { - root.setAttribute("aria-activedescendant", type || ""); + setAttributes(root, { + "aria-activedescendant": type || "" + }); }; const getClassGroupHeight = (outputUl, classGroup) => { - const allLi = document.querySelectorAll("#" + outputUl + " > li:not(." + classGroup + ")"); + const allLiElements = document.querySelectorAll("#" + outputUl + " > li:not(." + classGroup + ")"); let height = 0; - [].slice.call(allLi).map(el => height += el.offsetHeight); + [].slice.call(allLiElements).map(el => height += el.offsetHeight); return height; }; const followActiveElement = (target, outputUl, classGroup, resultList) => { @@ -77,6 +78,13 @@ var Autocomplete = (function () { root.parentNode.insertBefore(resultWrap, root.nextSibling); }; const createElement = type => document.createElement(type); + const select = element => document.querySelector(element); + const onEvent = (element, action, callback) => { + element.addEventListener(action, callback); + }; + const offEvent = (element, action, callback) => { + element.removeEventListener(action, callback); + }; const keyCodes = { ESC: 27, @@ -114,8 +122,8 @@ var Autocomplete = (function () { this._initial = () => { this._clearbutton(); output(this._root, this._resultList, this._outputUl, this._resultWrap, this._prefix); - this._root.addEventListener("input", this._handleInput); - this._showAll && this._root.addEventListener("click", this._handleInput); + onEvent(this._root, "input", this._handleInput); + this._showAll && onEvent(this._root, "click", this._handleInput); this._onRender({ element: this._root, results: this._resultList @@ -148,7 +156,6 @@ var Autocomplete = (function () { }, delay); }; this._reset = () => { - var _this$_matches; setAttributes(this._root, { "aria-owns": this._id + "-list", "aria-expanded": "false", @@ -157,19 +164,16 @@ var Autocomplete = (function () { role: "combobox", removeClass: "auto-expanded" }); - this._resultWrap.classList.remove(this._isActive); - if (((_this$_matches = this._matches) == null ? void 0 : _this$_matches.length) == 0 && !this._toInput || this._showAll) { - this._resultList.innerHTML = ""; - } + classList(this._resultWrap, "remove", this._isActive); this._index = this._selectFirst ? 0 : -1; this._onClose(); }; this._searchItem = value => { this._value = value; this._onLoading(true); - showBtnToClearData(this._cBtn, this.destroy); + showBtnToClearData(this._clearBtn, this.destroy); if (value.length == 0 && this._clearButton) { - this._cBtn.classList.add("hidden"); + classList(this._clearBtn, "add", "hidden"); } if (this._characters > value.length && !this._showAll) { this._onLoading(); @@ -181,14 +185,14 @@ var Autocomplete = (function () { }).then(result => { const rootValueLength = this._root.value.length; const resultLength = result.length; - this._matches = Array.isArray(result) ? [...result] : JSON.parse(JSON.stringify(result)); + this._matches = Array.isArray(result) ? result : JSON.parse(JSON.stringify(result)); this._onLoading(); this._error(); if (resultLength == 0 && rootValueLength == 0) { - this._cBtn.classList.add("hidden"); + classList(this._clearBtn, "add", "hidden"); } if (resultLength == 0 && rootValueLength) { - this._root.classList.remove("auto-expanded"); + classList(this._root, "remove", "auto-expanded"); this._reset(); this._noResults({ element: this._root, @@ -207,21 +211,22 @@ var Autocomplete = (function () { }); }; this._onLoading = type => this._root.parentNode.classList[type ? "add" : "remove"](this._isLoading); - this._error = () => this._root.classList.remove(this._err); + this._error = () => classList(this._root, "remove", this._err); this._events = () => { - this._root.addEventListener("keydown", this._handleKeys); - this._root.addEventListener("click", this._handleShowItems); + onEvent(this._root, "keydown", this._handleKeys); + onEvent(this._root, "click", this._handleShowItems); ["mousemove", "click"].map(eventType => { - this._resultList.addEventListener(eventType, this._handleMouse); + onEvent(this._resultList, eventType, this._handleMouse); }); - document.addEventListener("click", this._handleDocClick); + onEvent(document, "click", this._handleDocClick); }; this._results = template => { setAttributes(this._root, { "aria-expanded": "true", addClass: this._prefix + "-expanded" }); - this._resultList.innerHTML = this._matches.length === 0 ? this._onResults({ + this._resultList.textContent = ""; + const dataResults = this._matches.length === 0 ? this._onResults({ currentValue: this._value, matches: 0, template @@ -230,7 +235,8 @@ var Autocomplete = (function () { matches: this._matches, classGroup: this._classGroup }); - this._resultWrap.classList.add(this._isActive); + this._resultList.insertAdjacentHTML("afterbegin", dataResults); + classList(this._resultWrap, "add", this._isActive); const checkIfClassGroupExist = this._classGroup ? ":not(." + this._classGroup + ")" : ""; this._itemsLi = document.querySelectorAll("#" + this._outputUl + " > li" + checkIfClassGroupExist); addAriaToAllLiElements(this._itemsLi); @@ -239,7 +245,7 @@ var Autocomplete = (function () { element: this._root, results: this._resultList }); - this._selectFirstEl(); + this._selectFirstElement(); scrollResultsToTop(this._resultList, this._resultWrap); }; this._handleDocClick = _ref3 => { @@ -256,8 +262,8 @@ var Autocomplete = (function () { return; } }; - this._selectFirstEl = () => { - this._remAria(document.querySelector("." + this._activeList)); + this._selectFirstElement = () => { + this._removeAria(select("." + this._activeList)); if (!this._selectFirst) { return; } @@ -278,14 +284,14 @@ var Autocomplete = (function () { setAriaActivedescendant(this._root, this._selectedOption + "-0"); }; this._handleShowItems = () => { - if (this._resultList.textContent.length > 0 && !this._resultWrap.classList.contains(this._isActive)) { + if (this._resultList.textContent.length > 0 && !classList(this._resultWrap, "contains", this._isActive)) { setAttributes(this._root, { "aria-expanded": "true", addClass: this._prefix + "-expanded" }); - this._resultWrap.classList.add(this._isActive); + classList(this._resultWrap, "add", this._isActive); scrollResultsToTop(this._resultList, this._resultWrap); - this._selectFirstEl(); + this._selectFirstElement(); this._onOpened({ type: "showItems", element: this._root, @@ -302,15 +308,15 @@ var Autocomplete = (function () { const targetClosest = target.closest("li"); const targetClosestRole = targetClosest == null ? void 0 : targetClosest.hasAttribute("role"); const activeClass = this._activeList; - const activeClassElement = document.querySelector("." + activeClass); + const activeClassElement = select("." + activeClass); if (!targetClosest || !targetClosestRole) { return; } if (type === "click") { this._getTextFromLi(targetClosest); } - if (type === "mousemove" && !targetClosest.classList.contains(activeClass)) { - this._remAria(activeClassElement); + if (type === "mousemove" && !classList(targetClosest, "contains", activeClass)) { + this._removeAria(activeClassElement); this._setAria(targetClosest); this._index = this._indexLiSelected(targetClosest); this._onSelected({ @@ -325,7 +331,7 @@ var Autocomplete = (function () { !this._disable && this._reset(); return; } - getFirstElementFromLiAndAddToInput(element, this._root); + this._root.value = getFirstElement(element); this._onSubmit({ index: this._index, element: this._root, @@ -333,10 +339,10 @@ var Autocomplete = (function () { results: this._resultList }); if (!this._disable) { - this._remAria(element); + this._removeAria(element); this._reset(); } - this._clearButton && this._cBtn.classList.remove("hidden"); + this._clearButton && classList(this._clearBtn, "remove", "hidden"); this._cacheAct("remove"); }; this._indexLiSelected = target => @@ -345,9 +351,9 @@ var Autocomplete = (function () { const { keyCode } = event; - const resultList = this._resultWrap.classList.contains(this._isActive); + const resultList = classList(this._resultWrap, "contains", this._isActive); const matchesLength = this._matches.length + 1; - this._selectedLi = document.querySelector("." + this._activeList); + this._selectedLi = select("." + this._activeList); switch (keyCode) { case keyCodes.UP: case keyCodes.DOWN: @@ -366,10 +372,10 @@ var Autocomplete = (function () { this._index = 0; } } - this._remAria(this._selectedLi); - if (matchesLength > 0 && this._index >= 0 && this._index < matchesLength - 1) { + this._removeAria(this._selectedLi); + if (this._index >= 0 && this._index < matchesLength - 1) { if (this._toInput && resultList) { - getFirstElementFromLiAndAddToInput(this._itemsLi[this._index], this._root); + this._root.value = getFirstElement(this._itemsLi[this._index]); } this._onSelected({ index: this._index, @@ -407,7 +413,7 @@ var Autocomplete = (function () { setAriaActivedescendant(this._root, selectedOption); followActiveElement(target, this._outputUl, this._classGroup, this._resultList); }; - this._remAria = element => { + this._removeAria = element => { if (!element) return; setAttributes(element, { id: "", @@ -417,25 +423,25 @@ var Autocomplete = (function () { }; this._clearbutton = () => { if (!this._clearButton) return; - setAttributes(this._cBtn, { + setAttributes(this._clearBtn, { class: this._prefix + "-clear hidden", type: "button", title: this._clearBtnAriLabel, "aria-label": this._clearBtnAriLabel }); - this._root.insertAdjacentElement("afterend", this._cBtn); + this._root.insertAdjacentElement("afterend", this._clearBtn); }; this.destroy = () => { - this._clearButton && this._cBtn.classList.add("hidden"); + this._clearButton && classList(this._clearBtn, "add", "hidden"); this._root.value = ""; this._root.focus(); this._resultList.textContent = ""; this._reset(); this._error(); this._onReset(this._root); - this._root.removeEventListener("keydown", this._handleKeys); - this._root.removeEventListener("click", this._handleShowItems); - document.removeEventListener("click", this._handleDocClick); + offEvent(this._root, "keydown", this._handleKeys); + offEvent(this._root, "click", this._handleShowItems); + offEvent(document, "click", this._handleDocClick); }; this._id = _element; this._root = document.getElementById(_element); @@ -480,7 +486,7 @@ var Autocomplete = (function () { this._timeout = null; this._resultWrap = createElement("div"); this._resultList = createElement("ul"); - this._cBtn = createElement("button"); + this._clearBtn = createElement("button"); this._initial(); } } diff --git a/dist/js/autocomplete.js.map b/dist/js/autocomplete.js.map index 4e6fa8b..161aad9 100644 --- a/dist/js/autocomplete.js.map +++ b/dist/js/autocomplete.js.map @@ -1 +1 @@ -{"version":3,"file":"autocomplete.js","sources":["../../sources/js/utils/function.js","../../sources/js/utils/keyCodes.js","../../sources/js/script.js"],"sourcesContent":["/**\r\n * Check is a Object\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isObject = (value) =>\r\n value && typeof value === \"object\" && value.constructor === Object;\r\n\r\n/**\r\n * Check if is a Promise\r\n * https://stackoverflow.com/a/53955664/10424385\r\n *\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isPromise = (value) => Boolean(value && typeof value.then === \"function\");\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n if (key === \"addClass\") {\r\n el.classList.add(object[key]);\r\n } else if (key === \"removeClass\") {\r\n el.classList.remove(object[key]);\r\n } else {\r\n el.setAttribute(key, object[key]);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Get first element from child\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {HTMLELement}\r\n */\r\nconst getFirstElement = (element) => element.firstElementChild || element;\r\n\r\n/**\r\n * Set data from li to input\r\n *\r\n * @param {String} element\r\n * @param {HTMLElement} root\r\n * @returns {String}\r\n */\r\nconst getFirstElementFromLiAndAddToInput = (element, root) =>\r\n // get first element from li and add to input\r\n (root.value = getFirstElement(element).textContent.trim());\r\n\r\n/**\r\n * Scroll to top result-list\r\n * @param {HTMLElement} resultList\r\n * @param {HTMLElement} resultWrap\r\n */\r\nconst scrollResultsToTop = (resultList, resultWrap) => {\r\n // if there is an overflow of ul element, after\r\n // opening we always move ul to the top of the results\r\n resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight;\r\n};\r\n\r\n/**\r\n * Adding role, tabindex, aria and call handleMouse\r\n *\r\n * @param {HTMLElement} itemsLi\r\n */\r\nconst addAriaToAllLiElements = (itemsLi) => {\r\n // add role to all li elements\r\n for (let i = 0; i < itemsLi.length; i++) {\r\n setAttributes(itemsLi[i], {\r\n role: \"option\",\r\n tabindex: \"-1\",\r\n \"aria-selected\": \"false\",\r\n \"aria-setsize\": itemsLi.length,\r\n \"aria-posinset\": i,\r\n });\r\n }\r\n};\r\n\r\n/**\r\n * Show btn to clear data\r\n *\r\n * @param {HTMLElement} clearButton - button to clear data\r\n * @param {Function} destroy - destroy function\r\n */\r\nconst showBtnToClearData = (clearButton = false, destroy) => {\r\n if (!clearButton) return;\r\n\r\n clearButton.classList.remove(\"hidden\");\r\n // add event to clear button\r\n clearButton.addEventListener(\"click\", destroy);\r\n};\r\n\r\n/**\r\n * Set aria-activedescendant\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {String} type\r\n */\r\nconst setAriaActivedescendant = (root, type) => {\r\n root.setAttribute(\"aria-activedescendant\", type || \"\");\r\n};\r\n\r\n/**\r\n * Get height of ul without group class\r\n *\r\n * @param {String} outputUl\r\n * @param {String} classGroup\r\n * @returns {Number}\r\n */\r\nconst getClassGroupHeight = (outputUl, classGroup) => {\r\n // get height of ul without group class\r\n const allLi = document.querySelectorAll(\r\n `#${outputUl} > li:not(.${classGroup})`\r\n );\r\n let height = 0;\r\n [].slice.call(allLi).map((el) => (height += el.offsetHeight));\r\n\r\n // return height\r\n return height;\r\n};\r\n\r\n/**\r\n * Scroll into view when press up/down arrows\r\n *\r\n * @param {HTMLElement} target\r\n * @param {HTMLElement} outputUl\r\n * @param {String} classGroup\r\n * @param {HTMLElement} resultList\r\n */\r\nconst followActiveElement = (target, outputUl, classGroup, resultList) => {\r\n const previusElement = resultList.previousSibling;\r\n\r\n const previusElementHeight = previusElement ? previusElement.offsetHeight : 0;\r\n\r\n if (target.getAttribute(\"aria-posinset\") == \"0\") {\r\n resultList.scrollTop =\r\n target.offsetTop - getClassGroupHeight(outputUl, classGroup);\r\n }\r\n\r\n if (target.offsetTop - previusElementHeight < resultList.scrollTop) {\r\n resultList.scrollTop = target.offsetTop - previusElementHeight;\r\n } else {\r\n const offsetBottom =\r\n target.offsetTop + target.offsetHeight - previusElementHeight;\r\n const scrollBottom = resultList.scrollTop + resultList.offsetHeight;\r\n if (offsetBottom > scrollBottom) {\r\n resultList.scrollTop = offsetBottom - resultList.offsetHeight;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Create output-list and put after search input\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {HTMLElement} resultList - output-list ul\r\n * @param {String} outputUl - id name of output-list\r\n * @param {HTMLElement} resultWrap - wrapper ul element\r\n * @param {String} prefix - add prefix to all class auto\r\n */\r\nconst output = (root, resultList, outputUl, resultWrap, prefix) => {\r\n // set attribute to results-list\r\n setAttributes(resultList, {\r\n id: outputUl,\r\n tabIndex: \"0\",\r\n role: \"listbox\",\r\n });\r\n\r\n // add class to wrap element\r\n setAttributes(resultWrap, {\r\n addClass: `${prefix}-results-wrapper`,\r\n });\r\n\r\n // insert the results into the wrap element\r\n resultWrap.insertAdjacentElement(\"beforeend\", resultList);\r\n\r\n // insert the wrap element after the search input\r\n root.parentNode.insertBefore(resultWrap, root.nextSibling);\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLDivElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport {\r\n addAriaToAllLiElements,\r\n createElement,\r\n followActiveElement,\r\n getFirstElementFromLiAndAddToInput,\r\n isObject,\r\n isPromise,\r\n output,\r\n scrollResultsToTop,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n};\r\n","/**\r\n * Key codes\r\n */\r\nconst keyCodes = {\r\n ESC: 27,\r\n ENTER: 13,\r\n UP: 38,\r\n DOWN: 40,\r\n TAB: 9,\r\n};\r\n\r\nexport default keyCodes;\r\n","import {\r\n addAriaToAllLiElements,\r\n createElement,\r\n followActiveElement,\r\n getFirstElementFromLiAndAddToInput,\r\n isObject,\r\n isPromise,\r\n output,\r\n scrollResultsToTop,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n} from \"./utils/function\";\r\n\r\nimport keyCodes from \"./utils/keyCodes\";\r\n\r\n/**\r\n * @class Autocomplete\r\n */\r\nexport default class Autocomplete {\r\n /**\r\n * Constructor\r\n *\r\n * @param {String} element\r\n * @param {Object} object\r\n */\r\n constructor(\r\n element,\r\n {\r\n delay = 500,\r\n clearButton = true,\r\n howManyCharacters = 1,\r\n selectFirst = false,\r\n insertToInput = false,\r\n showAllValues = false,\r\n cache = false,\r\n disableCloseOnSelect = false,\r\n classGroup,\r\n classPreventClosing,\r\n classPrefix,\r\n ariaLabelClear,\r\n onSearch,\r\n onResults = () => {},\r\n onSubmit = () => {},\r\n onOpened = () => {},\r\n onReset = () => {},\r\n onRender = () => {},\r\n onClose = () => {},\r\n noResults = () => {},\r\n onSelectedItem = () => {},\r\n }\r\n ) {\r\n this._id = element;\r\n this._root = document.getElementById(element);\r\n this._onSearch = isPromise(onSearch)\r\n ? onSearch\r\n : ({ currentValue, element }) =>\r\n Promise.resolve(onSearch({ currentValue, element }));\r\n this._onResults = onResults;\r\n this._onRender = onRender;\r\n this._onSubmit = onSubmit;\r\n this._onSelected = onSelectedItem;\r\n this._onOpened = onOpened;\r\n this._onReset = onReset;\r\n this._noResults = noResults;\r\n this._onClose = onClose;\r\n\r\n this._delay = delay;\r\n this._characters = howManyCharacters;\r\n this._clearButton = clearButton;\r\n this._selectFirst = selectFirst;\r\n this._toInput = insertToInput;\r\n this._showAll = showAllValues;\r\n this._classGroup = classGroup;\r\n this._prevClosing = classPreventClosing;\r\n this._clearBtnAriLabel = ariaLabelClear\r\n ? ariaLabelClear\r\n : \"clear the search query\";\r\n this._prefix = classPrefix ? `${classPrefix}-auto` : \"auto\";\r\n this._disable = disableCloseOnSelect;\r\n\r\n // default config\r\n this._cache = cache;\r\n this._outputUl = `${this._prefix}-${this._id}-results`;\r\n this._cacheData = `data-cache-auto-${this._id}`;\r\n this._isLoading = `${this._prefix}-is-loading`;\r\n this._isActive = `${this._prefix}-is-active`;\r\n this._activeList = `${this._prefix}-selected`;\r\n this._selectedOption = `${this._prefix}-selected-option`;\r\n this._err = `${this._prefix}-error`;\r\n this._regex = /[|\\\\{}()[\\]^$+*?.]/g;\r\n this._timeout = null;\r\n\r\n this._resultWrap = createElement(\"div\");\r\n this._resultList = createElement(\"ul\");\r\n this._cBtn = createElement(\"button\");\r\n\r\n this._initial();\r\n }\r\n\r\n /**\r\n * Initial function\r\n */\r\n _initial = () => {\r\n this._clearbutton();\r\n\r\n output(\r\n this._root,\r\n this._resultList,\r\n this._outputUl,\r\n this._resultWrap,\r\n this._prefix\r\n );\r\n\r\n // default aria\r\n // this.reset();\r\n this._root.addEventListener(\"input\", this._handleInput);\r\n\r\n // show all values on click root input\r\n this._showAll && this._root.addEventListener(\"click\", this._handleInput);\r\n\r\n // calback functions\r\n this._onRender({\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n };\r\n\r\n /**\r\n * Actions on input\r\n *\r\n * @param {String} type - set attribute depending on type\r\n * @param {String} target\r\n */\r\n _cacheAct = (type, target) => {\r\n if (!this._cache) return;\r\n\r\n if (type === \"update\") {\r\n this._root.setAttribute(this._cacheData, target.value);\r\n } else if (type === \"remove\") {\r\n this._root.removeAttribute(this._cacheData);\r\n } else {\r\n this._root.value = this._root.getAttribute(this._cacheData);\r\n }\r\n };\r\n\r\n /**\r\n * Handle input\r\n *\r\n * @param {Event} object\r\n */\r\n _handleInput = ({ target, type }) => {\r\n if (\r\n this._root.getAttribute(\"aria-expanded\") === \"true\" &&\r\n type === \"click\"\r\n ) {\r\n return;\r\n }\r\n\r\n // replace all special characters\r\n const regex = target.value.replace(this._regex, \"\\\\$&\");\r\n\r\n // update data attribute cache\r\n this._cacheAct(\"update\", target);\r\n\r\n const delay = this._showAll ? 0 : this._delay;\r\n // clear timeout\r\n clearTimeout(this._timeout);\r\n this._timeout = setTimeout(() => {\r\n this._searchItem(regex.trim());\r\n }, delay);\r\n };\r\n\r\n /**\r\n * Default aria\r\n */\r\n _reset = () => {\r\n // set attributes to root - input\r\n setAttributes(this._root, {\r\n \"aria-owns\": `${this._id}-list`,\r\n \"aria-expanded\": \"false\",\r\n \"aria-autocomplete\": \"list\",\r\n \"aria-activedescendant\": \"\",\r\n role: \"combobox\",\r\n removeClass: \"auto-expanded\",\r\n });\r\n\r\n // remove class isActive\r\n this._resultWrap.classList.remove(this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n // scrollResultsToTop(this.resultList, this.resultWrap);\r\n\r\n // remove result when lengh = 0 and insertToInput is false\r\n if ((this._matches?.length == 0 && !this._toInput) || this._showAll) {\r\n this._resultList.innerHTML = \"\";\r\n }\r\n\r\n // set index\r\n this._index = this._selectFirst ? 0 : -1;\r\n\r\n // callback function\r\n this._onClose();\r\n };\r\n\r\n /**\r\n * The async function gets the text from the search\r\n * and returns the matching array\r\n *\r\n * @param {String} value\r\n */\r\n _searchItem = (value) => {\r\n this._value = value;\r\n\r\n // if searching show loading icon\r\n this._onLoading(true);\r\n\r\n // hide button clear\r\n showBtnToClearData(this._cBtn, this.destroy);\r\n\r\n // if there is no value and clearButton is true\r\n if (value.length == 0 && this._clearButton) {\r\n this._cBtn.classList.add(\"hidden\");\r\n }\r\n\r\n // if declare characters more then value.len and showAll is false\r\n // remove class isActive\r\n if (this._characters > value.length && !this._showAll) {\r\n this._onLoading();\r\n return;\r\n }\r\n\r\n // callblack function onSearch\r\n this._onSearch({ currentValue: value, element: this._root })\r\n .then((result) => {\r\n const rootValueLength = this._root.value.length;\r\n const resultLength = result.length;\r\n // set no result\r\n this._matches = Array.isArray(result)\r\n ? [...result]\r\n : JSON.parse(JSON.stringify(result));\r\n\r\n this._onLoading();\r\n this._error();\r\n\r\n // if use destroy() method\r\n if (resultLength == 0 && rootValueLength == 0) {\r\n this._cBtn.classList.add(\"hidden\");\r\n }\r\n\r\n if (resultLength == 0 && rootValueLength) {\r\n this._root.classList.remove(\"auto-expanded\");\r\n this._reset();\r\n this._noResults({\r\n element: this._root,\r\n currentValue: value,\r\n template: this._results,\r\n });\r\n this._events();\r\n } else if (resultLength > 0 || isObject(result)) {\r\n this._index = this._selectFirst ? 0 : -1;\r\n this._results();\r\n this._events();\r\n }\r\n })\r\n .catch(() => {\r\n this._onLoading();\r\n this._reset();\r\n });\r\n };\r\n\r\n /**\r\n * Set or remove loading class\r\n *\r\n * @param {Boolean} type\r\n */\r\n _onLoading = (type) =>\r\n this._root.parentNode.classList[type ? \"add\" : \"remove\"](this._isLoading);\r\n\r\n /**\r\n * Set error class to the root element\r\n */\r\n _error = () => this._root.classList.remove(this._err);\r\n\r\n /**\r\n * Events\r\n */\r\n _events = () => {\r\n // handle click on keydown [up, down, enter, tab, esc]\r\n this._root.addEventListener(\"keydown\", this._handleKeys);\r\n\r\n //\r\n this._root.addEventListener(\"click\", this._handleShowItems);\r\n\r\n // temporarily disabled mouseleave\r\n [\"mousemove\", \"click\"].map((eventType) => {\r\n this._resultList.addEventListener(eventType, this._handleMouse);\r\n });\r\n\r\n // close expanded items\r\n document.addEventListener(\"click\", this._handleDocClick);\r\n };\r\n\r\n /**\r\n * Results\r\n *\r\n * @param {HTMLElement|String} template - html or string returned from the function,\r\n * look at the example - https://github.com/tomik23/autocomplete/blob/master/docs/js/examples/no-results.js#L30\r\n */\r\n _results = (template) => {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add all found records to otput ul\r\n this._resultList.innerHTML =\r\n this._matches.length === 0\r\n ? this._onResults({\r\n currentValue: this._value,\r\n matches: 0,\r\n template,\r\n })\r\n : this._onResults({\r\n currentValue: this._value,\r\n matches: this._matches,\r\n classGroup: this._classGroup,\r\n });\r\n\r\n this._resultWrap.classList.add(this._isActive);\r\n\r\n const checkIfClassGroupExist = this._classGroup\r\n ? `:not(.${this._classGroup})`\r\n : \"\";\r\n\r\n this._itemsLi = document.querySelectorAll(\r\n `#${this._outputUl} > li${checkIfClassGroupExist}`\r\n );\r\n\r\n // adding role, tabindex and aria\r\n addAriaToAllLiElements(this._itemsLi);\r\n\r\n // action on open results\r\n this._onOpened({\r\n type: \"results\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n\r\n // select first element\r\n this._selectFirstEl();\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n };\r\n\r\n /**\r\n * Hangle click on document\r\n *\r\n * @param {Event} object\r\n */\r\n _handleDocClick = ({ target }) => {\r\n let disableClose = null;\r\n\r\n // if 'target' is a ul and 'disableCloseOnSelect'\r\n // is a 'true' set 'disableClose' on true\r\n if (\r\n (target.closest(\"ul\") && this._disable) ||\r\n // when class classDisableClose\r\n // then do not not close results\r\n target.closest(`.${this._prevClosing}`)\r\n ) {\r\n disableClose = true;\r\n }\r\n\r\n if (target.id !== this._id && !disableClose) {\r\n this._reset();\r\n return;\r\n }\r\n };\r\n\r\n /**\r\n * Select first element\r\n */\r\n _selectFirstEl = () => {\r\n this._remAria(document.querySelector(`.${this._activeList}`));\r\n\r\n if (!this._selectFirst) {\r\n return;\r\n }\r\n\r\n const { firstElementChild } = this._resultList;\r\n\r\n const classSelectFirst =\r\n this._classGroup && this._matches.length > 0 && this._selectFirst\r\n ? firstElementChild.nextElementSibling\r\n : firstElementChild;\r\n\r\n // calback function onSelect when first element is true\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set attribute to first element\r\n setAttributes(classSelectFirst, {\r\n id: `${this._selectedOption}-0`,\r\n addClass: this._activeList,\r\n \"aria-selected\": \"true\",\r\n });\r\n\r\n // set aria active descendant\r\n setAriaActivedescendant(this._root, `${this._selectedOption}-0`);\r\n };\r\n\r\n /**\r\n * show items when items.length > 0 and is not empty\r\n */\r\n _handleShowItems = () => {\r\n // if resultWrap is not active and resultList is not empty\r\n if (\r\n this._resultList.textContent.length > 0 &&\r\n !this._resultWrap.classList.contains(this._isActive)\r\n ) {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add isActive class to resultWrap\r\n this._resultWrap.classList.add(this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n\r\n // select first element\r\n this._selectFirstEl();\r\n\r\n // callback function\r\n this._onOpened({\r\n type: \"showItems\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Adding text from the list when li is clicking\r\n * or adding aria-selected to li elements\r\n *\r\n * @param {Event} event\r\n */\r\n _handleMouse = (event) => {\r\n event.preventDefault();\r\n\r\n const { target, type } = event;\r\n const targetClosest = target.closest(\"li\");\r\n const targetClosestRole = targetClosest?.hasAttribute(\"role\");\r\n const activeClass = this._activeList;\r\n const activeClassElement = document.querySelector(`.${activeClass}`);\r\n\r\n if (!targetClosest || !targetClosestRole) {\r\n return;\r\n }\r\n\r\n // click on li get element\r\n if (type === \"click\") {\r\n // get text from clicked li\r\n this._getTextFromLi(targetClosest);\r\n }\r\n\r\n if (\r\n type === \"mousemove\" &&\r\n !targetClosest.classList.contains(activeClass)\r\n ) {\r\n this._remAria(activeClassElement);\r\n\r\n // add aria to li\r\n this._setAria(targetClosest);\r\n this._index = this._indexLiSelected(targetClosest);\r\n\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Get text from li on enter or click\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _getTextFromLi = (element) => {\r\n if (!element || this._matches.length === 0) {\r\n // set default settings\r\n !this._disable && this._reset();\r\n\r\n return;\r\n }\r\n\r\n // get first element from li and set it to root\r\n getFirstElementFromLiAndAddToInput(element, this._root);\r\n\r\n // onSubmit passing text to function\r\n this._onSubmit({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n results: this._resultList,\r\n });\r\n\r\n // set default settings\r\n if (!this._disable) {\r\n this._remAria(element);\r\n this._reset();\r\n }\r\n\r\n // show clearBtn when select element\r\n this._clearButton && this._cBtn.classList.remove(\"hidden\");\r\n\r\n // remove cache\r\n this._cacheAct(\"remove\");\r\n };\r\n\r\n /**\r\n * Return which li element was selected\r\n * by hovering the mouse over\r\n *\r\n * @param {HTMLElement} target\r\n * @returns {Number}\r\n */\r\n _indexLiSelected = (target) =>\r\n // get index of li element\r\n Array.prototype.indexOf.call(this._itemsLi, target);\r\n\r\n /**\r\n * Navigating the elements li and enter\r\n *\r\n * @param {Event} event\r\n */\r\n _handleKeys = (event) => {\r\n const { keyCode } = event;\r\n\r\n const resultList = this._resultWrap.classList.contains(this._isActive);\r\n\r\n const matchesLength = this._matches.length + 1;\r\n this._selectedLi = document.querySelector(`.${this._activeList}`);\r\n\r\n // switch between keys\r\n switch (keyCode) {\r\n case keyCodes.UP:\r\n case keyCodes.DOWN:\r\n // Wrong cursor position in the input field #62\r\n // Prevents the cursor from moving to the beginning\r\n // of input as the cursor hovers over the results.\r\n event.preventDefault();\r\n\r\n if ((matchesLength <= 1 && this._selectFirst) || !resultList) {\r\n return;\r\n }\r\n\r\n // if keyCode is up\r\n if (keyCode === keyCodes.UP) {\r\n if (this._index < 0) {\r\n this._index = matchesLength - 1;\r\n }\r\n this._index -= 1;\r\n } else {\r\n this._index += 1;\r\n if (this._index >= matchesLength) {\r\n this._index = 0;\r\n }\r\n }\r\n\r\n // remove aria-selected\r\n this._remAria(this._selectedLi);\r\n\r\n if (\r\n matchesLength > 0 &&\r\n this._index >= 0 &&\r\n this._index < matchesLength - 1\r\n ) {\r\n if (this._toInput && resultList) {\r\n getFirstElementFromLiAndAddToInput(\r\n this._itemsLi[this._index],\r\n this._root\r\n );\r\n }\r\n\r\n // callback function\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set aria-selected\r\n this._setAria(this._itemsLi[this._index]);\r\n } else {\r\n // catch action\r\n this._cacheAct();\r\n setAriaActivedescendant(this._root);\r\n\r\n this._onSelected({\r\n index: null,\r\n element: this._root,\r\n object: null,\r\n });\r\n }\r\n\r\n break;\r\n // keycode enter\r\n case keyCodes.ENTER:\r\n this._getTextFromLi(this._selectedLi);\r\n break;\r\n\r\n // keycode escape and keycode tab\r\n case keyCodes.TAB:\r\n case keyCodes.ESC:\r\n event.stopPropagation(); // #120\r\n this._reset();\r\n\r\n break;\r\n default:\r\n break;\r\n }\r\n };\r\n\r\n /**\r\n * Set aria label on item li\r\n *\r\n * @param {HTMLElement} target\r\n */\r\n _setAria = (target) => {\r\n const selectedOption = `${this._selectedOption}-${this._indexLiSelected(\r\n target\r\n )}`;\r\n\r\n // set aria to li\r\n setAttributes(target, {\r\n id: selectedOption,\r\n \"aria-selected\": \"true\",\r\n addClass: this._activeList,\r\n });\r\n\r\n setAriaActivedescendant(this._root, selectedOption);\r\n\r\n // scrollIntoView when press up/down arrows\r\n followActiveElement(\r\n target,\r\n this._outputUl,\r\n this._classGroup,\r\n this._resultList\r\n );\r\n };\r\n\r\n /**\r\n * Remove aria label from item li\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _remAria = (element) => {\r\n if (!element) return;\r\n\r\n // remove aria from li\r\n setAttributes(element, {\r\n id: \"\",\r\n removeClass: this._activeList,\r\n \"aria-selected\": \"false\",\r\n });\r\n };\r\n\r\n /**\r\n * Create clear button and\r\n * removing text from the input field\r\n */\r\n _clearbutton = () => {\r\n // stop when clear button is disabled\r\n if (!this._clearButton) return;\r\n\r\n // add aria to clear button\r\n setAttributes(this._cBtn, {\r\n class: `${this._prefix}-clear hidden`,\r\n type: \"button\",\r\n title: this._clearBtnAriLabel,\r\n \"aria-label\": this._clearBtnAriLabel,\r\n });\r\n\r\n // insert clear button after input - root\r\n this._root.insertAdjacentElement(\"afterend\", this._cBtn);\r\n };\r\n\r\n /**\r\n * Clicking on the clear button\r\n * publick destroy method\r\n */\r\n destroy = () => {\r\n // if clear button is true then add class hidden\r\n this._clearButton && this._cBtn.classList.add(\"hidden\");\r\n // clear value searchId\r\n this._root.value = \"\";\r\n // set focus\r\n this._root.focus();\r\n // remove li from ul\r\n this._resultList.textContent = \"\";\r\n // set default aria\r\n this._reset();\r\n // remove error if exist\r\n this._error();\r\n\r\n // callback function\r\n this._onReset(this._root);\r\n\r\n // remove listener\r\n this._root.removeEventListener(\"keydown\", this._handleKeys);\r\n this._root.removeEventListener(\"click\", this._handleShowItems);\r\n // remove listener on click on document\r\n document.removeEventListener(\"click\", this._handleDocClick);\r\n };\r\n}\r\n"],"names":["isObject","value","constructor","Object","isPromise","Boolean","then","setAttributes","el","object","key","classList","add","remove","setAttribute","getFirstElement","element","firstElementChild","getFirstElementFromLiAndAddToInput","root","textContent","trim","scrollResultsToTop","resultList","resultWrap","scrollTop","offsetTop","offsetHeight","addAriaToAllLiElements","itemsLi","i","length","role","tabindex","showBtnToClearData","clearButton","destroy","addEventListener","setAriaActivedescendant","type","getClassGroupHeight","outputUl","classGroup","allLi","document","querySelectorAll","height","slice","call","map","followActiveElement","target","previusElement","previousSibling","previusElementHeight","getAttribute","offsetBottom","scrollBottom","output","prefix","id","tabIndex","addClass","insertAdjacentElement","parentNode","insertBefore","nextSibling","createElement","keyCodes","ESC","ENTER","UP","DOWN","TAB","Autocomplete","delay","howManyCharacters","selectFirst","insertToInput","showAllValues","cache","disableCloseOnSelect","classPreventClosing","classPrefix","ariaLabelClear","onSearch","onResults","onSubmit","onOpened","onReset","onRender","onClose","noResults","onSelectedItem","_initial","_clearbutton","_root","_resultList","_outputUl","_resultWrap","_prefix","_handleInput","_showAll","_onRender","results","_cacheAct","_cache","_cacheData","removeAttribute","regex","replace","_regex","_delay","clearTimeout","_timeout","setTimeout","_searchItem","_reset","_id","removeClass","_isActive","_matches","_toInput","innerHTML","_index","_selectFirst","_onClose","_value","_onLoading","_cBtn","_clearButton","_characters","_onSearch","currentValue","result","rootValueLength","resultLength","Array","isArray","JSON","parse","stringify","_error","_noResults","template","_results","_events","catch","_isLoading","_err","_handleKeys","_handleShowItems","eventType","_handleMouse","_handleDocClick","_onResults","matches","_classGroup","checkIfClassGroupExist","_itemsLi","_onOpened","_selectFirstEl","disableClose","closest","_disable","_prevClosing","_remAria","querySelector","_activeList","classSelectFirst","nextElementSibling","_onSelected","index","_selectedOption","contains","event","preventDefault","targetClosest","targetClosestRole","hasAttribute","activeClass","activeClassElement","_getTextFromLi","_setAria","_indexLiSelected","_onSubmit","prototype","indexOf","keyCode","matchesLength","_selectedLi","stopPropagation","selectedOption","class","title","_clearBtnAriLabel","focus","_onReset","removeEventListener","getElementById","Promise","resolve"],"mappings":";;;EAKA,MAAMA,QAAQ,GAAIC,KAAD,IACfA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAA1B,IAAsCA,KAAK,CAACC,WAAN,KAAsBC,MAD9D;EAUA,MAAMC,SAAS,GAAIH,KAAD,IAAWI,OAAO,CAACJ,KAAK,IAAI,OAAOA,KAAK,CAACK,IAAb,KAAsB,UAAhC,CAApC;EAQA,MAAMC,aAAa,GAAG,CAACC,EAAD,EAAKC,MAAL,KAAgB;EACpC,OAAK,IAAIC,GAAT,IAAgBD,MAAhB,EAAwB;EACtB,QAAIC,GAAG,KAAK,UAAZ,EAAwB;EACtBF,MAAAA,EAAE,CAACG,SAAH,CAAaC,GAAb,CAAiBH,MAAM,CAACC,GAAD,CAAvB;EACD,KAFD,MAEO,IAAIA,GAAG,KAA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vD,iBAAnB;EACA,SAAKsD,YAAL,GAAoB/F,WAApB;EACA,SAAK0F,YAAL,GAAoBhD,WAApB;EACA,SAAK6C,QAAL,GAAgB5C,aAAhB;EACA,SAAKwB,QAAL,GAAgBvB,aAAhB;EACA,SAAK8E,WAAL,GAAmBnH,UAAnB;EACA,SAAK2H,YAAL,GAAoBnF,mBAApB;EACA,SAAKiH,iBAAL,GAAyB/G,cAAc,GACnCA,cADmC,GAEnC,wBAFJ;EAGA,SAAKgB,OAAL,GAAejB,WAAW,GAAMA,WAAN,aAA2B,MAArD;EACA,SAAKiF,QAAL,GAAgBnF,oBAAhB,CA5BA;EA+BA,SAAKyB,MAAL,GAAc1B,KAAd;EACA,SAAKkB,SAAL,GAAoB,KAAKE,OAAzB,SAAoC,KAAKkB,GAAzC;EACA,SAAKX,UAAL,wBAAqC,KAAKW,GAA1C;EACA,SAAK8B,UAAL,GAAqB,KAAKhD,OAA1B;EACA,SAAKoB,SAAL,GAAoB,KAAKpB,OAAzB;EACA,SAAKoE,WAAL,GAAsB,KAAKpE,OAA3B;EACA,SAAKyE,eAAL,GAA0B,KAAKzE,OAA/B;EACA,SAAKiD,IAAL,GAAe,KAAKjD,OAApB;EACA,SAAKW,MAAL,GAAc,qBAAd;EACA,SAAKG,QAAL,GAAgB,IAAhB;EAEA,SAAKf,WAAL,GAAmBhC,aAAa,CAAC,KAAD,CAAhC;EACA,SAAK8B,WAAL,GAAmB9B,aAAa,CAAC,IAAD,CAAhC;EACA,SAAK8D,KAAL,GAAa9D,aAAa,CAAC,QAAD,CAA1B;EAEA,SAAK2B,QAAL;EACD;EA/E+B;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"autocomplete.js","sources":["../../sources/js/utils/function.js","../../sources/js/utils/keyCodes.js","../../sources/js/script.js"],"sourcesContent":["/**\r\n * Check is a Object\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isObject = (value) =>\r\n value && typeof value === \"object\" && value.constructor === Object;\r\n\r\n/**\r\n * Check if is a Promise\r\n * https://stackoverflow.com/a/53955664/10424385\r\n *\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isPromise = (value) => Boolean(value && typeof value.then === \"function\");\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n if (key === \"addClass\") {\r\n classList(el, \"add\", object[key]);\r\n } else if (key === \"removeClass\") {\r\n classList(el, \"remove\", object[key]);\r\n } else {\r\n el.setAttribute(key, object[key]);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Get first element from child\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {HTMLELement}\r\n */\r\nconst getFirstElement = (element) =>\r\n (element.firstElementChild || element).textContent.trim();\r\n\r\n/**\r\n * Scroll to top result-list\r\n * @param {HTMLElement} resultList\r\n * @param {HTMLElement} resultWrap\r\n */\r\nconst scrollResultsToTop = (resultList, resultWrap) => {\r\n // if there is an overflow of ul element, after\r\n // opening we always move ul to the top of the results\r\n resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight;\r\n};\r\n\r\n/**\r\n * Adding role, tabindex, aria and call handleMouse\r\n *\r\n * @param {HTMLElement} itemsLi\r\n */\r\nconst addAriaToAllLiElements = (itemsLi) => {\r\n // add role to all li elements\r\n for (let i = 0; i < itemsLi.length; i++) {\r\n setAttributes(itemsLi[i], {\r\n role: \"option\",\r\n tabindex: \"-1\",\r\n \"aria-selected\": \"false\",\r\n \"aria-setsize\": itemsLi.length,\r\n \"aria-posinset\": i,\r\n });\r\n }\r\n};\r\n\r\n/**\r\n * Show btn to clear data\r\n *\r\n * @param {HTMLElement} clearButton - button to clear data\r\n * @param {Function} destroy - destroy function\r\n */\r\nconst showBtnToClearData = (clearButton = false, destroy) => {\r\n if (!clearButton) return;\r\n\r\n classList(clearButton, \"remove\", \"hidden\");\r\n // add event to clear button\r\n onEvent(clearButton, \"click\", destroy);\r\n};\r\n\r\n/**\r\n * ClassList add/remove/contains\r\n *\r\n * @param {HTMLElement} element - html element\r\n * @param {String} action - add/remove/contains\r\n * @param {String} className - class name\r\n */\r\nconst classList = (element, action, className) =>\r\n element.classList[action](className);\r\n\r\n/**\r\n * Set aria-activedescendant\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {String} type\r\n */\r\nconst setAriaActivedescendant = (root, type) => {\r\n setAttributes(root, {\r\n \"aria-activedescendant\": type || \"\",\r\n });\r\n};\r\n\r\n/**\r\n * Get height of ul without group class\r\n *\r\n * @param {String} outputUl\r\n * @param {String} classGroup\r\n * @returns {Number}\r\n */\r\nconst getClassGroupHeight = (outputUl, classGroup) => {\r\n // get height of ul without group class\r\n const allLiElements = document.querySelectorAll(\r\n `#${outputUl} > li:not(.${classGroup})`\r\n );\r\n let height = 0;\r\n [].slice.call(allLiElements).map((el) => (height += el.offsetHeight));\r\n\r\n // return height\r\n return height;\r\n};\r\n\r\n/**\r\n * Scroll into view when press up/down arrows\r\n *\r\n * @param {HTMLElement} target\r\n * @param {HTMLElement} outputUl\r\n * @param {String} classGroup\r\n * @param {HTMLElement} resultList\r\n */\r\nconst followActiveElement = (target, outputUl, classGroup, resultList) => {\r\n const previusElement = resultList.previousSibling;\r\n\r\n const previusElementHeight = previusElement ? previusElement.offsetHeight : 0;\r\n\r\n if (target.getAttribute(\"aria-posinset\") == \"0\") {\r\n resultList.scrollTop =\r\n target.offsetTop - getClassGroupHeight(outputUl, classGroup);\r\n }\r\n\r\n if (target.offsetTop - previusElementHeight < resultList.scrollTop) {\r\n resultList.scrollTop = target.offsetTop - previusElementHeight;\r\n } else {\r\n const offsetBottom =\r\n target.offsetTop + target.offsetHeight - previusElementHeight;\r\n const scrollBottom = resultList.scrollTop + resultList.offsetHeight;\r\n if (offsetBottom > scrollBottom) {\r\n resultList.scrollTop = offsetBottom - resultList.offsetHeight;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Create output-list and put after search input\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {HTMLElement} resultList - output-list ul\r\n * @param {String} outputUl - id name of output-list\r\n * @param {HTMLElement} resultWrap - wrapper ul element\r\n * @param {String} prefix - add prefix to all class auto\r\n */\r\nconst output = (root, resultList, outputUl, resultWrap, prefix) => {\r\n // set attribute to results-list\r\n setAttributes(resultList, {\r\n id: outputUl,\r\n tabIndex: \"0\",\r\n role: \"listbox\",\r\n });\r\n\r\n // add class to wrap element\r\n setAttributes(resultWrap, {\r\n addClass: `${prefix}-results-wrapper`,\r\n });\r\n\r\n // insert the results into the wrap element\r\n resultWrap.insertAdjacentElement(\"beforeend\", resultList);\r\n\r\n // insert the wrap element after the search input\r\n root.parentNode.insertBefore(resultWrap, root.nextSibling);\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLDivElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\n/**\r\n * Get element\r\n *\r\n * @param {String} element\r\n * @returns {HTMLElement}\r\n */\r\nconst select = (element) => document.querySelector(element);\r\n\r\n/**\r\n * Event listeners\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} action\r\n * @param {Function} callback\r\n */\r\nconst onEvent = (element, action, callback) => {\r\n element.addEventListener(action, callback);\r\n};\r\n\r\n/**\r\n * Remove event listeners\r\n */\r\nconst offEvent = (element, action, callback) => {\r\n element.removeEventListener(action, callback);\r\n};\r\n\r\nexport {\r\n addAriaToAllLiElements,\r\n classList,\r\n createElement,\r\n followActiveElement,\r\n getFirstElement,\r\n isObject,\r\n isPromise,\r\n offEvent,\r\n onEvent,\r\n output,\r\n scrollResultsToTop,\r\n select,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n};\r\n","/**\r\n * Key codes\r\n */\r\nconst keyCodes = {\r\n ESC: 27,\r\n ENTER: 13,\r\n UP: 38,\r\n DOWN: 40,\r\n TAB: 9,\r\n};\r\n\r\nexport default keyCodes;\r\n","import {\r\n addAriaToAllLiElements,\r\n classList,\r\n createElement,\r\n followActiveElement,\r\n getFirstElement,\r\n isObject,\r\n isPromise,\r\n offEvent,\r\n onEvent,\r\n output,\r\n scrollResultsToTop,\r\n select,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n} from \"./utils/function\";\r\n\r\nimport keyCodes from \"./utils/keyCodes\";\r\n\r\n/**\r\n * @class Autocomplete\r\n */\r\nexport default class Autocomplete {\r\n /**\r\n * Constructor\r\n *\r\n * @param {String} element\r\n * @param {Object} object\r\n */\r\n constructor(\r\n element,\r\n {\r\n delay = 500,\r\n clearButton = true,\r\n howManyCharacters = 1,\r\n selectFirst = false,\r\n insertToInput = false,\r\n showAllValues = false,\r\n cache = false,\r\n disableCloseOnSelect = false,\r\n classGroup,\r\n classPreventClosing,\r\n classPrefix,\r\n ariaLabelClear,\r\n onSearch,\r\n onResults = () => {},\r\n onSubmit = () => {},\r\n onOpened = () => {},\r\n onReset = () => {},\r\n onRender = () => {},\r\n onClose = () => {},\r\n noResults = () => {},\r\n onSelectedItem = () => {},\r\n }\r\n ) {\r\n this._id = element;\r\n this._root = document.getElementById(element);\r\n this._onSearch = isPromise(onSearch)\r\n ? onSearch\r\n : ({ currentValue, element }) =>\r\n Promise.resolve(onSearch({ currentValue, element }));\r\n this._onResults = onResults;\r\n this._onRender = onRender;\r\n this._onSubmit = onSubmit;\r\n this._onSelected = onSelectedItem;\r\n this._onOpened = onOpened;\r\n this._onReset = onReset;\r\n this._noResults = noResults;\r\n this._onClose = onClose;\r\n\r\n this._delay = delay;\r\n this._characters = howManyCharacters;\r\n this._clearButton = clearButton;\r\n this._selectFirst = selectFirst;\r\n this._toInput = insertToInput;\r\n this._showAll = showAllValues;\r\n this._classGroup = classGroup;\r\n this._prevClosing = classPreventClosing;\r\n this._clearBtnAriLabel = ariaLabelClear\r\n ? ariaLabelClear\r\n : \"clear the search query\";\r\n this._prefix = classPrefix ? `${classPrefix}-auto` : \"auto\";\r\n this._disable = disableCloseOnSelect;\r\n\r\n // default config\r\n this._cache = cache;\r\n this._outputUl = `${this._prefix}-${this._id}-results`;\r\n this._cacheData = `data-cache-auto-${this._id}`;\r\n this._isLoading = `${this._prefix}-is-loading`;\r\n this._isActive = `${this._prefix}-is-active`;\r\n this._activeList = `${this._prefix}-selected`;\r\n this._selectedOption = `${this._prefix}-selected-option`;\r\n this._err = `${this._prefix}-error`;\r\n this._regex = /[|\\\\{}()[\\]^$+*?.]/g;\r\n this._timeout = null;\r\n\r\n this._resultWrap = createElement(\"div\");\r\n this._resultList = createElement(\"ul\");\r\n this._clearBtn = createElement(\"button\");\r\n\r\n this._initial();\r\n }\r\n\r\n /**\r\n * Initial function\r\n */\r\n _initial = () => {\r\n this._clearbutton();\r\n\r\n output(\r\n this._root,\r\n this._resultList,\r\n this._outputUl,\r\n this._resultWrap,\r\n this._prefix\r\n );\r\n\r\n // default aria\r\n onEvent(this._root, \"input\", this._handleInput);\r\n\r\n // show all values on click root input\r\n this._showAll && onEvent(this._root, \"click\", this._handleInput);\r\n\r\n // calback functions\r\n this._onRender({\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n };\r\n\r\n /**\r\n * Actions on input\r\n *\r\n * @param {String} type - set attribute depending on type\r\n * @param {String} target\r\n */\r\n _cacheAct = (type, target) => {\r\n if (!this._cache) return;\r\n\r\n if (type === \"update\") {\r\n this._root.setAttribute(this._cacheData, target.value);\r\n } else if (type === \"remove\") {\r\n this._root.removeAttribute(this._cacheData);\r\n } else {\r\n this._root.value = this._root.getAttribute(this._cacheData);\r\n }\r\n };\r\n\r\n /**\r\n * Handle input\r\n *\r\n * @param {Event} object\r\n */\r\n _handleInput = ({ target, type }) => {\r\n if (\r\n this._root.getAttribute(\"aria-expanded\") === \"true\" &&\r\n type === \"click\"\r\n ) {\r\n return;\r\n }\r\n\r\n // replace all special characters\r\n const regex = target.value.replace(this._regex, \"\\\\$&\");\r\n\r\n // update data attribute cache\r\n this._cacheAct(\"update\", target);\r\n\r\n const delay = this._showAll ? 0 : this._delay;\r\n // clear timeout\r\n clearTimeout(this._timeout);\r\n this._timeout = setTimeout(() => {\r\n this._searchItem(regex.trim());\r\n }, delay);\r\n };\r\n\r\n /**\r\n * Default aria\r\n */\r\n _reset = () => {\r\n // set attributes to root - input\r\n setAttributes(this._root, {\r\n \"aria-owns\": `${this._id}-list`,\r\n \"aria-expanded\": \"false\",\r\n \"aria-autocomplete\": \"list\",\r\n \"aria-activedescendant\": \"\",\r\n role: \"combobox\",\r\n removeClass: \"auto-expanded\",\r\n });\r\n\r\n // remove class isActive\r\n classList(this._resultWrap, \"remove\", this._isActive);\r\n\r\n // set index\r\n this._index = this._selectFirst ? 0 : -1;\r\n\r\n // callback function\r\n this._onClose();\r\n };\r\n\r\n /**\r\n * The async function gets the text from the search\r\n * and returns the matching array\r\n *\r\n * @param {String} value\r\n */\r\n _searchItem = (value) => {\r\n this._value = value;\r\n\r\n // if searching show loading icon\r\n this._onLoading(true);\r\n\r\n // hide button clear\r\n showBtnToClearData(this._clearBtn, this.destroy);\r\n\r\n // if there is no value and clearButton is true\r\n if (value.length == 0 && this._clearButton) {\r\n classList(this._clearBtn, \"add\", \"hidden\");\r\n }\r\n\r\n // if declare characters more then value.len and showAll is false\r\n // remove class isActive\r\n if (this._characters > value.length && !this._showAll) {\r\n this._onLoading();\r\n return;\r\n }\r\n\r\n // callblack function onSearch\r\n this._onSearch({ currentValue: value, element: this._root })\r\n .then((result) => {\r\n const rootValueLength = this._root.value.length;\r\n const resultLength = result.length;\r\n // set no result\r\n this._matches = Array.isArray(result)\r\n ? result\r\n : JSON.parse(JSON.stringify(result));\r\n\r\n this._onLoading();\r\n this._error();\r\n\r\n // if use destroy() method\r\n if (resultLength == 0 && rootValueLength == 0) {\r\n classList(this._clearBtn, \"add\", \"hidden\");\r\n }\r\n\r\n if (resultLength == 0 && rootValueLength) {\r\n classList(this._root, \"remove\", \"auto-expanded\");\r\n this._reset();\r\n this._noResults({\r\n element: this._root,\r\n currentValue: value,\r\n template: this._results,\r\n });\r\n this._events();\r\n } else if (resultLength > 0 || isObject(result)) {\r\n this._index = this._selectFirst ? 0 : -1;\r\n this._results();\r\n this._events();\r\n }\r\n })\r\n .catch(() => {\r\n this._onLoading();\r\n this._reset();\r\n });\r\n };\r\n\r\n /**\r\n * Set or remove loading class\r\n *\r\n * @param {Boolean} type\r\n */\r\n _onLoading = (type) =>\r\n this._root.parentNode.classList[type ? \"add\" : \"remove\"](this._isLoading);\r\n\r\n /**\r\n * Set error class to the root element\r\n */\r\n _error = () => classList(this._root, \"remove\", this._err);\r\n\r\n /**\r\n * Events\r\n */\r\n _events = () => {\r\n // handle click on keydown [up, down, enter, tab, esc]\r\n onEvent(this._root, \"keydown\", this._handleKeys);\r\n\r\n onEvent(this._root, \"click\", this._handleShowItems);\r\n\r\n // temporarily disabled mouseleave\r\n [\"mousemove\", \"click\"].map((eventType) => {\r\n onEvent(this._resultList, eventType, this._handleMouse);\r\n });\r\n\r\n // close expanded items\r\n onEvent(document, \"click\", this._handleDocClick);\r\n };\r\n\r\n /**\r\n * Results\r\n *\r\n * @param {HTMLElement|String} template - html or string returned from the function,\r\n * look at the example - https://github.com/tomik23/autocomplete/blob/master/docs/js/examples/no-results.js#L30\r\n */\r\n _results = (template) => {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // clear result list\r\n this._resultList.textContent = \"\";\r\n\r\n // add all found records to otput ul\r\n const dataResults =\r\n this._matches.length === 0\r\n ? this._onResults({\r\n currentValue: this._value,\r\n matches: 0,\r\n template,\r\n })\r\n : this._onResults({\r\n currentValue: this._value,\r\n matches: this._matches,\r\n classGroup: this._classGroup,\r\n });\r\n\r\n // add data to ul\r\n this._resultList.insertAdjacentHTML(\"afterbegin\", dataResults);\r\n\r\n // add class isActive\r\n classList(this._resultWrap, \"add\", this._isActive);\r\n\r\n const checkIfClassGroupExist = this._classGroup\r\n ? `:not(.${this._classGroup})`\r\n : \"\";\r\n\r\n this._itemsLi = document.querySelectorAll(\r\n `#${this._outputUl} > li${checkIfClassGroupExist}`\r\n );\r\n\r\n // adding role, tabindex and aria\r\n addAriaToAllLiElements(this._itemsLi);\r\n\r\n // action on open results\r\n this._onOpened({\r\n type: \"results\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n\r\n // select first element\r\n this._selectFirstElement();\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n };\r\n\r\n /**\r\n * Hangle click on document\r\n *\r\n * @param {Event} object\r\n */\r\n _handleDocClick = ({ target }) => {\r\n let disableClose = null;\r\n\r\n // if 'target' is a ul and 'disableCloseOnSelect'\r\n // is a 'true' set 'disableClose' on true\r\n if (\r\n (target.closest(\"ul\") && this._disable) ||\r\n // when class classDisableClose\r\n // then do not not close results\r\n target.closest(`.${this._prevClosing}`)\r\n ) {\r\n disableClose = true;\r\n }\r\n\r\n if (target.id !== this._id && !disableClose) {\r\n this._reset();\r\n return;\r\n }\r\n };\r\n\r\n /**\r\n * Select first element\r\n */\r\n _selectFirstElement = () => {\r\n this._removeAria(select(`.${this._activeList}`));\r\n\r\n if (!this._selectFirst) {\r\n return;\r\n }\r\n\r\n const { firstElementChild } = this._resultList;\r\n\r\n const classSelectFirst =\r\n this._classGroup && this._matches.length > 0 && this._selectFirst\r\n ? firstElementChild.nextElementSibling\r\n : firstElementChild;\r\n\r\n // calback function onSelect when first element is true\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set attribute to first element\r\n setAttributes(classSelectFirst, {\r\n id: `${this._selectedOption}-0`,\r\n addClass: this._activeList,\r\n \"aria-selected\": \"true\",\r\n });\r\n\r\n // set aria active descendant\r\n setAriaActivedescendant(this._root, `${this._selectedOption}-0`);\r\n };\r\n\r\n /**\r\n * show items when items.length > 0 and is not empty\r\n */\r\n _handleShowItems = () => {\r\n // if resultWrap is not active and resultList is not empty\r\n if (\r\n this._resultList.textContent.length > 0 &&\r\n !classList(this._resultWrap, \"contains\", this._isActive)\r\n ) {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add isActive class to resultWrap\r\n classList(this._resultWrap, \"add\", this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n\r\n // select first element\r\n this._selectFirstElement();\r\n\r\n // callback function\r\n this._onOpened({\r\n type: \"showItems\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Adding text from the list when li is clicking\r\n * or adding aria-selected to li elements\r\n *\r\n * @param {Event} event\r\n */\r\n _handleMouse = (event) => {\r\n event.preventDefault();\r\n\r\n const { target, type } = event;\r\n const targetClosest = target.closest(\"li\");\r\n const targetClosestRole = targetClosest?.hasAttribute(\"role\");\r\n const activeClass = this._activeList;\r\n const activeClassElement = select(`.${activeClass}`);\r\n\r\n if (!targetClosest || !targetClosestRole) {\r\n return;\r\n }\r\n\r\n // click on li get element\r\n if (type === \"click\") {\r\n // get text from clicked li\r\n this._getTextFromLi(targetClosest);\r\n }\r\n\r\n if (\r\n type === \"mousemove\" &&\r\n !classList(targetClosest, \"contains\", activeClass)\r\n ) {\r\n this._removeAria(activeClassElement);\r\n\r\n // add aria to li\r\n this._setAria(targetClosest);\r\n this._index = this._indexLiSelected(targetClosest);\r\n\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Get text from li on enter or click\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _getTextFromLi = (element) => {\r\n if (!element || this._matches.length === 0) {\r\n // set default settings\r\n !this._disable && this._reset();\r\n\r\n return;\r\n }\r\n\r\n // get first element from li and set it to root\r\n this._root.value = getFirstElement(element);\r\n\r\n // onSubmit passing text to function\r\n this._onSubmit({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n results: this._resultList,\r\n });\r\n\r\n // set default settings\r\n if (!this._disable) {\r\n this._removeAria(element);\r\n this._reset();\r\n }\r\n\r\n // show clearBtn when select element\r\n this._clearButton && classList(this._clearBtn, \"remove\", \"hidden\");\r\n\r\n // remove cache\r\n this._cacheAct(\"remove\");\r\n };\r\n\r\n /**\r\n * Return which li element was selected\r\n * by hovering the mouse over\r\n *\r\n * @param {HTMLElement} target\r\n * @returns {Number}\r\n */\r\n _indexLiSelected = (target) =>\r\n // get index of li element\r\n Array.prototype.indexOf.call(this._itemsLi, target);\r\n\r\n /**\r\n * Navigating the elements li and enter\r\n *\r\n * @param {Event} event\r\n */\r\n _handleKeys = (event) => {\r\n const { keyCode } = event;\r\n\r\n const resultList = classList(this._resultWrap, \"contains\", this._isActive);\r\n\r\n const matchesLength = this._matches.length + 1;\r\n this._selectedLi = select(`.${this._activeList}`);\r\n\r\n // switch between keys\r\n switch (keyCode) {\r\n case keyCodes.UP:\r\n case keyCodes.DOWN:\r\n // Wrong cursor position in the input field #62\r\n // Prevents the cursor from moving to the beginning\r\n // of input as the cursor hovers over the results.\r\n event.preventDefault();\r\n\r\n if ((matchesLength <= 1 && this._selectFirst) || !resultList) {\r\n return;\r\n }\r\n\r\n // if keyCode is up\r\n if (keyCode === keyCodes.UP) {\r\n if (this._index < 0) {\r\n this._index = matchesLength - 1;\r\n }\r\n this._index -= 1;\r\n } else {\r\n this._index += 1;\r\n if (this._index >= matchesLength) {\r\n this._index = 0;\r\n }\r\n }\r\n\r\n // remove aria-selected\r\n this._removeAria(this._selectedLi);\r\n\r\n if (this._index >= 0 && this._index < matchesLength - 1) {\r\n if (this._toInput && resultList) {\r\n this._root.value = getFirstElement(this._itemsLi[this._index]);\r\n }\r\n\r\n // callback function\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set aria-selected\r\n this._setAria(this._itemsLi[this._index]);\r\n } else {\r\n // catch action\r\n this._cacheAct();\r\n setAriaActivedescendant(this._root);\r\n\r\n this._onSelected({\r\n index: null,\r\n element: this._root,\r\n object: null,\r\n });\r\n }\r\n\r\n break;\r\n // keycode enter\r\n case keyCodes.ENTER:\r\n this._getTextFromLi(this._selectedLi);\r\n break;\r\n\r\n // keycode escape and keycode tab\r\n case keyCodes.TAB:\r\n case keyCodes.ESC:\r\n event.stopPropagation(); // #120\r\n this._reset();\r\n\r\n break;\r\n default:\r\n break;\r\n }\r\n };\r\n\r\n /**\r\n * Set aria label on item li\r\n *\r\n * @param {HTMLElement} target\r\n */\r\n _setAria = (target) => {\r\n const selectedOption = `${this._selectedOption}-${this._indexLiSelected(\r\n target\r\n )}`;\r\n\r\n // set aria to li\r\n setAttributes(target, {\r\n id: selectedOption,\r\n \"aria-selected\": \"true\",\r\n addClass: this._activeList,\r\n });\r\n\r\n setAriaActivedescendant(this._root, selectedOption);\r\n\r\n // scrollIntoView when press up/down arrows\r\n followActiveElement(\r\n target,\r\n this._outputUl,\r\n this._classGroup,\r\n this._resultList\r\n );\r\n };\r\n\r\n /**\r\n * Remove aria label from item li\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _removeAria = (element) => {\r\n if (!element) return;\r\n\r\n // remove aria from li\r\n setAttributes(element, {\r\n id: \"\",\r\n removeClass: this._activeList,\r\n \"aria-selected\": \"false\",\r\n });\r\n };\r\n\r\n /**\r\n * Create clear button and\r\n * removing text from the input field\r\n */\r\n _clearbutton = () => {\r\n // stop when clear button is disabled\r\n if (!this._clearButton) return;\r\n\r\n // add aria to clear button\r\n setAttributes(this._clearBtn, {\r\n class: `${this._prefix}-clear hidden`,\r\n type: \"button\",\r\n title: this._clearBtnAriLabel,\r\n \"aria-label\": this._clearBtnAriLabel,\r\n });\r\n\r\n // insert clear button after input - root\r\n this._root.insertAdjacentElement(\"afterend\", this._clearBtn);\r\n };\r\n\r\n /**\r\n * Clicking on the clear button\r\n * publick destroy method\r\n */\r\n destroy = () => {\r\n // if clear button is true then add class hidden\r\n this._clearButton && classList(this._clearBtn, \"add\", \"hidden\");\r\n // clear value searchId\r\n this._root.value = \"\";\r\n // set focus\r\n this._root.focus();\r\n // remove li from ul\r\n this._resultList.textContent = \"\";\r\n // set default aria\r\n this._reset();\r\n // remove error if exist\r\n this._error();\r\n\r\n // callback function\r\n this._onReset(this._root);\r\n\r\n // remove listener\r\n offEvent(this._root, \"keydown\", this._handleKeys);\r\n offEvent(this._root, \"click\", this._handleShowItems);\r\n // remove listener on click on document\r\n offEvent(document, \"click\", this._handleDocClick);\r\n };\r\n}\r\n"],"names":["isObject","value","constructor","Object","isPromise","Boolean","then","setAttributes","el","object","key","classList","setAttribute","getFirstElement","element","firstElementChild","textContent","trim","scrollResultsToTop","resultList","resultWrap","scrollTop","offsetTop","offsetHeight","addAriaToAllLiElements","itemsLi","i","length","role","tabindex","showBtnToClearData","clearButton","destroy","onEvent","action","className","setAriaActivedescendant","root","type","getClassGroupHeight","outputUl","classGroup","allLiElements","document","querySelectorAll","height","slice","call","map","followActiveElement","target","previusElement","previousSibling","previusElementHeight","getAttribute","offsetBottom","scrollBottom","output","prefix","id","tabIndex","addClass","insertAdjacentElement","parentNode","insertBefore","nextSibling","createElement","select","querySelector","callback","addEventListener","offEvent","removeEventListener","keyCodes","ESC","ENTER","UP","DOWN","TAB","Autocomplete","delay","howManyCharacters","selectFirst","insertToInput","showAllValues","cache","disableCloseOnSelect","classPreventClosing","classPrefix","ariaLabelClear","onSearch","onResults","onSubmit","onOpened","onReset","onRender","onClose","noResults","onSelectedItem","_initial","_clearbutton","_root","_resultList","_outputUl","_resultWrap","_prefix","_handleInput","_showAll","_onRender","results","_cacheAct","_cache","_cacheData","removeAttribute","regex","replace","_regex","_delay","clearTimeout","_timeout","setTimeout","_searchItem","_reset","_id","removeClass","_isActive","_index","_selectFirst","_onClose","_value","_onLoading","_clearBtn","_clearButton","_characters","_onSearch","currentValue","result","rootValueLength","resultLength","_matches","Array","isArray","JSON","parse","stringify","_error","_noResults","template","_results","_events","catch","_isLoading","_err","_handleKeys","_handleShowItems","eventType","_handleMouse","_handleDocClick","dataResults","_onResults","matches","_classGroup","insertAdjacentHTML","checkIfClassGroupExist","_itemsLi","_onOpened","_selectFirstElement","disableClose","closest","_disable","_prevClosing","_removeAria","_activeList","classSelectFirst","nextElementSibling","_onSelected","index","_selectedOption","event","preventDefault","targetClosest","targetClosestRole","hasAttribute","activeClass","activeClassElement","_getTextFromLi","_setAria","_indexLiSelected","_onSubmit","prototype","indexOf","keyCode","matchesLength","_selectedLi","_toInput","stopPropagation","selectedOption","class","title","_clearBtnAriLabel","focus","_onReset","getElementById","Promise","resolve"],"mappings":";;;EAKA,MAAMA,QAAQ,GAAIC,KAAD,IACfA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAA1B,IAAsCA,KAAK,CAACC,WAAN,KAAsBC,MAD9D;EAUA,MAAMC,SAAS,GAAIH,KAAD,IAAWI,OAAO,CAACJ,KAAK,IAAI,OAAOA,KAAK,CAACK,IAAb,KAAsB,UAAhC,CAApC;EAQA,MAAMC,aAAa,GAAG,CAACC,EAAD,EAAKC,MAAL,KAAgB;EACpC,OAAK,IAAIC,GAAT,IAAgBD,MAAhB,EAAwB;EACtB,QAAIC,GAAG,KAAK,UAAZ,EAAwB;EACtBC,MAAAA,SAAS,CAACH,EAAD,EAAK,KAAL,EAAYC,MAAM,CAACC,GAAD,CAAlB,CAAT;EACD,KAFD,MAEO,IAAIA,GAAG,KAAK,aAAZ,EAA2B;EAChCC,MAAAA,SAAS,CAACH,EAAD,EAAK,QAAL,EAAeC,MAAM,CAACC,GAAD,CAArB,CAAT;EACD,KAFM,MAEA;EACLF,MAAAA,EAAE,CAACI,YAAH,CAAgBF,GAAhB,EAAqBD,MAAM,CAACC,GAAD,CAA3B;EACD;EACF;EACF,CAVD;EAkBA,MAAMG,eAAe,GAAIC,OAAD,I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line at end of file diff --git a/dist/js/autocomplete.min.js b/dist/js/autocomplete.min.js index 1f141e6..54914f5 100644 --- a/dist/js/autocomplete.min.js +++ b/dist/js/autocomplete.min.js @@ -1 +1 @@ -var Autocomplete=function(){"use strict";const t=(t,s)=>{for(let i in s)"addClass"===i?t.classList.add(s[i]):"removeClass"===i?t.classList.remove(s[i]):t.setAttribute(i,s[i])},s=(t,s)=>s.value=(t=>t.firstElementChild||t)(t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=(t,s)=>{t.setAttribute("aria-activedescendant",s||"")},e=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll("#"+t+" > li:not(."+s+")");let h=0;return[].slice.call(i).map(t=>h+=t.offsetHeight),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},a=t=>document.createElement(t),l=27,n=13,o=38,r=40,c=9;return class{constructor(d,u){let{delay:m=500,clearButton:p=!0,howManyCharacters:b=1,selectFirst:v=!1,insertToInput:f=!1,showAllValues:x=!1,cache:C=!1,disableCloseOnSelect:y=!1,classGroup:k,classPreventClosing:w,classPrefix:j,ariaLabelClear:V,onSearch:g,onResults:S=(()=>{}),onSubmit:O=(()=>{}),onOpened:A=(()=>{}),onReset:I=(()=>{}),onRender:R=(()=>{}),onClose:P=(()=>{}),noResults:T=(()=>{}),onSelectedItem:B=(()=>{})}=u;var G;this.t=()=>{var s,i,h,e,a;this.s(),s=this.i,i=this.h,h=this.l,e=this.o,a=this.u,t(i,{id:h,tabIndex:"0",role:"listbox"}),t(e,{addClass:a+"-results-wrapper"}),e.insertAdjacentElement("beforeend",i),s.parentNode.insertBefore(e,s.nextSibling),this.i.addEventListener("input",this.m),this.p&&this.i.addEventListener("click",this.m),this.v({element:this.i,results:this.h})},this.C=(t,s)=>{this.k&&("update"===t?this.i.setAttribute(this.j,s.value):"remove"===t?this.i.removeAttribute(this.j):this.i.value=this.i.getAttribute(this.j))},this.m=t=>{let{target:s,type:i}=t;if("true"===this.i.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.V,"\\$&");this.C("update",s);const e=this.p?0:this.g;clearTimeout(this.S),this.S=setTimeout(()=>{this.O(h.trim())},e)},this.A=()=>{var s;t(this.i,{"aria-owns":this.I+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),this.o.classList.remove(this.R),(0==(null==(s=this.P)?void 0:s.length)&&!this.T||this.p)&&(this.h.innerHTML=""),this.B=this.G?0:-1,this.J()},this.O=t=>{this.N=t,this.$(!0),function(t,s){void 0===t&&(t=!1),t&&(t.classList.remove("hidden"),t.addEventListener("click",s))}(this.q,this.destroy),0==t.length&&this.F&&this.q.classList.add("hidden"),this.L>t.length&&!this.p?this.$():this.M({currentValue:t,element:this.i}).then(s=>{const i=this.i.value.length,h=s.length;this.P=Array.isArray(s)?[...s]:JSON.parse(JSON.stringify(s)),this.$(),this.D(),0==h&&0==i&&this.q.classList.add("hidden"),0==h&&i?(this.i.classList.remove("auto-expanded"),this.A(),this.H({element:this.i,currentValue:t,template:this.K}),this.U()):(h>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.B=this.G?0:-1,this.K(),this.U())}).catch(()=>{this.$(),this.A()})},this.$=t=>this.i.parentNode.classList[t?"add":"remove"](this.W),this.D=()=>this.i.classList.remove(this.X),this.U=()=>{this.i.addEventListener("keydown",this.Y),this.i.addEventListener("click",this.Z),["mousemove","click"].map(t=>{this.h.addEventListener(t,this._)}),document.addEventListener("click",this.tt)},this.K=s=>{t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.h.innerHTML=0===this.P.length?this.st({currentValue:this.N,matches:0,template:s}):this.st({currentValue:this.N,matches:this.P,classGroup:this.it}),this.o.classList.add(this.R);const h=this.it?":not(."+this.it+")":"";this.ht=document.querySelectorAll("#"+this.l+" > li"+h),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.lt||s.closest("."+this.nt))&&(i=!0),s.id===this.I||i||this.A()},this.at=()=>{if(this.ot(document.querySelector("."+this.rt)),!this.G)return;const{firstElementChild:s}=this.h,i=this.it&&this.P.length>0&&this.G?s.nextElementSibling:s;this.ct({index:this.B,element:this.i,object:this.P[this.B]}),t(i,{id:this.dt+"-0",addClass:this.rt,"aria-selected":"true"}),h(this.i,this.dt+"-0")},this.Z=()=>{this.h.textContent.length>0&&!this.o.classList.contains(this.R)&&(t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.o.classList.add(this.R),i(this.h,this.o),this.at(),this.et({type:"showItems",element:this.i,results:this.h}))},this._=t=>{t.preventDefault();const{target:s,type:i}=t,h=s.closest("li"),e=null==h?void 0:h.hasAttribute("role"),a=this.rt,l=document.querySelector("."+a);h&&e&&("click"===i&&this.ut(h),"mousemove"!==i||h.classList.contains(a)||(this.ot(l),this.pt(h),this.B=this.bt(h),this.ct({index:this.B,element:this.i,object:this.P[this.B]})))},this.ut=t=>{t&&0!==this.P.length?(s(t,this.i),this.vt({index:this.B,element:this.i,object:this.P[this.B],results:this.h}),this.lt||(this.ot(t),this.A()),this.F&&this.q.classList.remove("hidden"),this.C("remove")):!this.lt&&this.A()},this.bt=t=>Array.prototype.indexOf.call(this.ht,t),this.Y=t=>{const{keyCode:i}=t,e=this.o.classList.contains(this.R),a=this.P.length+1;switch(this.ft=document.querySelector("."+this.rt),i){case o:case r:if(t.preventDefault(),a<=1&&this.G||!e)return;i===o?(this.B<0&&(this.B=a-1),this.B-=1):(this.B+=1,this.B>=a&&(this.B=0)),this.ot(this.ft),a>0&&this.B>=0&&this.B{const i=this.dt+"-"+this.bt(s);t(s,{id:i,"aria-selected":"true",addClass:this.rt}),h(this.i,i),e(s,this.l,this.it,this.h)},this.ot=s=>{s&&t(s,{id:"",removeClass:this.rt,"aria-selected":"false"})},this.s=()=>{this.F&&(t(this.q,{class:this.u+"-clear hidden",type:"button",title:this.xt,"aria-label":this.xt}),this.i.insertAdjacentElement("afterend",this.q))},this.destroy=()=>{this.F&&this.q.classList.add("hidden"),this.i.value="",this.i.focus(),this.h.textContent="",this.A(),this.D(),this.Ct(this.i),this.i.removeEventListener("keydown",this.Y),this.i.removeEventListener("click",this.Z),document.removeEventListener("click",this.tt)},this.I=d,this.i=document.getElementById(d),this.M=(G=g,Boolean(G&&"function"==typeof G.then)?g:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(g({currentValue:s,element:i}))}),this.st=S,this.v=R,this.vt=O,this.ct=B,this.et=A,this.Ct=I,this.H=T,this.J=P,this.g=m,this.L=b,this.F=p,this.G=v,this.T=f,this.p=x,this.it=k,this.nt=w,this.xt=V||"clear the search query",this.u=j?j+"-auto":"auto",this.lt=y,this.k=C,this.l=this.u+"-"+this.I+"-results",this.j="data-cache-auto-"+this.I,this.W=this.u+"-is-loading",this.R=this.u+"-is-active",this.rt=this.u+"-selected",this.dt=this.u+"-selected-option",this.X=this.u+"-error",this.V=/[|\\{}()[\]^$+*?.]/g,this.S=null,this.o=a("div"),this.h=a("ul"),this.q=a("button"),this.t()}}}(); +var Autocomplete=function(){"use strict";const t=(t,s)=>{for(let i in s)"addClass"===i?h(t,"add",s[i]):"removeClass"===i?h(t,"remove",s[i]):t.setAttribute(i,s[i])},s=t=>(t.firstElementChild||t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=(t,s,i)=>t.classList[s](i),e=(s,i)=>{t(s,{"aria-activedescendant":i||""})},a=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll("#"+t+" > li:not(."+s+")");let h=0;return[].slice.call(i).map(t=>h+=t.offsetHeight),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},n=t=>document.createElement(t),l=t=>document.querySelector(t),o=(t,s,i)=>{t.addEventListener(s,i)},r=(t,s,i)=>{t.removeEventListener(s,i)},c=27,d=13,u=38,m=40,p=9;return class{constructor(v,b){let{delay:f=500,clearButton:x=!0,howManyCharacters:C=1,selectFirst:y=!1,insertToInput:k=!1,showAllValues:w=!1,cache:g=!1,disableCloseOnSelect:j=!1,classGroup:V,classPreventClosing:S,classPrefix:O,ariaLabelClear:A,onSearch:I,onResults:R=(()=>{}),onSubmit:P=(()=>{}),onOpened:T=(()=>{}),onReset:B=(()=>{}),onRender:G=(()=>{}),onClose:J=(()=>{}),noResults:N=(()=>{}),onSelectedItem:$=(()=>{})}=b;var q;this.t=()=>{var s,i,h,e,a;this.s(),s=this.i,i=this.h,h=this.l,e=this.o,a=this.u,t(i,{id:h,tabIndex:"0",role:"listbox"}),t(e,{addClass:a+"-results-wrapper"}),e.insertAdjacentElement("beforeend",i),s.parentNode.insertBefore(e,s.nextSibling),o(this.i,"input",this.m),this.p&&o(this.i,"click",this.m),this.v({element:this.i,results:this.h})},this.C=(t,s)=>{this.k&&("update"===t?this.i.setAttribute(this.g,s.value):"remove"===t?this.i.removeAttribute(this.g):this.i.value=this.i.getAttribute(this.g))},this.m=t=>{let{target:s,type:i}=t;if("true"===this.i.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.j,"\\$&");this.C("update",s);const e=this.p?0:this.V;clearTimeout(this.S),this.S=setTimeout(()=>{this.O(h.trim())},e)},this.A=()=>{t(this.i,{"aria-owns":this.I+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),h(this.o,"remove",this.R),this.P=this.T?0:-1,this.B()},this.O=t=>{this.G=t,this.J(!0),function(t,s){void 0===t&&(t=!1),t&&(h(t,"remove","hidden"),o(t,"click",s))}(this.N,this.destroy),0==t.length&&this.$&&h(this.N,"add","hidden"),this.q>t.length&&!this.p?this.J():this.F({currentValue:t,element:this.i}).then(s=>{const i=this.i.value.length,e=s.length;this.L=Array.isArray(s)?s:JSON.parse(JSON.stringify(s)),this.J(),this.M(),0==e&&0==i&&h(this.N,"add","hidden"),0==e&&i?(h(this.i,"remove","auto-expanded"),this.A(),this.D({element:this.i,currentValue:t,template:this.H}),this.K()):(e>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.P=this.T?0:-1,this.H(),this.K())}).catch(()=>{this.J(),this.A()})},this.J=t=>this.i.parentNode.classList[t?"add":"remove"](this.U),this.M=()=>h(this.i,"remove",this.W),this.K=()=>{o(this.i,"keydown",this.X),o(this.i,"click",this.Y),["mousemove","click"].map(t=>{o(this.h,t,this.Z)}),o(document,"click",this._)},this.H=s=>{t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.h.textContent="";const e=0===this.L.length?this.tt({currentValue:this.G,matches:0,template:s}):this.tt({currentValue:this.G,matches:this.L,classGroup:this.st});this.h.insertAdjacentHTML("afterbegin",e),h(this.o,"add",this.R);const a=this.st?":not(."+this.st+")":"";this.it=document.querySelectorAll("#"+this.l+" > li"+a),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.at||s.closest("."+this.nt))&&(i=!0),s.id===this.I||i||this.A()},this.et=()=>{if(this.lt(l("."+this.ot)),!this.T)return;const{firstElementChild:s}=this.h,i=this.st&&this.L.length>0&&this.T?s.nextElementSibling:s;this.rt({index:this.P,element:this.i,object:this.L[this.P]}),t(i,{id:this.ct+"-0",addClass:this.ot,"aria-selected":"true"}),e(this.i,this.ct+"-0")},this.Y=()=>{this.h.textContent.length>0&&!h(this.o,"contains",this.R)&&(t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),h(this.o,"add",this.R),i(this.h,this.o),this.et(),this.ht({type:"showItems",element:this.i,results:this.h}))},this.Z=t=>{t.preventDefault();const{target:s,type:i}=t,e=s.closest("li"),a=null==e?void 0:e.hasAttribute("role"),n=this.ot,o=l("."+n);e&&a&&("click"===i&&this.dt(e),"mousemove"!==i||h(e,"contains",n)||(this.lt(o),this.ut(e),this.P=this.pt(e),this.rt({index:this.P,element:this.i,object:this.L[this.P]})))},this.dt=t=>{t&&0!==this.L.length?(this.i.value=s(t),this.vt({index:this.P,element:this.i,object:this.L[this.P],results:this.h}),this.at||(this.lt(t),this.A()),this.$&&h(this.N,"remove","hidden"),this.C("remove")):!this.at&&this.A()},this.pt=t=>Array.prototype.indexOf.call(this.it,t),this.X=t=>{const{keyCode:i}=t,a=h(this.o,"contains",this.R),n=this.L.length+1;switch(this.bt=l("."+this.ot),i){case u:case m:if(t.preventDefault(),n<=1&&this.T||!a)return;i===u?(this.P<0&&(this.P=n-1),this.P-=1):(this.P+=1,this.P>=n&&(this.P=0)),this.lt(this.bt),this.P>=0&&this.P{const i=this.ct+"-"+this.pt(s);t(s,{id:i,"aria-selected":"true",addClass:this.ot}),e(this.i,i),a(s,this.l,this.st,this.h)},this.lt=s=>{s&&t(s,{id:"",removeClass:this.ot,"aria-selected":"false"})},this.s=()=>{this.$&&(t(this.N,{class:this.u+"-clear hidden",type:"button",title:this.xt,"aria-label":this.xt}),this.i.insertAdjacentElement("afterend",this.N))},this.destroy=()=>{this.$&&h(this.N,"add","hidden"),this.i.value="",this.i.focus(),this.h.textContent="",this.A(),this.M(),this.Ct(this.i),r(this.i,"keydown",this.X),r(this.i,"click",this.Y),r(document,"click",this._)},this.I=v,this.i=document.getElementById(v),this.F=(q=I,Boolean(q&&"function"==typeof q.then)?I:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(I({currentValue:s,element:i}))}),this.tt=R,this.v=G,this.vt=P,this.rt=$,this.ht=T,this.Ct=B,this.D=N,this.B=J,this.V=f,this.q=C,this.$=x,this.T=y,this.ft=k,this.p=w,this.st=V,this.nt=S,this.xt=A||"clear the search query",this.u=O?O+"-auto":"auto",this.at=j,this.k=g,this.l=this.u+"-"+this.I+"-results",this.g="data-cache-auto-"+this.I,this.U=this.u+"-is-loading",this.R=this.u+"-is-active",this.ot=this.u+"-selected",this.ct=this.u+"-selected-option",this.W=this.u+"-error",this.j=/[|\\{}()[\]^$+*?.]/g,this.S=null,this.o=n("div"),this.h=n("ul"),this.N=n("button"),this.t()}}}(); diff --git a/dist/js/autocomplete.umd.js b/dist/js/autocomplete.umd.js index 2177fab..76b9eae 100644 --- a/dist/js/autocomplete.umd.js +++ b/dist/js/autocomplete.umd.js @@ -9,17 +9,15 @@ const setAttributes = (el, object) => { for (let key in object) { if (key === "addClass") { - el.classList.add(object[key]); + classList(el, "add", object[key]); } else if (key === "removeClass") { - el.classList.remove(object[key]); + classList(el, "remove", object[key]); } else { el.setAttribute(key, object[key]); } } }; - const getFirstElement = element => element.firstElementChild || element; - const getFirstElementFromLiAndAddToInput = (element, root) => - root.value = getFirstElement(element).textContent.trim(); + const getFirstElement = element => (element.firstElementChild || element).textContent.trim(); const scrollResultsToTop = (resultList, resultWrap) => { resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight; }; @@ -39,16 +37,19 @@ clearButton = false; } if (!clearButton) return; - clearButton.classList.remove("hidden"); - clearButton.addEventListener("click", destroy); + classList(clearButton, "remove", "hidden"); + onEvent(clearButton, "click", destroy); }; + const classList = (element, action, className) => element.classList[action](className); const setAriaActivedescendant = (root, type) => { - root.setAttribute("aria-activedescendant", type || ""); + setAttributes(root, { + "aria-activedescendant": type || "" + }); }; const getClassGroupHeight = (outputUl, classGroup) => { - const allLi = document.querySelectorAll("#" + outputUl + " > li:not(." + classGroup + ")"); + const allLiElements = document.querySelectorAll("#" + outputUl + " > li:not(." + classGroup + ")"); let height = 0; - [].slice.call(allLi).map(el => height += el.offsetHeight); + [].slice.call(allLiElements).map(el => height += el.offsetHeight); return height; }; const followActiveElement = (target, outputUl, classGroup, resultList) => { @@ -80,6 +81,13 @@ root.parentNode.insertBefore(resultWrap, root.nextSibling); }; const createElement = type => document.createElement(type); + const select = element => document.querySelector(element); + const onEvent = (element, action, callback) => { + element.addEventListener(action, callback); + }; + const offEvent = (element, action, callback) => { + element.removeEventListener(action, callback); + }; const keyCodes = { ESC: 27, @@ -117,8 +125,8 @@ this._initial = () => { this._clearbutton(); output(this._root, this._resultList, this._outputUl, this._resultWrap, this._prefix); - this._root.addEventListener("input", this._handleInput); - this._showAll && this._root.addEventListener("click", this._handleInput); + onEvent(this._root, "input", this._handleInput); + this._showAll && onEvent(this._root, "click", this._handleInput); this._onRender({ element: this._root, results: this._resultList @@ -151,7 +159,6 @@ }, delay); }; this._reset = () => { - var _this$_matches; setAttributes(this._root, { "aria-owns": this._id + "-list", "aria-expanded": "false", @@ -160,19 +167,16 @@ role: "combobox", removeClass: "auto-expanded" }); - this._resultWrap.classList.remove(this._isActive); - if (((_this$_matches = this._matches) == null ? void 0 : _this$_matches.length) == 0 && !this._toInput || this._showAll) { - this._resultList.innerHTML = ""; - } + classList(this._resultWrap, "remove", this._isActive); this._index = this._selectFirst ? 0 : -1; this._onClose(); }; this._searchItem = value => { this._value = value; this._onLoading(true); - showBtnToClearData(this._cBtn, this.destroy); + showBtnToClearData(this._clearBtn, this.destroy); if (value.length == 0 && this._clearButton) { - this._cBtn.classList.add("hidden"); + classList(this._clearBtn, "add", "hidden"); } if (this._characters > value.length && !this._showAll) { this._onLoading(); @@ -184,14 +188,14 @@ }).then(result => { const rootValueLength = this._root.value.length; const resultLength = result.length; - this._matches = Array.isArray(result) ? [...result] : JSON.parse(JSON.stringify(result)); + this._matches = Array.isArray(result) ? result : JSON.parse(JSON.stringify(result)); this._onLoading(); this._error(); if (resultLength == 0 && rootValueLength == 0) { - this._cBtn.classList.add("hidden"); + classList(this._clearBtn, "add", "hidden"); } if (resultLength == 0 && rootValueLength) { - this._root.classList.remove("auto-expanded"); + classList(this._root, "remove", "auto-expanded"); this._reset(); this._noResults({ element: this._root, @@ -210,21 +214,22 @@ }); }; this._onLoading = type => this._root.parentNode.classList[type ? "add" : "remove"](this._isLoading); - this._error = () => this._root.classList.remove(this._err); + this._error = () => classList(this._root, "remove", this._err); this._events = () => { - this._root.addEventListener("keydown", this._handleKeys); - this._root.addEventListener("click", this._handleShowItems); + onEvent(this._root, "keydown", this._handleKeys); + onEvent(this._root, "click", this._handleShowItems); ["mousemove", "click"].map(eventType => { - this._resultList.addEventListener(eventType, this._handleMouse); + onEvent(this._resultList, eventType, this._handleMouse); }); - document.addEventListener("click", this._handleDocClick); + onEvent(document, "click", this._handleDocClick); }; this._results = template => { setAttributes(this._root, { "aria-expanded": "true", addClass: this._prefix + "-expanded" }); - this._resultList.innerHTML = this._matches.length === 0 ? this._onResults({ + this._resultList.textContent = ""; + const dataResults = this._matches.length === 0 ? this._onResults({ currentValue: this._value, matches: 0, template @@ -233,7 +238,8 @@ matches: this._matches, classGroup: this._classGroup }); - this._resultWrap.classList.add(this._isActive); + this._resultList.insertAdjacentHTML("afterbegin", dataResults); + classList(this._resultWrap, "add", this._isActive); const checkIfClassGroupExist = this._classGroup ? ":not(." + this._classGroup + ")" : ""; this._itemsLi = document.querySelectorAll("#" + this._outputUl + " > li" + checkIfClassGroupExist); addAriaToAllLiElements(this._itemsLi); @@ -242,7 +248,7 @@ element: this._root, results: this._resultList }); - this._selectFirstEl(); + this._selectFirstElement(); scrollResultsToTop(this._resultList, this._resultWrap); }; this._handleDocClick = _ref3 => { @@ -259,8 +265,8 @@ return; } }; - this._selectFirstEl = () => { - this._remAria(document.querySelector("." + this._activeList)); + this._selectFirstElement = () => { + this._removeAria(select("." + this._activeList)); if (!this._selectFirst) { return; } @@ -281,14 +287,14 @@ setAriaActivedescendant(this._root, this._selectedOption + "-0"); }; this._handleShowItems = () => { - if (this._resultList.textContent.length > 0 && !this._resultWrap.classList.contains(this._isActive)) { + if (this._resultList.textContent.length > 0 && !classList(this._resultWrap, "contains", this._isActive)) { setAttributes(this._root, { "aria-expanded": "true", addClass: this._prefix + "-expanded" }); - this._resultWrap.classList.add(this._isActive); + classList(this._resultWrap, "add", this._isActive); scrollResultsToTop(this._resultList, this._resultWrap); - this._selectFirstEl(); + this._selectFirstElement(); this._onOpened({ type: "showItems", element: this._root, @@ -305,15 +311,15 @@ const targetClosest = target.closest("li"); const targetClosestRole = targetClosest == null ? void 0 : targetClosest.hasAttribute("role"); const activeClass = this._activeList; - const activeClassElement = document.querySelector("." + activeClass); + const activeClassElement = select("." + activeClass); if (!targetClosest || !targetClosestRole) { return; } if (type === "click") { this._getTextFromLi(targetClosest); } - if (type === "mousemove" && !targetClosest.classList.contains(activeClass)) { - this._remAria(activeClassElement); + if (type === "mousemove" && !classList(targetClosest, "contains", activeClass)) { + this._removeAria(activeClassElement); this._setAria(targetClosest); this._index = this._indexLiSelected(targetClosest); this._onSelected({ @@ -328,7 +334,7 @@ !this._disable && this._reset(); return; } - getFirstElementFromLiAndAddToInput(element, this._root); + this._root.value = getFirstElement(element); this._onSubmit({ index: this._index, element: this._root, @@ -336,10 +342,10 @@ results: this._resultList }); if (!this._disable) { - this._remAria(element); + this._removeAria(element); this._reset(); } - this._clearButton && this._cBtn.classList.remove("hidden"); + this._clearButton && classList(this._clearBtn, "remove", "hidden"); this._cacheAct("remove"); }; this._indexLiSelected = target => @@ -348,9 +354,9 @@ const { keyCode } = event; - const resultList = this._resultWrap.classList.contains(this._isActive); + const resultList = classList(this._resultWrap, "contains", this._isActive); const matchesLength = this._matches.length + 1; - this._selectedLi = document.querySelector("." + this._activeList); + this._selectedLi = select("." + this._activeList); switch (keyCode) { case keyCodes.UP: case keyCodes.DOWN: @@ -369,10 +375,10 @@ this._index = 0; } } - this._remAria(this._selectedLi); - if (matchesLength > 0 && this._index >= 0 && this._index < matchesLength - 1) { + this._removeAria(this._selectedLi); + if (this._index >= 0 && this._index < matchesLength - 1) { if (this._toInput && resultList) { - getFirstElementFromLiAndAddToInput(this._itemsLi[this._index], this._root); + this._root.value = getFirstElement(this._itemsLi[this._index]); } this._onSelected({ index: this._index, @@ -410,7 +416,7 @@ setAriaActivedescendant(this._root, selectedOption); followActiveElement(target, this._outputUl, this._classGroup, this._resultList); }; - this._remAria = element => { + this._removeAria = element => { if (!element) return; setAttributes(element, { id: "", @@ -420,25 +426,25 @@ }; this._clearbutton = () => { if (!this._clearButton) return; - setAttributes(this._cBtn, { + setAttributes(this._clearBtn, { class: this._prefix + "-clear hidden", type: "button", title: this._clearBtnAriLabel, "aria-label": this._clearBtnAriLabel }); - this._root.insertAdjacentElement("afterend", this._cBtn); + this._root.insertAdjacentElement("afterend", this._clearBtn); }; this.destroy = () => { - this._clearButton && this._cBtn.classList.add("hidden"); + this._clearButton && classList(this._clearBtn, "add", "hidden"); this._root.value = ""; this._root.focus(); this._resultList.textContent = ""; this._reset(); this._error(); this._onReset(this._root); - this._root.removeEventListener("keydown", this._handleKeys); - this._root.removeEventListener("click", this._handleShowItems); - document.removeEventListener("click", this._handleDocClick); + offEvent(this._root, "keydown", this._handleKeys); + offEvent(this._root, "click", this._handleShowItems); + offEvent(document, "click", this._handleDocClick); }; this._id = _element; this._root = document.getElementById(_element); @@ -483,7 +489,7 @@ this._timeout = null; this._resultWrap = createElement("div"); this._resultList = createElement("ul"); - this._cBtn = createElement("button"); + this._clearBtn = createElement("button"); this._initial(); } } diff --git a/dist/js/autocomplete.umd.js.map b/dist/js/autocomplete.umd.js.map index bca1b36..ed95623 100644 --- a/dist/js/autocomplete.umd.js.map +++ b/dist/js/autocomplete.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"autocomplete.umd.js","sources":["../../sources/js/utils/function.js","../../sources/js/utils/keyCodes.js","../../sources/js/script.js"],"sourcesContent":["/**\r\n * Check is a Object\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isObject = (value) =>\r\n value && typeof value === \"object\" && value.constructor === Object;\r\n\r\n/**\r\n * Check if is a Promise\r\n * https://stackoverflow.com/a/53955664/10424385\r\n *\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isPromise = (value) => Boolean(value && typeof value.then === \"function\");\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n if (key === \"addClass\") {\r\n el.classList.add(object[key]);\r\n } else if (key === \"removeClass\") {\r\n el.classList.remove(object[key]);\r\n } else {\r\n el.setAttribute(key, object[key]);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Get first element from child\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {HTMLELement}\r\n */\r\nconst getFirstElement = (element) => element.firstElementChild || element;\r\n\r\n/**\r\n * Set data from li to input\r\n *\r\n * @param {String} element\r\n * @param {HTMLElement} root\r\n * @returns {String}\r\n */\r\nconst getFirstElementFromLiAndAddToInput = (element, root) =>\r\n // get first element from li and add to input\r\n (root.value = getFirstElement(element).textContent.trim());\r\n\r\n/**\r\n * Scroll to top result-list\r\n * @param {HTMLElement} resultList\r\n * @param {HTMLElement} resultWrap\r\n */\r\nconst scrollResultsToTop = (resultList, resultWrap) => {\r\n // if there is an overflow of ul element, after\r\n // opening we always move ul to the top of the results\r\n resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight;\r\n};\r\n\r\n/**\r\n * Adding role, tabindex, aria and call handleMouse\r\n *\r\n * @param {HTMLElement} itemsLi\r\n */\r\nconst addAriaToAllLiElements = (itemsLi) => {\r\n // add role to all li elements\r\n for (let i = 0; i < itemsLi.length; i++) {\r\n setAttributes(itemsLi[i], {\r\n role: \"option\",\r\n tabindex: \"-1\",\r\n \"aria-selected\": \"false\",\r\n \"aria-setsize\": itemsLi.length,\r\n \"aria-posinset\": i,\r\n });\r\n }\r\n};\r\n\r\n/**\r\n * Show btn to clear data\r\n *\r\n * @param {HTMLElement} clearButton - button to clear data\r\n * @param {Function} destroy - destroy function\r\n */\r\nconst showBtnToClearData = (clearButton = false, destroy) => {\r\n if (!clearButton) return;\r\n\r\n clearButton.classList.remove(\"hidden\");\r\n // add event to clear button\r\n clearButton.addEventListener(\"click\", destroy);\r\n};\r\n\r\n/**\r\n * Set aria-activedescendant\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {String} type\r\n */\r\nconst setAriaActivedescendant = (root, type) => {\r\n root.setAttribute(\"aria-activedescendant\", type || \"\");\r\n};\r\n\r\n/**\r\n * Get height of ul without group class\r\n *\r\n * @param {String} outputUl\r\n * @param {String} classGroup\r\n * @returns {Number}\r\n */\r\nconst getClassGroupHeight = (outputUl, classGroup) => {\r\n // get height of ul without group class\r\n const allLi = document.querySelectorAll(\r\n `#${outputUl} > li:not(.${classGroup})`\r\n );\r\n let height = 0;\r\n [].slice.call(allLi).map((el) => (height += el.offsetHeight));\r\n\r\n // return height\r\n return height;\r\n};\r\n\r\n/**\r\n * Scroll into view when press up/down arrows\r\n *\r\n * @param {HTMLElement} target\r\n * @param {HTMLElement} outputUl\r\n * @param {String} classGroup\r\n * @param {HTMLElement} resultList\r\n */\r\nconst followActiveElement = (target, outputUl, classGroup, resultList) => {\r\n const previusElement = resultList.previousSibling;\r\n\r\n const previusElementHeight = previusElement ? previusElement.offsetHeight : 0;\r\n\r\n if (target.getAttribute(\"aria-posinset\") == \"0\") {\r\n resultList.scrollTop =\r\n target.offsetTop - getClassGroupHeight(outputUl, classGroup);\r\n }\r\n\r\n if (target.offsetTop - previusElementHeight < resultList.scrollTop) {\r\n resultList.scrollTop = target.offsetTop - previusElementHeight;\r\n } else {\r\n const offsetBottom =\r\n target.offsetTop + target.offsetHeight - previusElementHeight;\r\n const scrollBottom = resultList.scrollTop + resultList.offsetHeight;\r\n if (offsetBottom > scrollBottom) {\r\n resultList.scrollTop = offsetBottom - resultList.offsetHeight;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Create output-list and put after search input\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {HTMLElement} resultList - output-list ul\r\n * @param {String} outputUl - id name of output-list\r\n * @param {HTMLElement} resultWrap - wrapper ul element\r\n * @param {String} prefix - add prefix to all class auto\r\n */\r\nconst output = (root, resultList, outputUl, resultWrap, prefix) => {\r\n // set attribute to results-list\r\n setAttributes(resultList, {\r\n id: outputUl,\r\n tabIndex: \"0\",\r\n role: \"listbox\",\r\n });\r\n\r\n // add class to wrap element\r\n setAttributes(resultWrap, {\r\n addClass: `${prefix}-results-wrapper`,\r\n });\r\n\r\n // insert the results into the wrap element\r\n resultWrap.insertAdjacentElement(\"beforeend\", resultList);\r\n\r\n // insert the wrap element after the search input\r\n root.parentNode.insertBefore(resultWrap, root.nextSibling);\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLDivElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport {\r\n addAriaToAllLiElements,\r\n createElement,\r\n followActiveElement,\r\n getFirstElementFromLiAndAddToInput,\r\n isObject,\r\n isPromise,\r\n output,\r\n scrollResultsToTop,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n};\r\n","/**\r\n * Key codes\r\n */\r\nconst keyCodes = {\r\n ESC: 27,\r\n ENTER: 13,\r\n UP: 38,\r\n DOWN: 40,\r\n TAB: 9,\r\n};\r\n\r\nexport default keyCodes;\r\n","import {\r\n addAriaToAllLiElements,\r\n createElement,\r\n followActiveElement,\r\n getFirstElementFromLiAndAddToInput,\r\n isObject,\r\n isPromise,\r\n output,\r\n scrollResultsToTop,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n} from \"./utils/function\";\r\n\r\nimport keyCodes from \"./utils/keyCodes\";\r\n\r\n/**\r\n * @class Autocomplete\r\n */\r\nexport default class Autocomplete {\r\n /**\r\n * Constructor\r\n *\r\n * @param {String} element\r\n * @param {Object} object\r\n */\r\n constructor(\r\n element,\r\n {\r\n delay = 500,\r\n clearButton = true,\r\n howManyCharacters = 1,\r\n selectFirst = false,\r\n insertToInput = false,\r\n showAllValues = false,\r\n cache = false,\r\n disableCloseOnSelect = false,\r\n classGroup,\r\n classPreventClosing,\r\n classPrefix,\r\n ariaLabelClear,\r\n onSearch,\r\n onResults = () => {},\r\n onSubmit = () => {},\r\n onOpened = () => {},\r\n onReset = () => {},\r\n onRender = () => {},\r\n onClose = () => {},\r\n noResults = () => {},\r\n onSelectedItem = () => {},\r\n }\r\n ) {\r\n this._id = element;\r\n this._root = document.getElementById(element);\r\n this._onSearch = isPromise(onSearch)\r\n ? onSearch\r\n : ({ currentValue, element }) =>\r\n Promise.resolve(onSearch({ currentValue, element }));\r\n this._onResults = onResults;\r\n this._onRender = onRender;\r\n this._onSubmit = onSubmit;\r\n this._onSelected = onSelectedItem;\r\n this._onOpened = onOpened;\r\n this._onReset = onReset;\r\n this._noResults = noResults;\r\n this._onClose = onClose;\r\n\r\n this._delay = delay;\r\n this._characters = howManyCharacters;\r\n this._clearButton = clearButton;\r\n this._selectFirst = selectFirst;\r\n this._toInput = insertToInput;\r\n this._showAll = showAllValues;\r\n this._classGroup = classGroup;\r\n this._prevClosing = classPreventClosing;\r\n this._clearBtnAriLabel = ariaLabelClear\r\n ? ariaLabelClear\r\n : \"clear the search query\";\r\n this._prefix = classPrefix ? `${classPrefix}-auto` : \"auto\";\r\n this._disable = disableCloseOnSelect;\r\n\r\n // default config\r\n this._cache = cache;\r\n this._outputUl = `${this._prefix}-${this._id}-results`;\r\n this._cacheData = `data-cache-auto-${this._id}`;\r\n this._isLoading = `${this._prefix}-is-loading`;\r\n this._isActive = `${this._prefix}-is-active`;\r\n this._activeList = `${this._prefix}-selected`;\r\n this._selectedOption = `${this._prefix}-selected-option`;\r\n this._err = `${this._prefix}-error`;\r\n this._regex = /[|\\\\{}()[\\]^$+*?.]/g;\r\n this._timeout = null;\r\n\r\n this._resultWrap = createElement(\"div\");\r\n this._resultList = createElement(\"ul\");\r\n this._cBtn = createElement(\"button\");\r\n\r\n this._initial();\r\n }\r\n\r\n /**\r\n * Initial function\r\n */\r\n _initial = () => {\r\n this._clearbutton();\r\n\r\n output(\r\n this._root,\r\n this._resultList,\r\n this._outputUl,\r\n this._resultWrap,\r\n this._prefix\r\n );\r\n\r\n // default aria\r\n // this.reset();\r\n this._root.addEventListener(\"input\", this._handleInput);\r\n\r\n // show all values on click root input\r\n this._showAll && this._root.addEventListener(\"click\", this._handleInput);\r\n\r\n // calback functions\r\n this._onRender({\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n };\r\n\r\n /**\r\n * Actions on input\r\n *\r\n * @param {String} type - set attribute depending on type\r\n * @param {String} target\r\n */\r\n _cacheAct = (type, target) => {\r\n if (!this._cache) return;\r\n\r\n if (type === \"update\") {\r\n this._root.setAttribute(this._cacheData, target.value);\r\n } else if (type === \"remove\") {\r\n this._root.removeAttribute(this._cacheData);\r\n } else {\r\n this._root.value = this._root.getAttribute(this._cacheData);\r\n }\r\n };\r\n\r\n /**\r\n * Handle input\r\n *\r\n * @param {Event} object\r\n */\r\n _handleInput = ({ target, type }) => {\r\n if (\r\n this._root.getAttribute(\"aria-expanded\") === \"true\" &&\r\n type === \"click\"\r\n ) {\r\n return;\r\n }\r\n\r\n // replace all special characters\r\n const regex = target.value.replace(this._regex, \"\\\\$&\");\r\n\r\n // update data attribute cache\r\n this._cacheAct(\"update\", target);\r\n\r\n const delay = this._showAll ? 0 : this._delay;\r\n // clear timeout\r\n clearTimeout(this._timeout);\r\n this._timeout = setTimeout(() => {\r\n this._searchItem(regex.trim());\r\n }, delay);\r\n };\r\n\r\n /**\r\n * Default aria\r\n */\r\n _reset = () => {\r\n // set attributes to root - input\r\n setAttributes(this._root, {\r\n \"aria-owns\": `${this._id}-list`,\r\n \"aria-expanded\": \"false\",\r\n \"aria-autocomplete\": \"list\",\r\n \"aria-activedescendant\": \"\",\r\n role: \"combobox\",\r\n removeClass: \"auto-expanded\",\r\n });\r\n\r\n // remove class isActive\r\n this._resultWrap.classList.remove(this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n // scrollResultsToTop(this.resultList, this.resultWrap);\r\n\r\n // remove result when lengh = 0 and insertToInput is false\r\n if ((this._matches?.length == 0 && !this._toInput) || this._showAll) {\r\n this._resultList.innerHTML = \"\";\r\n }\r\n\r\n // set index\r\n this._index = this._selectFirst ? 0 : -1;\r\n\r\n // callback function\r\n this._onClose();\r\n };\r\n\r\n /**\r\n * The async function gets the text from the search\r\n * and returns the matching array\r\n *\r\n * @param {String} value\r\n */\r\n _searchItem = (value) => {\r\n this._value = value;\r\n\r\n // if searching show loading icon\r\n this._onLoading(true);\r\n\r\n // hide button clear\r\n showBtnToClearData(this._cBtn, this.destroy);\r\n\r\n // if there is no value and clearButton is true\r\n if (value.length == 0 && this._clearButton) {\r\n this._cBtn.classList.add(\"hidden\");\r\n }\r\n\r\n // if declare characters more then value.len and showAll is false\r\n // remove class isActive\r\n if (this._characters > value.length && !this._showAll) {\r\n this._onLoading();\r\n return;\r\n }\r\n\r\n // callblack function onSearch\r\n this._onSearch({ currentValue: value, element: this._root })\r\n .then((result) => {\r\n const rootValueLength = this._root.value.length;\r\n const resultLength = result.length;\r\n // set no result\r\n this._matches = Array.isArray(result)\r\n ? [...result]\r\n : JSON.parse(JSON.stringify(result));\r\n\r\n this._onLoading();\r\n this._error();\r\n\r\n // if use destroy() method\r\n if (resultLength == 0 && rootValueLength == 0) {\r\n this._cBtn.classList.add(\"hidden\");\r\n }\r\n\r\n if (resultLength == 0 && rootValueLength) {\r\n this._root.classList.remove(\"auto-expanded\");\r\n this._reset();\r\n this._noResults({\r\n element: this._root,\r\n currentValue: value,\r\n template: this._results,\r\n });\r\n this._events();\r\n } else if (resultLength > 0 || isObject(result)) {\r\n this._index = this._selectFirst ? 0 : -1;\r\n this._results();\r\n this._events();\r\n }\r\n })\r\n .catch(() => {\r\n this._onLoading();\r\n this._reset();\r\n });\r\n };\r\n\r\n /**\r\n * Set or remove loading class\r\n *\r\n * @param {Boolean} type\r\n */\r\n _onLoading = (type) =>\r\n this._root.parentNode.classList[type ? \"add\" : \"remove\"](this._isLoading);\r\n\r\n /**\r\n * Set error class to the root element\r\n */\r\n _error = () => this._root.classList.remove(this._err);\r\n\r\n /**\r\n * Events\r\n */\r\n _events = () => {\r\n // handle click on keydown [up, down, enter, tab, esc]\r\n this._root.addEventListener(\"keydown\", this._handleKeys);\r\n\r\n //\r\n this._root.addEventListener(\"click\", this._handleShowItems);\r\n\r\n // temporarily disabled mouseleave\r\n [\"mousemove\", \"click\"].map((eventType) => {\r\n this._resultList.addEventListener(eventType, this._handleMouse);\r\n });\r\n\r\n // close expanded items\r\n document.addEventListener(\"click\", this._handleDocClick);\r\n };\r\n\r\n /**\r\n * Results\r\n *\r\n * @param {HTMLElement|String} template - html or string returned from the function,\r\n * look at the example - https://github.com/tomik23/autocomplete/blob/master/docs/js/examples/no-results.js#L30\r\n */\r\n _results = (template) => {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add all found records to otput ul\r\n this._resultList.innerHTML =\r\n this._matches.length === 0\r\n ? this._onResults({\r\n currentValue: this._value,\r\n matches: 0,\r\n template,\r\n })\r\n : this._onResults({\r\n currentValue: this._value,\r\n matches: this._matches,\r\n classGroup: this._classGroup,\r\n });\r\n\r\n this._resultWrap.classList.add(this._isActive);\r\n\r\n const checkIfClassGroupExist = this._classGroup\r\n ? `:not(.${this._classGroup})`\r\n : \"\";\r\n\r\n this._itemsLi = document.querySelectorAll(\r\n `#${this._outputUl} > li${checkIfClassGroupExist}`\r\n );\r\n\r\n // adding role, tabindex and aria\r\n addAriaToAllLiElements(this._itemsLi);\r\n\r\n // action on open results\r\n this._onOpened({\r\n type: \"results\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n\r\n // select first element\r\n this._selectFirstEl();\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n };\r\n\r\n /**\r\n * Hangle click on document\r\n *\r\n * @param {Event} object\r\n */\r\n _handleDocClick = ({ target }) => {\r\n let disableClose = null;\r\n\r\n // if 'target' is a ul and 'disableCloseOnSelect'\r\n // is a 'true' set 'disableClose' on true\r\n if (\r\n (target.closest(\"ul\") && this._disable) ||\r\n // when class classDisableClose\r\n // then do not not close results\r\n target.closest(`.${this._prevClosing}`)\r\n ) {\r\n disableClose = true;\r\n }\r\n\r\n if (target.id !== this._id && !disableClose) {\r\n this._reset();\r\n return;\r\n }\r\n };\r\n\r\n /**\r\n * Select first element\r\n */\r\n _selectFirstEl = () => {\r\n this._remAria(document.querySelector(`.${this._activeList}`));\r\n\r\n if (!this._selectFirst) {\r\n return;\r\n }\r\n\r\n const { firstElementChild } = this._resultList;\r\n\r\n const classSelectFirst =\r\n this._classGroup && this._matches.length > 0 && this._selectFirst\r\n ? firstElementChild.nextElementSibling\r\n : firstElementChild;\r\n\r\n // calback function onSelect when first element is true\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set attribute to first element\r\n setAttributes(classSelectFirst, {\r\n id: `${this._selectedOption}-0`,\r\n addClass: this._activeList,\r\n \"aria-selected\": \"true\",\r\n });\r\n\r\n // set aria active descendant\r\n setAriaActivedescendant(this._root, `${this._selectedOption}-0`);\r\n };\r\n\r\n /**\r\n * show items when items.length > 0 and is not empty\r\n */\r\n _handleShowItems = () => {\r\n // if resultWrap is not active and resultList is not empty\r\n if (\r\n this._resultList.textContent.length > 0 &&\r\n !this._resultWrap.classList.contains(this._isActive)\r\n ) {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add isActive class to resultWrap\r\n this._resultWrap.classList.add(this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n\r\n // select first element\r\n this._selectFirstEl();\r\n\r\n // callback function\r\n this._onOpened({\r\n type: \"showItems\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Adding text from the list when li is clicking\r\n * or adding aria-selected to li elements\r\n *\r\n * @param {Event} event\r\n */\r\n _handleMouse = (event) => {\r\n event.preventDefault();\r\n\r\n const { target, type } = event;\r\n const targetClosest = target.closest(\"li\");\r\n const targetClosestRole = targetClosest?.hasAttribute(\"role\");\r\n const activeClass = this._activeList;\r\n const activeClassElement = document.querySelector(`.${activeClass}`);\r\n\r\n if (!targetClosest || !targetClosestRole) {\r\n return;\r\n }\r\n\r\n // click on li get element\r\n if (type === \"click\") {\r\n // get text from clicked li\r\n this._getTextFromLi(targetClosest);\r\n }\r\n\r\n if (\r\n type === \"mousemove\" &&\r\n !targetClosest.classList.contains(activeClass)\r\n ) {\r\n this._remAria(activeClassElement);\r\n\r\n // add aria to li\r\n this._setAria(targetClosest);\r\n this._index = this._indexLiSelected(targetClosest);\r\n\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Get text from li on enter or click\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _getTextFromLi = (element) => {\r\n if (!element || this._matches.length === 0) {\r\n // set default settings\r\n !this._disable && this._reset();\r\n\r\n return;\r\n }\r\n\r\n // get first element from li and set it to root\r\n getFirstElementFromLiAndAddToInput(element, this._root);\r\n\r\n // onSubmit passing text to function\r\n this._onSubmit({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n results: this._resultList,\r\n });\r\n\r\n // set default settings\r\n if (!this._disable) {\r\n this._remAria(element);\r\n this._reset();\r\n }\r\n\r\n // show clearBtn when select element\r\n this._clearButton && this._cBtn.classList.remove(\"hidden\");\r\n\r\n // remove cache\r\n this._cacheAct(\"remove\");\r\n };\r\n\r\n /**\r\n * Return which li element was selected\r\n * by hovering the mouse over\r\n *\r\n * @param {HTMLElement} target\r\n * @returns {Number}\r\n */\r\n _indexLiSelected = (target) =>\r\n // get index of li element\r\n Array.prototype.indexOf.call(this._itemsLi, target);\r\n\r\n /**\r\n * Navigating the elements li and enter\r\n *\r\n * @param {Event} event\r\n */\r\n _handleKeys = (event) => {\r\n const { keyCode } = event;\r\n\r\n const resultList = this._resultWrap.classList.contains(this._isActive);\r\n\r\n const matchesLength = this._matches.length + 1;\r\n this._selectedLi = document.querySelector(`.${this._activeList}`);\r\n\r\n // switch between keys\r\n switch (keyCode) {\r\n case keyCodes.UP:\r\n case keyCodes.DOWN:\r\n // Wrong cursor position in the input field #62\r\n // Prevents the cursor from moving to the beginning\r\n // of input as the cursor hovers over the results.\r\n event.preventDefault();\r\n\r\n if ((matchesLength <= 1 && this._selectFirst) || !resultList) {\r\n return;\r\n }\r\n\r\n // if keyCode is up\r\n if (keyCode === keyCodes.UP) {\r\n if (this._index < 0) {\r\n this._index = matchesLength - 1;\r\n }\r\n this._index -= 1;\r\n } else {\r\n this._index += 1;\r\n if (this._index >= matchesLength) {\r\n this._index = 0;\r\n }\r\n }\r\n\r\n // remove aria-selected\r\n this._remAria(this._selectedLi);\r\n\r\n if (\r\n matchesLength > 0 &&\r\n this._index >= 0 &&\r\n this._index < matchesLength - 1\r\n ) {\r\n if (this._toInput && resultList) {\r\n getFirstElementFromLiAndAddToInput(\r\n this._itemsLi[this._index],\r\n this._root\r\n );\r\n }\r\n\r\n // callback function\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set aria-selected\r\n this._setAria(this._itemsLi[this._index]);\r\n } else {\r\n // catch action\r\n this._cacheAct();\r\n setAriaActivedescendant(this._root);\r\n\r\n this._onSelected({\r\n index: null,\r\n element: this._root,\r\n object: null,\r\n });\r\n }\r\n\r\n break;\r\n // keycode enter\r\n case keyCodes.ENTER:\r\n this._getTextFromLi(this._selectedLi);\r\n break;\r\n\r\n // keycode escape and keycode tab\r\n case keyCodes.TAB:\r\n case keyCodes.ESC:\r\n event.stopPropagation(); // #120\r\n this._reset();\r\n\r\n break;\r\n default:\r\n break;\r\n }\r\n };\r\n\r\n /**\r\n * Set aria label on item li\r\n *\r\n * @param {HTMLElement} target\r\n */\r\n _setAria = (target) => {\r\n const selectedOption = `${this._selectedOption}-${this._indexLiSelected(\r\n target\r\n )}`;\r\n\r\n // set aria to li\r\n setAttributes(target, {\r\n id: selectedOption,\r\n \"aria-selected\": \"true\",\r\n addClass: this._activeList,\r\n });\r\n\r\n setAriaActivedescendant(this._root, selectedOption);\r\n\r\n // scrollIntoView when press up/down arrows\r\n followActiveElement(\r\n target,\r\n this._outputUl,\r\n this._classGroup,\r\n this._resultList\r\n );\r\n };\r\n\r\n /**\r\n * Remove aria label from item li\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _remAria = (element) => {\r\n if (!element) return;\r\n\r\n // remove aria from li\r\n setAttributes(element, {\r\n id: \"\",\r\n removeClass: this._activeList,\r\n \"aria-selected\": \"false\",\r\n });\r\n };\r\n\r\n /**\r\n * Create clear button and\r\n * removing text from the input field\r\n */\r\n _clearbutton = () => {\r\n // stop when clear button is disabled\r\n if (!this._clearButton) return;\r\n\r\n // add aria to clear button\r\n setAttributes(this._cBtn, {\r\n class: `${this._prefix}-clear hidden`,\r\n type: \"button\",\r\n title: this._clearBtnAriLabel,\r\n \"aria-label\": this._clearBtnAriLabel,\r\n });\r\n\r\n // insert clear button after input - root\r\n this._root.insertAdjacentElement(\"afterend\", this._cBtn);\r\n };\r\n\r\n /**\r\n * Clicking on the clear button\r\n * publick destroy method\r\n */\r\n destroy = () => {\r\n // if clear button is true then add class hidden\r\n this._clearButton && this._cBtn.classList.add(\"hidden\");\r\n // clear value searchId\r\n this._root.value = \"\";\r\n // set focus\r\n this._root.focus();\r\n // remove li from ul\r\n this._resultList.textContent = \"\";\r\n // set default aria\r\n this._reset();\r\n // remove error if exist\r\n this._error();\r\n\r\n // callback function\r\n this._onReset(this._root);\r\n\r\n // remove listener\r\n this._root.removeEventListener(\"keydown\", this._handleKeys);\r\n this._root.removeEventListener(\"click\", this._handleShowItems);\r\n // remove listener on click on document\r\n document.removeEventListener(\"click\", this._handleDocClick);\r\n };\r\n}\r\n"],"names":["isObject","value","constructor","Object","isPromise","Boolean","then","setAttributes","el","object","key","classList","add","remove","setAttribute","getFirstElement","element","firstElementChild","getFirstElementFromLiAndAddToInput","root","textContent","trim","scrollResultsToTop","resultList","resultWrap","scrollTop","offsetTop","offsetHeight","addAriaToAllLiElements","itemsLi","i","length","role","tabindex","showBtnToClearData","clearButton","destroy","addEventListener","setAriaActivedescendant","type","getClassGroupHeight","outputUl","classGroup","allLi","document","querySelectorAll","height","slice","call","map","followActiveElement","target","previusElement","previousSibling","previusElementHeight","getAttribute","offsetBottom","scrollBottom","output","prefix","id","tabIndex","addClass","insertAdjacentElement","parentNode","insertBefore","nextSibling","createElement","keyCodes","ESC","ENTER","UP","DOWN","TAB","Autocomplete","delay","howManyCharacters","selectFirst","insertToInput","showAllValues","cache","disableCloseOnSelect","classPreventClosing","classPrefix","ariaLabelClear","onSearch","onResults","onSubmit","onOpened","onReset","onRender","onClose","noResults","onSelectedItem","_initial","_clearbutton","_root","_resultList","_outputUl","_resultWrap","_prefix","_handleInput","_showAll","_onRender","results","_cacheAct","_cache","_cacheData","removeAttribute","regex","replace","_regex","_delay","clearTimeout","_timeout","setTimeout","_searchItem","_reset","_id","removeClass","_isActive","_matches","_toInput","innerHTML","_index","_selectFirst","_onClose","_value","_onLoading","_cBtn","_clearButton","_characters","_onSearch","currentValue","result","rootValueLength","resultLength","Array","isArray","JSON","parse","stringify","_error","_noResults","template","_results","_events","catch","_isLoading","_err","_handleKeys","_handleShowItems","eventType","_handleMouse","_handleDocClick","_onResults","matches","_classGroup","checkIfClassGroupExist","_itemsLi","_onOpened","_selectFirstEl","disableClose","closest","_disable","_prevClosing","_remAria","querySelector","_activeList","classSelectFirst","nextElementSibling","_onSelected","index","_selectedOption","contains","event","preventDefault","targetClosest","targetClosestRole","hasAttribute","activeClass","activeClassElement","_getTextFromLi","_setAria","_indexLiSelected","_onSubmit","prototype","indexOf","keyCode","matchesLength","_selectedLi","stopPropagation","selectedOption","class","title","_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L,GAA0B,KAAKzE,OAA/B;EACA,SAAKiD,IAAL,GAAe,KAAKjD,OAApB;EACA,SAAKW,MAAL,GAAc,qBAAd;EACA,SAAKG,QAAL,GAAgB,IAAhB;EAEA,SAAKf,WAAL,GAAmBhC,aAAa,CAAC,KAAD,CAAhC;EACA,SAAK8B,WAAL,GAAmB9B,aAAa,CAAC,IAAD,CAAhC;EACA,SAAK8D,KAAL,GAAa9D,aAAa,CAAC,QAAD,CAA1B;EAEA,SAAK2B,QAAL;EACD;EA/E+B;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"autocomplete.umd.js","sources":["../../sources/js/utils/function.js","../../sources/js/utils/keyCodes.js","../../sources/js/script.js"],"sourcesContent":["/**\r\n * Check is a Object\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isObject = (value) =>\r\n value && typeof value === \"object\" && value.constructor === Object;\r\n\r\n/**\r\n * Check if is a Promise\r\n * https://stackoverflow.com/a/53955664/10424385\r\n *\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isPromise = (value) => Boolean(value && typeof value.then === \"function\");\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n if (key === \"addClass\") {\r\n classList(el, \"add\", object[key]);\r\n } else if (key === \"removeClass\") {\r\n classList(el, \"remove\", object[key]);\r\n } else {\r\n el.setAttribute(key, object[key]);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Get first element from child\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {HTMLELement}\r\n */\r\nconst getFirstElement = (element) =>\r\n (element.firstElementChild || element).textContent.trim();\r\n\r\n/**\r\n * Scroll to top result-list\r\n * @param {HTMLElement} resultList\r\n * @param {HTMLElement} resultWrap\r\n */\r\nconst scrollResultsToTop = (resultList, resultWrap) => {\r\n // if there is an overflow of ul element, after\r\n // opening we always move ul to the top of the results\r\n resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight;\r\n};\r\n\r\n/**\r\n * Adding role, tabindex, aria and call handleMouse\r\n *\r\n * @param {HTMLElement} itemsLi\r\n */\r\nconst addAriaToAllLiElements = (itemsLi) => {\r\n // add role to all li elements\r\n for (let i = 0; i < itemsLi.length; i++) {\r\n setAttributes(itemsLi[i], {\r\n role: \"option\",\r\n tabindex: \"-1\",\r\n \"aria-selected\": \"false\",\r\n \"aria-setsize\": itemsLi.length,\r\n \"aria-posinset\": i,\r\n });\r\n }\r\n};\r\n\r\n/**\r\n * Show btn to clear data\r\n *\r\n * @param {HTMLElement} clearButton - button to clear data\r\n * @param {Function} destroy - destroy function\r\n */\r\nconst showBtnToClearData = (clearButton = false, destroy) => {\r\n if (!clearButton) return;\r\n\r\n classList(clearButton, \"remove\", \"hidden\");\r\n // add event to clear button\r\n onEvent(clearButton, \"click\", destroy);\r\n};\r\n\r\n/**\r\n * ClassList add/remove/contains\r\n *\r\n * @param {HTMLElement} element - html element\r\n * @param {String} action - add/remove/contains\r\n * @param {String} className - class name\r\n */\r\nconst classList = (element, action, className) =>\r\n element.classList[action](className);\r\n\r\n/**\r\n * Set aria-activedescendant\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {String} type\r\n */\r\nconst setAriaActivedescendant = (root, type) => {\r\n setAttributes(root, {\r\n \"aria-activedescendant\": type || \"\",\r\n });\r\n};\r\n\r\n/**\r\n * Get height of ul without group class\r\n *\r\n * @param {String} outputUl\r\n * @param {String} classGroup\r\n * @returns {Number}\r\n */\r\nconst getClassGroupHeight = (outputUl, classGroup) => {\r\n // get height of ul without group class\r\n const allLiElements = document.querySelectorAll(\r\n `#${outputUl} > li:not(.${classGroup})`\r\n );\r\n let height = 0;\r\n [].slice.call(allLiElements).map((el) => (height += el.offsetHeight));\r\n\r\n // return height\r\n return height;\r\n};\r\n\r\n/**\r\n * Scroll into view when press up/down arrows\r\n *\r\n * @param {HTMLElement} target\r\n * @param {HTMLElement} outputUl\r\n * @param {String} classGroup\r\n * @param {HTMLElement} resultList\r\n */\r\nconst followActiveElement = (target, outputUl, classGroup, resultList) => {\r\n const previusElement = resultList.previousSibling;\r\n\r\n const previusElementHeight = previusElement ? previusElement.offsetHeight : 0;\r\n\r\n if (target.getAttribute(\"aria-posinset\") == \"0\") {\r\n resultList.scrollTop =\r\n target.offsetTop - getClassGroupHeight(outputUl, classGroup);\r\n }\r\n\r\n if (target.offsetTop - previusElementHeight < resultList.scrollTop) {\r\n resultList.scrollTop = target.offsetTop - previusElementHeight;\r\n } else {\r\n const offsetBottom =\r\n target.offsetTop + target.offsetHeight - previusElementHeight;\r\n const scrollBottom = resultList.scrollTop + resultList.offsetHeight;\r\n if (offsetBottom > scrollBottom) {\r\n resultList.scrollTop = offsetBottom - resultList.offsetHeight;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Create output-list and put after search input\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {HTMLElement} resultList - output-list ul\r\n * @param {String} outputUl - id name of output-list\r\n * @param {HTMLElement} resultWrap - wrapper ul element\r\n * @param {String} prefix - add prefix to all class auto\r\n */\r\nconst output = (root, resultList, outputUl, resultWrap, prefix) => {\r\n // set attribute to results-list\r\n setAttributes(resultList, {\r\n id: outputUl,\r\n tabIndex: \"0\",\r\n role: \"listbox\",\r\n });\r\n\r\n // add class to wrap element\r\n setAttributes(resultWrap, {\r\n addClass: `${prefix}-results-wrapper`,\r\n });\r\n\r\n // insert the results into the wrap element\r\n resultWrap.insertAdjacentElement(\"beforeend\", resultList);\r\n\r\n // insert the wrap element after the search input\r\n root.parentNode.insertBefore(resultWrap, root.nextSibling);\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLDivElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\n/**\r\n * Get element\r\n *\r\n * @param {String} element\r\n * @returns {HTMLElement}\r\n */\r\nconst select = (element) => document.querySelector(element);\r\n\r\n/**\r\n * Event listeners\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} action\r\n * @param {Function} callback\r\n */\r\nconst onEvent = (element, action, callback) => {\r\n element.addEventListener(action, callback);\r\n};\r\n\r\n/**\r\n * Remove event listeners\r\n */\r\nconst offEvent = (element, action, callback) => {\r\n element.removeEventListener(action, callback);\r\n};\r\n\r\nexport {\r\n addAriaToAllLiElements,\r\n classList,\r\n createElement,\r\n followActiveElement,\r\n getFirstElement,\r\n isObject,\r\n isPromise,\r\n offEvent,\r\n onEvent,\r\n output,\r\n scrollResultsToTop,\r\n select,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n};\r\n","/**\r\n * Key codes\r\n */\r\nconst keyCodes = {\r\n ESC: 27,\r\n ENTER: 13,\r\n UP: 38,\r\n DOWN: 40,\r\n TAB: 9,\r\n};\r\n\r\nexport default keyCodes;\r\n","import {\r\n addAriaToAllLiElements,\r\n classList,\r\n createElement,\r\n followActiveElement,\r\n getFirstElement,\r\n isObject,\r\n isPromise,\r\n offEvent,\r\n onEvent,\r\n output,\r\n scrollResultsToTop,\r\n select,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n} from \"./utils/function\";\r\n\r\nimport keyCodes from \"./utils/keyCodes\";\r\n\r\n/**\r\n * @class Autocomplete\r\n */\r\nexport default class Autocomplete {\r\n /**\r\n * Constructor\r\n *\r\n * @param {String} element\r\n * @param {Object} object\r\n */\r\n constructor(\r\n element,\r\n {\r\n delay = 500,\r\n clearButton = true,\r\n howManyCharacters = 1,\r\n selectFirst = false,\r\n insertToInput = false,\r\n showAllValues = false,\r\n cache = false,\r\n disableCloseOnSelect = false,\r\n classGroup,\r\n classPreventClosing,\r\n classPrefix,\r\n ariaLabelClear,\r\n onSearch,\r\n onResults = () => {},\r\n onSubmit = () => {},\r\n onOpened = () => {},\r\n onReset = () => {},\r\n onRender = () => {},\r\n onClose = () => {},\r\n noResults = () => {},\r\n onSelectedItem = () => {},\r\n }\r\n ) {\r\n this._id = element;\r\n this._root = document.getElementById(element);\r\n this._onSearch = isPromise(onSearch)\r\n ? onSearch\r\n : ({ currentValue, element }) =>\r\n Promise.resolve(onSearch({ currentValue, element }));\r\n this._onResults = onResults;\r\n this._onRender = onRender;\r\n this._onSubmit = onSubmit;\r\n this._onSelected = onSelectedItem;\r\n this._onOpened = onOpened;\r\n this._onReset = onReset;\r\n this._noResults = noResults;\r\n this._onClose = onClose;\r\n\r\n this._delay = delay;\r\n this._characters = howManyCharacters;\r\n this._clearButton = clearButton;\r\n this._selectFirst = selectFirst;\r\n this._toInput = insertToInput;\r\n this._showAll = showAllValues;\r\n this._classGroup = classGroup;\r\n this._prevClosing = classPreventClosing;\r\n this._clearBtnAriLabel = ariaLabelClear\r\n ? ariaLabelClear\r\n : \"clear the search query\";\r\n this._prefix = classPrefix ? `${classPrefix}-auto` : \"auto\";\r\n this._disable = disableCloseOnSelect;\r\n\r\n // default config\r\n this._cache = cache;\r\n this._outputUl = `${this._prefix}-${this._id}-results`;\r\n this._cacheData = `data-cache-auto-${this._id}`;\r\n this._isLoading = `${this._prefix}-is-loading`;\r\n this._isActive = `${this._prefix}-is-active`;\r\n this._activeList = `${this._prefix}-selected`;\r\n this._selectedOption = `${this._prefix}-selected-option`;\r\n this._err = `${this._prefix}-error`;\r\n this._regex = /[|\\\\{}()[\\]^$+*?.]/g;\r\n this._timeout = null;\r\n\r\n this._resultWrap = createElement(\"div\");\r\n this._resultList = createElement(\"ul\");\r\n this._clearBtn = createElement(\"button\");\r\n\r\n this._initial();\r\n }\r\n\r\n /**\r\n * Initial function\r\n */\r\n _initial = () => {\r\n this._clearbutton();\r\n\r\n output(\r\n this._root,\r\n this._resultList,\r\n this._outputUl,\r\n this._resultWrap,\r\n this._prefix\r\n );\r\n\r\n // default aria\r\n onEvent(this._root, \"input\", this._handleInput);\r\n\r\n // show all values on click root input\r\n this._showAll && onEvent(this._root, \"click\", this._handleInput);\r\n\r\n // calback functions\r\n this._onRender({\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n };\r\n\r\n /**\r\n * Actions on input\r\n *\r\n * @param {String} type - set attribute depending on type\r\n * @param {String} target\r\n */\r\n _cacheAct = (type, target) => {\r\n if (!this._cache) return;\r\n\r\n if (type === \"update\") {\r\n this._root.setAttribute(this._cacheData, target.value);\r\n } else if (type === \"remove\") {\r\n this._root.removeAttribute(this._cacheData);\r\n } else {\r\n this._root.value = this._root.getAttribute(this._cacheData);\r\n }\r\n };\r\n\r\n /**\r\n * Handle input\r\n *\r\n * @param {Event} object\r\n */\r\n _handleInput = ({ target, type }) => {\r\n if (\r\n this._root.getAttribute(\"aria-expanded\") === \"true\" &&\r\n type === \"click\"\r\n ) {\r\n return;\r\n }\r\n\r\n // replace all special characters\r\n const regex = target.value.replace(this._regex, \"\\\\$&\");\r\n\r\n // update data attribute cache\r\n this._cacheAct(\"update\", target);\r\n\r\n const delay = this._showAll ? 0 : this._delay;\r\n // clear timeout\r\n clearTimeout(this._timeout);\r\n this._timeout = setTimeout(() => {\r\n this._searchItem(regex.trim());\r\n }, delay);\r\n };\r\n\r\n /**\r\n * Default aria\r\n */\r\n _reset = () => {\r\n // set attributes to root - input\r\n setAttributes(this._root, {\r\n \"aria-owns\": `${this._id}-list`,\r\n \"aria-expanded\": \"false\",\r\n \"aria-autocomplete\": \"list\",\r\n \"aria-activedescendant\": \"\",\r\n role: \"combobox\",\r\n removeClass: \"auto-expanded\",\r\n });\r\n\r\n // remove class isActive\r\n classList(this._resultWrap, \"remove\", this._isActive);\r\n\r\n // set index\r\n this._index = this._selectFirst ? 0 : -1;\r\n\r\n // callback function\r\n this._onClose();\r\n };\r\n\r\n /**\r\n * The async function gets the text from the search\r\n * and returns the matching array\r\n *\r\n * @param {String} value\r\n */\r\n _searchItem = (value) => {\r\n this._value = value;\r\n\r\n // if searching show loading icon\r\n this._onLoading(true);\r\n\r\n // hide button clear\r\n showBtnToClearData(this._clearBtn, this.destroy);\r\n\r\n // if there is no value and clearButton is true\r\n if (value.length == 0 && this._clearButton) {\r\n classList(this._clearBtn, \"add\", \"hidden\");\r\n }\r\n\r\n // if declare characters more then value.len and showAll is false\r\n // remove class isActive\r\n if (this._characters > value.length && !this._showAll) {\r\n this._onLoading();\r\n return;\r\n }\r\n\r\n // callblack function onSearch\r\n this._onSearch({ currentValue: value, element: this._root })\r\n .then((result) => {\r\n const rootValueLength = this._root.value.length;\r\n const resultLength = result.length;\r\n // set no result\r\n this._matches = Array.isArray(result)\r\n ? result\r\n : JSON.parse(JSON.stringify(result));\r\n\r\n this._onLoading();\r\n this._error();\r\n\r\n // if use destroy() method\r\n if (resultLength == 0 && rootValueLength == 0) {\r\n classList(this._clearBtn, \"add\", \"hidden\");\r\n }\r\n\r\n if (resultLength == 0 && rootValueLength) {\r\n classList(this._root, \"remove\", \"auto-expanded\");\r\n this._reset();\r\n this._noResults({\r\n element: this._root,\r\n currentValue: value,\r\n template: this._results,\r\n });\r\n this._events();\r\n } else if (resultLength > 0 || isObject(result)) {\r\n this._index = this._selectFirst ? 0 : -1;\r\n this._results();\r\n this._events();\r\n }\r\n })\r\n .catch(() => {\r\n this._onLoading();\r\n this._reset();\r\n });\r\n };\r\n\r\n /**\r\n * Set or remove loading class\r\n *\r\n * @param {Boolean} type\r\n */\r\n _onLoading = (type) =>\r\n this._root.parentNode.classList[type ? \"add\" : \"remove\"](this._isLoading);\r\n\r\n /**\r\n * Set error class to the root element\r\n */\r\n _error = () => classList(this._root, \"remove\", this._err);\r\n\r\n /**\r\n * Events\r\n */\r\n _events = () => {\r\n // handle click on keydown [up, down, enter, tab, esc]\r\n onEvent(this._root, \"keydown\", this._handleKeys);\r\n\r\n onEvent(this._root, \"click\", this._handleShowItems);\r\n\r\n // temporarily disabled mouseleave\r\n [\"mousemove\", \"click\"].map((eventType) => {\r\n onEvent(this._resultList, eventType, this._handleMouse);\r\n });\r\n\r\n // close expanded items\r\n onEvent(document, \"click\", this._handleDocClick);\r\n };\r\n\r\n /**\r\n * Results\r\n *\r\n * @param {HTMLElement|String} template - html or string returned from the function,\r\n * look at the example - https://github.com/tomik23/autocomplete/blob/master/docs/js/examples/no-results.js#L30\r\n */\r\n _results = (template) => {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // clear result list\r\n this._resultList.textContent = \"\";\r\n\r\n // add all found records to otput ul\r\n const dataResults =\r\n this._matches.length === 0\r\n ? this._onResults({\r\n currentValue: this._value,\r\n matches: 0,\r\n template,\r\n })\r\n : this._onResults({\r\n currentValue: this._value,\r\n matches: this._matches,\r\n classGroup: this._classGroup,\r\n });\r\n\r\n // add data to ul\r\n this._resultList.insertAdjacentHTML(\"afterbegin\", dataResults);\r\n\r\n // add class isActive\r\n classList(this._resultWrap, \"add\", this._isActive);\r\n\r\n const checkIfClassGroupExist = this._classGroup\r\n ? `:not(.${this._classGroup})`\r\n : \"\";\r\n\r\n this._itemsLi = document.querySelectorAll(\r\n `#${this._outputUl} > li${checkIfClassGroupExist}`\r\n );\r\n\r\n // adding role, tabindex and aria\r\n addAriaToAllLiElements(this._itemsLi);\r\n\r\n // action on open results\r\n this._onOpened({\r\n type: \"results\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n\r\n // select first element\r\n this._selectFirstElement();\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n };\r\n\r\n /**\r\n * Hangle click on document\r\n *\r\n * @param {Event} object\r\n */\r\n _handleDocClick = ({ target }) => {\r\n let disableClose = null;\r\n\r\n // if 'target' is a ul and 'disableCloseOnSelect'\r\n // is a 'true' set 'disableClose' on true\r\n if (\r\n (target.closest(\"ul\") && this._disable) ||\r\n // when class classDisableClose\r\n // then do not not close results\r\n target.closest(`.${this._prevClosing}`)\r\n ) {\r\n disableClose = true;\r\n }\r\n\r\n if (target.id !== this._id && !disableClose) {\r\n this._reset();\r\n return;\r\n }\r\n };\r\n\r\n /**\r\n * Select first element\r\n */\r\n _selectFirstElement = () => {\r\n this._removeAria(select(`.${this._activeList}`));\r\n\r\n if (!this._selectFirst) {\r\n return;\r\n }\r\n\r\n const { firstElementChild } = this._resultList;\r\n\r\n const classSelectFirst =\r\n this._classGroup && this._matches.length > 0 && this._selectFirst\r\n ? firstElementChild.nextElementSibling\r\n : firstElementChild;\r\n\r\n // calback function onSelect when first element is true\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set attribute to first element\r\n setAttributes(classSelectFirst, {\r\n id: `${this._selectedOption}-0`,\r\n addClass: this._activeList,\r\n \"aria-selected\": \"true\",\r\n });\r\n\r\n // set aria active descendant\r\n setAriaActivedescendant(this._root, `${this._selectedOption}-0`);\r\n };\r\n\r\n /**\r\n * show items when items.length > 0 and is not empty\r\n */\r\n _handleShowItems = () => {\r\n // if resultWrap is not active and resultList is not empty\r\n if (\r\n this._resultList.textContent.length > 0 &&\r\n !classList(this._resultWrap, \"contains\", this._isActive)\r\n ) {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add isActive class to resultWrap\r\n classList(this._resultWrap, \"add\", this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n\r\n // select first element\r\n this._selectFirstElement();\r\n\r\n // callback function\r\n this._onOpened({\r\n type: \"showItems\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Adding text from the list when li is clicking\r\n * or adding aria-selected to li elements\r\n *\r\n * @param {Event} event\r\n */\r\n _handleMouse = (event) => {\r\n event.preventDefault();\r\n\r\n const { target, type } = event;\r\n const targetClosest = target.closest(\"li\");\r\n const targetClosestRole = targetClosest?.hasAttribute(\"role\");\r\n const activeClass = this._activeList;\r\n const activeClassElement = select(`.${activeClass}`);\r\n\r\n if (!targetClosest || !targetClosestRole) {\r\n return;\r\n }\r\n\r\n // click on li get element\r\n if (type === \"click\") {\r\n // get text from clicked li\r\n this._getTextFromLi(targetClosest);\r\n }\r\n\r\n if (\r\n type === \"mousemove\" &&\r\n !classList(targetClosest, \"contains\", activeClass)\r\n ) {\r\n this._removeAria(activeClassElement);\r\n\r\n // add aria to li\r\n this._setAria(targetClosest);\r\n this._index = this._indexLiSelected(targetClosest);\r\n\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Get text from li on enter or click\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _getTextFromLi = (element) => {\r\n if (!element || this._matches.length === 0) {\r\n // set default settings\r\n !this._disable && this._reset();\r\n\r\n return;\r\n }\r\n\r\n // get first element from li and set it to root\r\n this._root.value = getFirstElement(element);\r\n\r\n // onSubmit passing text to function\r\n this._onSubmit({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n results: this._resultList,\r\n });\r\n\r\n // set default settings\r\n if (!this._disable) {\r\n this._removeAria(element);\r\n this._reset();\r\n }\r\n\r\n // show clearBtn when select element\r\n this._clearButton && classList(this._clearBtn, \"remove\", \"hidden\");\r\n\r\n // remove cache\r\n this._cacheAct(\"remove\");\r\n };\r\n\r\n /**\r\n * Return which li element was selected\r\n * by hovering the mouse over\r\n *\r\n * @param {HTMLElement} target\r\n * @returns {Number}\r\n */\r\n _indexLiSelected = (target) =>\r\n // get index of li element\r\n Array.prototype.indexOf.call(this._itemsLi, target);\r\n\r\n /**\r\n * Navigating the elements li and enter\r\n *\r\n * @param {Event} event\r\n */\r\n _handleKeys = (event) => {\r\n const { keyCode } = event;\r\n\r\n const resultList = classList(this._resultWrap, \"contains\", this._isActive);\r\n\r\n const matchesLength = this._matches.length + 1;\r\n this._selectedLi = select(`.${this._activeList}`);\r\n\r\n // switch between keys\r\n switch (keyCode) {\r\n case keyCodes.UP:\r\n case keyCodes.DOWN:\r\n // Wrong cursor position in the input field #62\r\n // Prevents the cursor from moving to the beginning\r\n // of input as the cursor hovers over the results.\r\n event.preventDefault();\r\n\r\n if ((matchesLength <= 1 && this._selectFirst) || !resultList) {\r\n return;\r\n }\r\n\r\n // if keyCode is up\r\n if (keyCode === keyCodes.UP) {\r\n if (this._index < 0) {\r\n this._index = matchesLength - 1;\r\n }\r\n this._index -= 1;\r\n } else {\r\n this._index += 1;\r\n if (this._index >= matchesLength) {\r\n this._index = 0;\r\n }\r\n }\r\n\r\n // remove aria-selected\r\n this._removeAria(this._selectedLi);\r\n\r\n if (this._index >= 0 && this._index < matchesLength - 1) {\r\n if (this._toInput && resultList) {\r\n this._root.value = getFirstElement(this._itemsLi[this._index]);\r\n }\r\n\r\n // callback function\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set aria-selected\r\n this._setAria(this._itemsLi[this._index]);\r\n } else {\r\n // catch action\r\n this._cacheAct();\r\n setAriaActivedescendant(this._root);\r\n\r\n this._onSelected({\r\n index: null,\r\n element: this._root,\r\n object: null,\r\n });\r\n }\r\n\r\n break;\r\n // keycode enter\r\n case keyCodes.ENTER:\r\n this._getTextFromLi(this._selectedLi);\r\n break;\r\n\r\n // keycode escape and keycode tab\r\n case keyCodes.TAB:\r\n case keyCodes.ESC:\r\n event.stopPropagation(); // #120\r\n this._reset();\r\n\r\n break;\r\n default:\r\n break;\r\n }\r\n };\r\n\r\n /**\r\n * Set aria label on item li\r\n *\r\n * @param {HTMLElement} target\r\n */\r\n _setAria = (target) => {\r\n const selectedOption = `${this._selectedOption}-${this._indexLiSelected(\r\n target\r\n )}`;\r\n\r\n // set aria to li\r\n setAttributes(target, {\r\n id: selectedOption,\r\n \"aria-selected\": \"true\",\r\n addClass: this._activeList,\r\n });\r\n\r\n setAriaActivedescendant(this._root, selectedOption);\r\n\r\n // scrollIntoView when press up/down arrows\r\n followActiveElement(\r\n target,\r\n this._outputUl,\r\n this._classGroup,\r\n this._resultList\r\n );\r\n };\r\n\r\n /**\r\n * Remove aria label from item li\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _removeAria = (element) => {\r\n if (!element) return;\r\n\r\n // remove aria from li\r\n setAttributes(element, {\r\n id: \"\",\r\n removeClass: this._activeList,\r\n \"aria-selected\": \"false\",\r\n });\r\n };\r\n\r\n /**\r\n * Create clear button and\r\n * removing text from the input field\r\n */\r\n _clearbutton = () => {\r\n // stop when clear button is disabled\r\n if (!this._clearButton) return;\r\n\r\n // add aria to clear button\r\n setAttributes(this._clearBtn, {\r\n class: `${this._prefix}-clear hidden`,\r\n type: \"button\",\r\n title: this._clearBtnAriLabel,\r\n \"aria-label\": this._clearBtnAriLabel,\r\n });\r\n\r\n // insert clear button after input - root\r\n this._root.insertAdjacentElement(\"afterend\", this._clearBtn);\r\n };\r\n\r\n /**\r\n * Clicking on the clear button\r\n * publick destroy method\r\n */\r\n destroy = () => {\r\n // if clear button is true then add class hidden\r\n this._clearButton && classList(this._clearBtn, \"add\", \"hidden\");\r\n // clear value searchId\r\n this._root.value = \"\";\r\n // set focus\r\n this._root.focus();\r\n // remove li from ul\r\n this._resultList.textContent = \"\";\r\n // set default aria\r\n this._reset();\r\n // remove error if exist\r\n this._error();\r\n\r\n // callback function\r\n this._onReset(this._root);\r\n\r\n // remove listener\r\n offEvent(this._root, \"keydown\", this._handleKeys);\r\n offEvent(this._root, \"click\", this._handleShowItems);\r\n // remove listener on click on document\r\n offEvent(document, \"click\", this._handleDocClick);\r\n };\r\n}\r\n"],"names":["isObject","value","constructor","Object","isPromise","Boolean","then","setAttributes","el","object","key","classList","setAttribute","getFirstElement","element","firstElementChild","textContent","trim","scrollResultsToTop","resultList","resultWrap","scrollTop","offsetTop","offsetHeight","addAriaToAllLiElements","itemsLi","i","length","role","tabindex","showBtnToClearData","clearButton","destroy","onEvent","action","className","setAriaActivedescendant","root","type","getClassGroupHeight","outputUl","classGroup","allLiElements","document","querySelectorAll","height","slice","call","map","followActiveElement","target","previusElement","previousSibling","previusElementHeight","getAttribute","offsetBottom","scrollBottom","output","prefix","id","tabIndex","addClass","insertAdjacentElement","parentNode","insertBefore","nextSibling","createElement","select","querySelector","callback","addEventListener","offEvent","removeEventListener","keyCodes","ESC","ENTER","UP","DOWN","TAB","Autocomplete","delay","howManyCharacters","selectFirst","insertToInput","showAllValues","cache","disableCloseOnSelect","classPreventClosing","classPrefix","ariaLabelClear","onSearch","onResults","onSubmit","onOpened","onReset","onRender","onClose","noResults","onSelectedItem","_initial","_clearbutton","_root","_resultList","_outputUl","_resultWrap","_prefix","_handleInput","_showAll","_onRender","results","_cacheAct","_cache","_cacheData","removeAttribute","regex","replace","_regex","_delay","clearTimeout","_timeout","setTimeout","_searchItem","_reset","_id","removeClass","_isActive","_index","_selectFirst","_onClose","_value","_onLoading","_clearBtn","_clearButton","_characters","_onSearch","currentValue","result","rootValueLength","resultLength","_matches","Array","isArray","JSON","parse","stringify","_error","_noResults","template","_results","_events","catch","_isLoading","_err","_handleKeys","_handleShowItems","eventType","_handleMouse","_handleDocClick","dataResults","_onResults","matches","_classGroup","insertAdjacentHTML","checkIfClassGroupExist","_itemsLi","_onOpened","_selectFirstElement","disableClose","closest","_disable","_prevClosing","_removeAria","_activeList","classSelectFirst","nextElementSibling","_onSelected","index","_selectedOption","event","preventDefault","targetClosest","targetClosestRole","hasAttribute","activeClass","activeClassElement","_getTextFromLi","_setAria","_indexLiSelected","_onSubmit","prototype","indexOf","keyCode","matchesLength","_selectedLi","_toInput","stopPropagation","selectedOption","class","title","_clearBtnAriLabel","focus","_onReset","getElementById","Promise","resolve"],"mappings":";;;;;;EAKA,MAAMA,QAAQ,GAAIC,KAAD,IACfA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAA1B,IAAsCA,KAAK,CAACC,WAAN,KAAsBC,MAD9D;EAUA,MAAMC,SAAS,GAAIH,KAAD,IAAWI,OAAO,CAACJ,KAAK,IAAI,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AKE,OAAzB,SAAoC,KAAKkB,GAAzC;EACA,SAAKX,UAAL,wBAAqC,KAAKW,GAA1C;EACA,SAAK4B,UAAL,GAAqB,KAAK9C,OAA1B;EACA,SAAKoB,SAAL,GAAoB,KAAKpB,OAAzB;EACA,SAAKmE,WAAL,GAAsB,KAAKnE,OAA3B;EACA,SAAKwE,eAAL,GAA0B,KAAKxE,OAA/B;EACA,SAAK+C,IAAL,GAAe,KAAK/C,OAApB;EACA,SAAKW,MAAL,GAAc,qBAAd;EACA,SAAKG,QAAL,GAAgB,IAAhB;EAEA,SAAKf,WAAL,GAAmBtC,aAAa,CAAC,KAAD,CAAhC;EACA,SAAKoC,WAAL,GAAmBpC,aAAa,CAAC,IAAD,CAAhC;EACA,SAAKiE,SAAL,GAAiBjE,aAAa,CAAC,QAAD,CAA9B;EAEA,SAAKiC,QAAL;EACD;EA/E+B;;;;;;;;"} \ No newline at end of file diff --git a/dist/js/autocomplete.umd.min.js b/dist/js/autocomplete.umd.min.js index 2325fbe..42ac9dc 100644 --- a/dist/js/autocomplete.umd.min.js +++ b/dist/js/autocomplete.umd.min.js @@ -1 +1 @@ -!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t="undefined"!=typeof globalThis?globalThis:t||self).Autocomplete=s()}(this,(function(){"use strict";const t=(t,s)=>{for(let i in s)"addClass"===i?t.classList.add(s[i]):"removeClass"===i?t.classList.remove(s[i]):t.setAttribute(i,s[i])},s=(t,s)=>s.value=(t=>t.firstElementChild||t)(t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=(t,s)=>{t.setAttribute("aria-activedescendant",s||"")},e=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll("#"+t+" > li:not(."+s+")");let h=0;return[].slice.call(i).map(t=>h+=t.offsetHeight),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},a=t=>document.createElement(t),n=27,l=13,o=38,r=40,c=9;return class{constructor(d,u){let{delay:m=500,clearButton:p=!0,howManyCharacters:f=1,selectFirst:b=!1,insertToInput:x=!1,showAllValues:y=!1,cache:v=!1,disableCloseOnSelect:C=!1,classGroup:k,classPreventClosing:g,classPrefix:j,ariaLabelClear:w,onSearch:V,onResults:S=(()=>{}),onSubmit:O=(()=>{}),onOpened:T=(()=>{}),onReset:I=(()=>{}),onRender:R=(()=>{}),onClose:A=(()=>{}),noResults:P=(()=>{}),onSelectedItem:B=(()=>{})}=u;var G;this.t=()=>{var s,i,h,e,a;this.s(),s=this.i,i=this.h,h=this.l,e=this.o,a=this.u,t(i,{id:h,tabIndex:"0",role:"listbox"}),t(e,{addClass:a+"-results-wrapper"}),e.insertAdjacentElement("beforeend",i),s.parentNode.insertBefore(e,s.nextSibling),this.i.addEventListener("input",this.m),this.p&&this.i.addEventListener("click",this.m),this.v({element:this.i,results:this.h})},this.C=(t,s)=>{this.k&&("update"===t?this.i.setAttribute(this.g,s.value):"remove"===t?this.i.removeAttribute(this.g):this.i.value=this.i.getAttribute(this.g))},this.m=t=>{let{target:s,type:i}=t;if("true"===this.i.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.j,"\\$&");this.C("update",s);const e=this.p?0:this.V;clearTimeout(this.S),this.S=setTimeout(()=>{this.O(h.trim())},e)},this.T=()=>{var s;t(this.i,{"aria-owns":this.I+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),this.o.classList.remove(this.R),(0==(null==(s=this.A)?void 0:s.length)&&!this.P||this.p)&&(this.h.innerHTML=""),this.B=this.G?0:-1,this.J()},this.O=t=>{this.N=t,this.$(!0),function(t,s){void 0===t&&(t=!1),t&&(t.classList.remove("hidden"),t.addEventListener("click",s))}(this.q,this.destroy),0==t.length&&this.F&&this.q.classList.add("hidden"),this.L>t.length&&!this.p?this.$():this.M({currentValue:t,element:this.i}).then(s=>{const i=this.i.value.length,h=s.length;this.A=Array.isArray(s)?[...s]:JSON.parse(JSON.stringify(s)),this.$(),this.D(),0==h&&0==i&&this.q.classList.add("hidden"),0==h&&i?(this.i.classList.remove("auto-expanded"),this.T(),this.H({element:this.i,currentValue:t,template:this.K}),this.U()):(h>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.B=this.G?0:-1,this.K(),this.U())}).catch(()=>{this.$(),this.T()})},this.$=t=>this.i.parentNode.classList[t?"add":"remove"](this.W),this.D=()=>this.i.classList.remove(this.X),this.U=()=>{this.i.addEventListener("keydown",this.Y),this.i.addEventListener("click",this.Z),["mousemove","click"].map(t=>{this.h.addEventListener(t,this._)}),document.addEventListener("click",this.tt)},this.K=s=>{t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.h.innerHTML=0===this.A.length?this.st({currentValue:this.N,matches:0,template:s}):this.st({currentValue:this.N,matches:this.A,classGroup:this.it}),this.o.classList.add(this.R);const h=this.it?":not(."+this.it+")":"";this.ht=document.querySelectorAll("#"+this.l+" > li"+h),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.nt||s.closest("."+this.lt))&&(i=!0),s.id===this.I||i||this.T()},this.at=()=>{if(this.ot(document.querySelector("."+this.rt)),!this.G)return;const{firstElementChild:s}=this.h,i=this.it&&this.A.length>0&&this.G?s.nextElementSibling:s;this.ct({index:this.B,element:this.i,object:this.A[this.B]}),t(i,{id:this.dt+"-0",addClass:this.rt,"aria-selected":"true"}),h(this.i,this.dt+"-0")},this.Z=()=>{this.h.textContent.length>0&&!this.o.classList.contains(this.R)&&(t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.o.classList.add(this.R),i(this.h,this.o),this.at(),this.et({type:"showItems",element:this.i,results:this.h}))},this._=t=>{t.preventDefault();const{target:s,type:i}=t,h=s.closest("li"),e=null==h?void 0:h.hasAttribute("role"),a=this.rt,n=document.querySelector("."+a);h&&e&&("click"===i&&this.ut(h),"mousemove"!==i||h.classList.contains(a)||(this.ot(n),this.pt(h),this.B=this.ft(h),this.ct({index:this.B,element:this.i,object:this.A[this.B]})))},this.ut=t=>{t&&0!==this.A.length?(s(t,this.i),this.bt({index:this.B,element:this.i,object:this.A[this.B],results:this.h}),this.nt||(this.ot(t),this.T()),this.F&&this.q.classList.remove("hidden"),this.C("remove")):!this.nt&&this.T()},this.ft=t=>Array.prototype.indexOf.call(this.ht,t),this.Y=t=>{const{keyCode:i}=t,e=this.o.classList.contains(this.R),a=this.A.length+1;switch(this.xt=document.querySelector("."+this.rt),i){case o:case r:if(t.preventDefault(),a<=1&&this.G||!e)return;i===o?(this.B<0&&(this.B=a-1),this.B-=1):(this.B+=1,this.B>=a&&(this.B=0)),this.ot(this.xt),a>0&&this.B>=0&&this.B{const i=this.dt+"-"+this.ft(s);t(s,{id:i,"aria-selected":"true",addClass:this.rt}),h(this.i,i),e(s,this.l,this.it,this.h)},this.ot=s=>{s&&t(s,{id:"",removeClass:this.rt,"aria-selected":"false"})},this.s=()=>{this.F&&(t(this.q,{class:this.u+"-clear hidden",type:"button",title:this.yt,"aria-label":this.yt}),this.i.insertAdjacentElement("afterend",this.q))},this.destroy=()=>{this.F&&this.q.classList.add("hidden"),this.i.value="",this.i.focus(),this.h.textContent="",this.T(),this.D(),this.vt(this.i),this.i.removeEventListener("keydown",this.Y),this.i.removeEventListener("click",this.Z),document.removeEventListener("click",this.tt)},this.I=d,this.i=document.getElementById(d),this.M=(G=V,Boolean(G&&"function"==typeof G.then)?V:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(V({currentValue:s,element:i}))}),this.st=S,this.v=R,this.bt=O,this.ct=B,this.et=T,this.vt=I,this.H=P,this.J=A,this.V=m,this.L=f,this.F=p,this.G=b,this.P=x,this.p=y,this.it=k,this.lt=g,this.yt=w||"clear the search query",this.u=j?j+"-auto":"auto",this.nt=C,this.k=v,this.l=this.u+"-"+this.I+"-results",this.g="data-cache-auto-"+this.I,this.W=this.u+"-is-loading",this.R=this.u+"-is-active",this.rt=this.u+"-selected",this.dt=this.u+"-selected-option",this.X=this.u+"-error",this.j=/[|\\{}()[\]^$+*?.]/g,this.S=null,this.o=a("div"),this.h=a("ul"),this.q=a("button"),this.t()}}})); +!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t="undefined"!=typeof globalThis?globalThis:t||self).Autocomplete=s()}(this,(function(){"use strict";const t=(t,s)=>{for(let i in s)"addClass"===i?h(t,"add",s[i]):"removeClass"===i?h(t,"remove",s[i]):t.setAttribute(i,s[i])},s=t=>(t.firstElementChild||t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=(t,s,i)=>t.classList[s](i),e=(s,i)=>{t(s,{"aria-activedescendant":i||""})},a=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll("#"+t+" > li:not(."+s+")");let h=0;return[].slice.call(i).map(t=>h+=t.offsetHeight),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},n=t=>document.createElement(t),l=t=>document.querySelector(t),o=(t,s,i)=>{t.addEventListener(s,i)},r=(t,s,i)=>{t.removeEventListener(s,i)},d=27,c=13,u=38,m=40,p=9;return class{constructor(f,b){let{delay:v=500,clearButton:x=!0,howManyCharacters:y=1,selectFirst:C=!1,insertToInput:k=!1,showAllValues:g=!1,cache:j=!1,disableCloseOnSelect:w=!1,classGroup:V,classPreventClosing:S,classPrefix:O,ariaLabelClear:T,onSearch:I,onResults:R=(()=>{}),onSubmit:A=(()=>{}),onOpened:P=(()=>{}),onReset:B=(()=>{}),onRender:G=(()=>{}),onClose:J=(()=>{}),noResults:N=(()=>{}),onSelectedItem:$=(()=>{})}=b;var q;this.t=()=>{var s,i,h,e,a;this.s(),s=this.i,i=this.h,h=this.l,e=this.o,a=this.u,t(i,{id:h,tabIndex:"0",role:"listbox"}),t(e,{addClass:a+"-results-wrapper"}),e.insertAdjacentElement("beforeend",i),s.parentNode.insertBefore(e,s.nextSibling),o(this.i,"input",this.m),this.p&&o(this.i,"click",this.m),this.v({element:this.i,results:this.h})},this.C=(t,s)=>{this.k&&("update"===t?this.i.setAttribute(this.g,s.value):"remove"===t?this.i.removeAttribute(this.g):this.i.value=this.i.getAttribute(this.g))},this.m=t=>{let{target:s,type:i}=t;if("true"===this.i.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.j,"\\$&");this.C("update",s);const e=this.p?0:this.V;clearTimeout(this.S),this.S=setTimeout(()=>{this.O(h.trim())},e)},this.T=()=>{t(this.i,{"aria-owns":this.I+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),h(this.o,"remove",this.R),this.A=this.P?0:-1,this.B()},this.O=t=>{this.G=t,this.J(!0),function(t,s){void 0===t&&(t=!1),t&&(h(t,"remove","hidden"),o(t,"click",s))}(this.N,this.destroy),0==t.length&&this.$&&h(this.N,"add","hidden"),this.q>t.length&&!this.p?this.J():this.F({currentValue:t,element:this.i}).then(s=>{const i=this.i.value.length,e=s.length;this.L=Array.isArray(s)?s:JSON.parse(JSON.stringify(s)),this.J(),this.M(),0==e&&0==i&&h(this.N,"add","hidden"),0==e&&i?(h(this.i,"remove","auto-expanded"),this.T(),this.D({element:this.i,currentValue:t,template:this.H}),this.K()):(e>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.A=this.P?0:-1,this.H(),this.K())}).catch(()=>{this.J(),this.T()})},this.J=t=>this.i.parentNode.classList[t?"add":"remove"](this.U),this.M=()=>h(this.i,"remove",this.W),this.K=()=>{o(this.i,"keydown",this.X),o(this.i,"click",this.Y),["mousemove","click"].map(t=>{o(this.h,t,this.Z)}),o(document,"click",this._)},this.H=s=>{t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.h.textContent="";const e=0===this.L.length?this.tt({currentValue:this.G,matches:0,template:s}):this.tt({currentValue:this.G,matches:this.L,classGroup:this.st});this.h.insertAdjacentHTML("afterbegin",e),h(this.o,"add",this.R);const a=this.st?":not(."+this.st+")":"";this.it=document.querySelectorAll("#"+this.l+" > li"+a),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.at||s.closest("."+this.nt))&&(i=!0),s.id===this.I||i||this.T()},this.et=()=>{if(this.lt(l("."+this.ot)),!this.P)return;const{firstElementChild:s}=this.h,i=this.st&&this.L.length>0&&this.P?s.nextElementSibling:s;this.rt({index:this.A,element:this.i,object:this.L[this.A]}),t(i,{id:this.dt+"-0",addClass:this.ot,"aria-selected":"true"}),e(this.i,this.dt+"-0")},this.Y=()=>{this.h.textContent.length>0&&!h(this.o,"contains",this.R)&&(t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),h(this.o,"add",this.R),i(this.h,this.o),this.et(),this.ht({type:"showItems",element:this.i,results:this.h}))},this.Z=t=>{t.preventDefault();const{target:s,type:i}=t,e=s.closest("li"),a=null==e?void 0:e.hasAttribute("role"),n=this.ot,o=l("."+n);e&&a&&("click"===i&&this.ct(e),"mousemove"!==i||h(e,"contains",n)||(this.lt(o),this.ut(e),this.A=this.pt(e),this.rt({index:this.A,element:this.i,object:this.L[this.A]})))},this.ct=t=>{t&&0!==this.L.length?(this.i.value=s(t),this.ft({index:this.A,element:this.i,object:this.L[this.A],results:this.h}),this.at||(this.lt(t),this.T()),this.$&&h(this.N,"remove","hidden"),this.C("remove")):!this.at&&this.T()},this.pt=t=>Array.prototype.indexOf.call(this.it,t),this.X=t=>{const{keyCode:i}=t,a=h(this.o,"contains",this.R),n=this.L.length+1;switch(this.bt=l("."+this.ot),i){case u:case m:if(t.preventDefault(),n<=1&&this.P||!a)return;i===u?(this.A<0&&(this.A=n-1),this.A-=1):(this.A+=1,this.A>=n&&(this.A=0)),this.lt(this.bt),this.A>=0&&this.A{const i=this.dt+"-"+this.pt(s);t(s,{id:i,"aria-selected":"true",addClass:this.ot}),e(this.i,i),a(s,this.l,this.st,this.h)},this.lt=s=>{s&&t(s,{id:"",removeClass:this.ot,"aria-selected":"false"})},this.s=()=>{this.$&&(t(this.N,{class:this.u+"-clear hidden",type:"button",title:this.xt,"aria-label":this.xt}),this.i.insertAdjacentElement("afterend",this.N))},this.destroy=()=>{this.$&&h(this.N,"add","hidden"),this.i.value="",this.i.focus(),this.h.textContent="",this.T(),this.M(),this.yt(this.i),r(this.i,"keydown",this.X),r(this.i,"click",this.Y),r(document,"click",this._)},this.I=f,this.i=document.getElementById(f),this.F=(q=I,Boolean(q&&"function"==typeof q.then)?I:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(I({currentValue:s,element:i}))}),this.tt=R,this.v=G,this.ft=A,this.rt=$,this.ht=P,this.yt=B,this.D=N,this.B=J,this.V=v,this.q=y,this.$=x,this.P=C,this.vt=k,this.p=g,this.st=V,this.nt=S,this.xt=T||"clear the search query",this.u=O?O+"-auto":"auto",this.at=w,this.k=j,this.l=this.u+"-"+this.I+"-results",this.g="data-cache-auto-"+this.I,this.U=this.u+"-is-loading",this.R=this.u+"-is-active",this.ot=this.u+"-selected",this.dt=this.u+"-selected-option",this.W=this.u+"-error",this.j=/[|\\{}()[\]^$+*?.]/g,this.S=null,this.o=n("div"),this.h=n("ul"),this.N=n("button"),this.t()}}})); diff --git a/docs/js/autocomplete.min.js b/docs/js/autocomplete.min.js index d7d7a5e..d00711a 100644 --- a/docs/js/autocomplete.min.js +++ b/docs/js/autocomplete.min.js @@ -1,2 +1,2 @@ -var Autocomplete=function(){"use strict";const t=(t,s)=>{for(let i in s)"addClass"===i?t.classList.add(s[i]):"removeClass"===i?t.classList.remove(s[i]):t.setAttribute(i,s[i])},s=(t,s)=>s.value=(t=>t.firstElementChild||t)(t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=(t,s)=>{t.setAttribute("aria-activedescendant",s||"")},e=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll("#"+t+" > li:not(."+s+")");let h=0;return[].slice.call(i).map(t=>h+=t.offsetHeight),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},a=t=>document.createElement(t),l=27,n=13,o=38,r=40,c=9;return class{constructor(d,u){let{delay:m=500,clearButton:p=!0,howManyCharacters:b=1,selectFirst:v=!1,insertToInput:f=!1,showAllValues:x=!1,cache:C=!1,disableCloseOnSelect:y=!1,classGroup:k,classPreventClosing:w,classPrefix:j,ariaLabelClear:V,onSearch:g,onResults:S=(()=>{}),onSubmit:O=(()=>{}),onOpened:A=(()=>{}),onReset:I=(()=>{}),onRender:R=(()=>{}),onClose:P=(()=>{}),noResults:T=(()=>{}),onSelectedItem:B=(()=>{})}=u;var G;this.t=()=>{var s,i,h,e,a;this.s(),s=this.i,i=this.h,h=this.l,e=this.o,a=this.u,t(i,{id:h,tabIndex:"0",role:"listbox"}),t(e,{addClass:a+"-results-wrapper"}),e.insertAdjacentElement("beforeend",i),s.parentNode.insertBefore(e,s.nextSibling),this.i.addEventListener("input",this.m),this.p&&this.i.addEventListener("click",this.m),this.v({element:this.i,results:this.h})},this.C=(t,s)=>{this.k&&("update"===t?this.i.setAttribute(this.j,s.value):"remove"===t?this.i.removeAttribute(this.j):this.i.value=this.i.getAttribute(this.j))},this.m=t=>{let{target:s,type:i}=t;if("true"===this.i.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.V,"\\$&");this.C("update",s);const e=this.p?0:this.g;clearTimeout(this.S),this.S=setTimeout(()=>{this.O(h.trim())},e)},this.A=()=>{var s;t(this.i,{"aria-owns":this.I+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),this.o.classList.remove(this.R),(0==(null==(s=this.P)?void 0:s.length)&&!this.T||this.p)&&(this.h.innerHTML=""),this.B=this.G?0:-1,this.J()},this.O=t=>{this.N=t,this.$(!0),function(t,s){void 0===t&&(t=!1),t&&(t.classList.remove("hidden"),t.addEventListener("click",s))}(this.q,this.destroy),0==t.length&&this.F&&this.q.classList.add("hidden"),this.L>t.length&&!this.p?this.$():this.M({currentValue:t,element:this.i}).then(s=>{const i=this.i.value.length,h=s.length;this.P=Array.isArray(s)?[...s]:JSON.parse(JSON.stringify(s)),this.$(),this.D(),0==h&&0==i&&this.q.classList.add("hidden"),0==h&&i?(this.i.classList.remove("auto-expanded"),this.A(),this.H({element:this.i,currentValue:t,template:this.K}),this.U()):(h>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.B=this.G?0:-1,this.K(),this.U())}).catch(()=>{this.$(),this.A()})},this.$=t=>this.i.parentNode.classList[t?"add":"remove"](this.W),this.D=()=>this.i.classList.remove(this.X),this.U=()=>{this.i.addEventListener("keydown",this.Y),this.i.addEventListener("click",this.Z),["mousemove","click"].map(t=>{this.h.addEventListener(t,this._)}),document.addEventListener("click",this.tt)},this.K=s=>{t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.h.innerHTML=0===this.P.length?this.st({currentValue:this.N,matches:0,template:s}):this.st({currentValue:this.N,matches:this.P,classGroup:this.it}),this.o.classList.add(this.R);const h=this.it?":not(."+this.it+")":"";this.ht=document.querySelectorAll("#"+this.l+" > li"+h),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.lt||s.closest("."+this.nt))&&(i=!0),s.id===this.I||i||this.A()},this.at=()=>{if(this.ot(document.querySelector("."+this.rt)),!this.G)return;const{firstElementChild:s}=this.h,i=this.it&&this.P.length>0&&this.G?s.nextElementSibling:s;this.ct({index:this.B,element:this.i,object:this.P[this.B]}),t(i,{id:this.dt+"-0",addClass:this.rt,"aria-selected":"true"}),h(this.i,this.dt+"-0")},this.Z=()=>{this.h.textContent.length>0&&!this.o.classList.contains(this.R)&&(t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.o.classList.add(this.R),i(this.h,this.o),this.at(),this.et({type:"showItems",element:this.i,results:this.h}))},this._=t=>{t.preventDefault();const{target:s,type:i}=t,h=s.closest("li"),e=null==h?void 0:h.hasAttribute("role"),a=this.rt,l=document.querySelector("."+a);h&&e&&("click"===i&&this.ut(h),"mousemove"!==i||h.classList.contains(a)||(this.ot(l),this.pt(h),this.B=this.bt(h),this.ct({index:this.B,element:this.i,object:this.P[this.B]})))},this.ut=t=>{t&&0!==this.P.length?(s(t,this.i),this.vt({index:this.B,element:this.i,object:this.P[this.B],results:this.h}),this.lt||(this.ot(t),this.A()),this.F&&this.q.classList.remove("hidden"),this.C("remove")):!this.lt&&this.A()},this.bt=t=>Array.prototype.indexOf.call(this.ht,t),this.Y=t=>{const{keyCode:i}=t,e=this.o.classList.contains(this.R),a=this.P.length+1;switch(this.ft=document.querySelector("."+this.rt),i){case o:case r:if(t.preventDefault(),a<=1&&this.G||!e)return;i===o?(this.B<0&&(this.B=a-1),this.B-=1):(this.B+=1,this.B>=a&&(this.B=0)),this.ot(this.ft),a>0&&this.B>=0&&this.B{const i=this.dt+"-"+this.bt(s);t(s,{id:i,"aria-selected":"true",addClass:this.rt}),h(this.i,i),e(s,this.l,this.it,this.h)},this.ot=s=>{s&&t(s,{id:"",removeClass:this.rt,"aria-selected":"false"})},this.s=()=>{this.F&&(t(this.q,{class:this.u+"-clear hidden",type:"button",title:this.xt,"aria-label":this.xt}),this.i.insertAdjacentElement("afterend",this.q))},this.destroy=()=>{this.F&&this.q.classList.add("hidden"),this.i.value="",this.i.focus(),this.h.textContent="",this.A(),this.D(),this.Ct(this.i),this.i.removeEventListener("keydown",this.Y),this.i.removeEventListener("click",this.Z),document.removeEventListener("click",this.tt)},this.I=d,this.i=document.getElementById(d),this.M=(G=g,Boolean(G&&"function"==typeof G.then)?g:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(g({currentValue:s,element:i}))}),this.st=S,this.v=R,this.vt=O,this.ct=B,this.et=A,this.Ct=I,this.H=T,this.J=P,this.g=m,this.L=b,this.F=p,this.G=v,this.T=f,this.p=x,this.it=k,this.nt=w,this.xt=V||"clear the search query",this.u=j?j+"-auto":"auto",this.lt=y,this.k=C,this.l=this.u+"-"+this.I+"-results",this.j="data-cache-auto-"+this.I,this.W=this.u+"-is-loading",this.R=this.u+"-is-active",this.rt=this.u+"-selected",this.dt=this.u+"-selected-option",this.X=this.u+"-error",this.V=/[|\\{}()[\]^$+*?.]/g,this.S=null,this.o=a("div"),this.h=a("ul"),this.q=a("button"),this.t()}}}(); +var Autocomplete=function(){"use strict";const t=(t,s)=>{for(let i in s)"addClass"===i?h(t,"add",s[i]):"removeClass"===i?h(t,"remove",s[i]):t.setAttribute(i,s[i])},s=t=>(t.firstElementChild||t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=(t,s,i)=>t.classList[s](i),e=(s,i)=>{t(s,{"aria-activedescendant":i||""})},a=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll("#"+t+" > li:not(."+s+")");let h=0;return[].slice.call(i).map(t=>h+=t.offsetHeight),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},n=t=>document.createElement(t),l=t=>document.querySelector(t),o=(t,s,i)=>{t.addEventListener(s,i)},r=(t,s,i)=>{t.removeEventListener(s,i)},c=27,d=13,u=38,m=40,p=9;return class{constructor(v,b){let{delay:f=500,clearButton:x=!0,howManyCharacters:C=1,selectFirst:y=!1,insertToInput:k=!1,showAllValues:w=!1,cache:g=!1,disableCloseOnSelect:j=!1,classGroup:V,classPreventClosing:S,classPrefix:O,ariaLabelClear:A,onSearch:I,onResults:R=(()=>{}),onSubmit:P=(()=>{}),onOpened:T=(()=>{}),onReset:B=(()=>{}),onRender:G=(()=>{}),onClose:J=(()=>{}),noResults:N=(()=>{}),onSelectedItem:$=(()=>{})}=b;var q;this.t=()=>{var s,i,h,e,a;this.s(),s=this.i,i=this.h,h=this.l,e=this.o,a=this.u,t(i,{id:h,tabIndex:"0",role:"listbox"}),t(e,{addClass:a+"-results-wrapper"}),e.insertAdjacentElement("beforeend",i),s.parentNode.insertBefore(e,s.nextSibling),o(this.i,"input",this.m),this.p&&o(this.i,"click",this.m),this.v({element:this.i,results:this.h})},this.C=(t,s)=>{this.k&&("update"===t?this.i.setAttribute(this.g,s.value):"remove"===t?this.i.removeAttribute(this.g):this.i.value=this.i.getAttribute(this.g))},this.m=t=>{let{target:s,type:i}=t;if("true"===this.i.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.j,"\\$&");this.C("update",s);const e=this.p?0:this.V;clearTimeout(this.S),this.S=setTimeout(()=>{this.O(h.trim())},e)},this.A=()=>{t(this.i,{"aria-owns":this.I+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),h(this.o,"remove",this.R),this.P=this.T?0:-1,this.B()},this.O=t=>{this.G=t,this.J(!0),function(t,s){void 0===t&&(t=!1),t&&(h(t,"remove","hidden"),o(t,"click",s))}(this.N,this.destroy),0==t.length&&this.$&&h(this.N,"add","hidden"),this.q>t.length&&!this.p?this.J():this.F({currentValue:t,element:this.i}).then(s=>{const i=this.i.value.length,e=s.length;this.L=Array.isArray(s)?s:JSON.parse(JSON.stringify(s)),this.J(),this.M(),0==e&&0==i&&h(this.N,"add","hidden"),0==e&&i?(h(this.i,"remove","auto-expanded"),this.A(),this.D({element:this.i,currentValue:t,template:this.H}),this.K()):(e>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.P=this.T?0:-1,this.H(),this.K())}).catch(()=>{this.J(),this.A()})},this.J=t=>this.i.parentNode.classList[t?"add":"remove"](this.U),this.M=()=>h(this.i,"remove",this.W),this.K=()=>{o(this.i,"keydown",this.X),o(this.i,"click",this.Y),["mousemove","click"].map(t=>{o(this.h,t,this.Z)}),o(document,"click",this._)},this.H=s=>{t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),this.h.textContent="";const e=0===this.L.length?this.tt({currentValue:this.G,matches:0,template:s}):this.tt({currentValue:this.G,matches:this.L,classGroup:this.st});this.h.insertAdjacentHTML("afterbegin",e),h(this.o,"add",this.R);const a=this.st?":not(."+this.st+")":"";this.it=document.querySelectorAll("#"+this.l+" > li"+a),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.at||s.closest("."+this.nt))&&(i=!0),s.id===this.I||i||this.A()},this.et=()=>{if(this.lt(l("."+this.ot)),!this.T)return;const{firstElementChild:s}=this.h,i=this.st&&this.L.length>0&&this.T?s.nextElementSibling:s;this.rt({index:this.P,element:this.i,object:this.L[this.P]}),t(i,{id:this.ct+"-0",addClass:this.ot,"aria-selected":"true"}),e(this.i,this.ct+"-0")},this.Y=()=>{this.h.textContent.length>0&&!h(this.o,"contains",this.R)&&(t(this.i,{"aria-expanded":"true",addClass:this.u+"-expanded"}),h(this.o,"add",this.R),i(this.h,this.o),this.et(),this.ht({type:"showItems",element:this.i,results:this.h}))},this.Z=t=>{t.preventDefault();const{target:s,type:i}=t,e=s.closest("li"),a=null==e?void 0:e.hasAttribute("role"),n=this.ot,o=l("."+n);e&&a&&("click"===i&&this.dt(e),"mousemove"!==i||h(e,"contains",n)||(this.lt(o),this.ut(e),this.P=this.pt(e),this.rt({index:this.P,element:this.i,object:this.L[this.P]})))},this.dt=t=>{t&&0!==this.L.length?(this.i.value=s(t),this.vt({index:this.P,element:this.i,object:this.L[this.P],results:this.h}),this.at||(this.lt(t),this.A()),this.$&&h(this.N,"remove","hidden"),this.C("remove")):!this.at&&this.A()},this.pt=t=>Array.prototype.indexOf.call(this.it,t),this.X=t=>{const{keyCode:i}=t,a=h(this.o,"contains",this.R),n=this.L.length+1;switch(this.bt=l("."+this.ot),i){case u:case m:if(t.preventDefault(),n<=1&&this.T||!a)return;i===u?(this.P<0&&(this.P=n-1),this.P-=1):(this.P+=1,this.P>=n&&(this.P=0)),this.lt(this.bt),this.P>=0&&this.P{const i=this.ct+"-"+this.pt(s);t(s,{id:i,"aria-selected":"true",addClass:this.ot}),e(this.i,i),a(s,this.l,this.st,this.h)},this.lt=s=>{s&&t(s,{id:"",removeClass:this.ot,"aria-selected":"false"})},this.s=()=>{this.$&&(t(this.N,{class:this.u+"-clear hidden",type:"button",title:this.xt,"aria-label":this.xt}),this.i.insertAdjacentElement("afterend",this.N))},this.destroy=()=>{this.$&&h(this.N,"add","hidden"),this.i.value="",this.i.focus(),this.h.textContent="",this.A(),this.M(),this.Ct(this.i),r(this.i,"keydown",this.X),r(this.i,"click",this.Y),r(document,"click",this._)},this.I=v,this.i=document.getElementById(v),this.F=(q=I,Boolean(q&&"function"==typeof q.then)?I:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(I({currentValue:s,element:i}))}),this.tt=R,this.v=G,this.vt=P,this.rt=$,this.ht=T,this.Ct=B,this.D=N,this.B=J,this.V=f,this.q=C,this.$=x,this.T=y,this.ft=k,this.p=w,this.st=V,this.nt=S,this.xt=A||"clear the search query",this.u=O?O+"-auto":"auto",this.at=j,this.k=g,this.l=this.u+"-"+this.I+"-results",this.g="data-cache-auto-"+this.I,this.U=this.u+"-is-loading",this.R=this.u+"-is-active",this.ot=this.u+"-selected",this.ct=this.u+"-selected-option",this.W=this.u+"-error",this.j=/[|\\{}()[\]^$+*?.]/g,this.S=null,this.o=n("div"),this.h=n("ul"),this.N=n("button"),this.t()}}}(); //# sourceMappingURL=autocomplete.min.js.map diff --git a/docs/js/autocomplete.min.js.map b/docs/js/autocomplete.min.js.map index c6f56cb..de896b4 100644 --- a/docs/js/autocomplete.min.js.map +++ b/docs/js/autocomplete.min.js.map @@ -1 +1 @@ -{"version":3,"file":"autocomplete.min.js","sources":["../../sources/js/utils/function.js","../../sources/js/utils/keyCodes.js","../../sources/js/script.js"],"sourcesContent":["/**\r\n * Check is a Object\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isObject = (value) =>\r\n value && typeof value === \"object\" && value.constructor === Object;\r\n\r\n/**\r\n * Check if is a Promise\r\n * https://stackoverflow.com/a/53955664/10424385\r\n *\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isPromise = (value) => Boolean(value && typeof value.then === \"function\");\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n if (key === \"addClass\") {\r\n el.classList.add(object[key]);\r\n } else if (key === \"removeClass\") {\r\n el.classList.remove(object[key]);\r\n } else {\r\n el.setAttribute(key, object[key]);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Get first element from child\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {HTMLELement}\r\n */\r\nconst getFirstElement = (element) => element.firstElementChild || element;\r\n\r\n/**\r\n * Set data from li to input\r\n *\r\n * @param {String} element\r\n * @param {HTMLElement} root\r\n * @returns {String}\r\n */\r\nconst getFirstElementFromLiAndAddToInput = (element, root) =>\r\n // get first element from li and add to input\r\n (root.value = getFirstElement(element).textContent.trim());\r\n\r\n/**\r\n * Scroll to top result-list\r\n * @param {HTMLElement} resultList\r\n * @param {HTMLElement} resultWrap\r\n */\r\nconst scrollResultsToTop = (resultList, resultWrap) => {\r\n // if there is an overflow of ul element, after\r\n // opening we always move ul to the top of the results\r\n resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight;\r\n};\r\n\r\n/**\r\n * Adding role, tabindex, aria and call handleMouse\r\n *\r\n * @param {HTMLElement} itemsLi\r\n */\r\nconst addAriaToAllLiElements = (itemsLi) => {\r\n // add role to all li elements\r\n for (let i = 0; i < itemsLi.length; i++) {\r\n setAttributes(itemsLi[i], {\r\n role: \"option\",\r\n tabindex: \"-1\",\r\n \"aria-selected\": \"false\",\r\n \"aria-setsize\": itemsLi.length,\r\n \"aria-posinset\": i,\r\n });\r\n }\r\n};\r\n\r\n/**\r\n * Show btn to clear data\r\n *\r\n * @param {HTMLElement} clearButton - button to clear data\r\n * @param {Function} destroy - destroy function\r\n */\r\nconst showBtnToClearData = (clearButton = false, destroy) => {\r\n if (!clearButton) return;\r\n\r\n clearButton.classList.remove(\"hidden\");\r\n // add event to clear button\r\n clearButton.addEventListener(\"click\", destroy);\r\n};\r\n\r\n/**\r\n * Set aria-activedescendant\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {String} type\r\n */\r\nconst setAriaActivedescendant = (root, type) => {\r\n root.setAttribute(\"aria-activedescendant\", type || \"\");\r\n};\r\n\r\n/**\r\n * Get height of ul without group class\r\n *\r\n * @param {String} outputUl\r\n * @param {String} classGroup\r\n * @returns {Number}\r\n */\r\nconst getClassGroupHeight = (outputUl, classGroup) => {\r\n // get height of ul without group class\r\n const allLi = document.querySelectorAll(\r\n `#${outputUl} > li:not(.${classGroup})`\r\n );\r\n let height = 0;\r\n [].slice.call(allLi).map((el) => (height += el.offsetHeight));\r\n\r\n // return height\r\n return height;\r\n};\r\n\r\n/**\r\n * Scroll into view when press up/down arrows\r\n *\r\n * @param {HTMLElement} target\r\n * @param {HTMLElement} outputUl\r\n * @param {String} classGroup\r\n * @param {HTMLElement} resultList\r\n */\r\nconst followActiveElement = (target, outputUl, classGroup, resultList) => {\r\n const previusElement = resultList.previousSibling;\r\n\r\n const previusElementHeight = previusElement ? previusElement.offsetHeight : 0;\r\n\r\n if (target.getAttribute(\"aria-posinset\") == \"0\") {\r\n resultList.scrollTop =\r\n target.offsetTop - getClassGroupHeight(outputUl, classGroup);\r\n }\r\n\r\n if (target.offsetTop - previusElementHeight < resultList.scrollTop) {\r\n resultList.scrollTop = target.offsetTop - previusElementHeight;\r\n } else {\r\n const offsetBottom =\r\n target.offsetTop + target.offsetHeight - previusElementHeight;\r\n const scrollBottom = resultList.scrollTop + resultList.offsetHeight;\r\n if (offsetBottom > scrollBottom) {\r\n resultList.scrollTop = offsetBottom - resultList.offsetHeight;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Create output-list and put after search input\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {HTMLElement} resultList - output-list ul\r\n * @param {String} outputUl - id name of output-list\r\n * @param {HTMLElement} resultWrap - wrapper ul element\r\n * @param {String} prefix - add prefix to all class auto\r\n */\r\nconst output = (root, resultList, outputUl, resultWrap, prefix) => {\r\n // set attribute to results-list\r\n setAttributes(resultList, {\r\n id: outputUl,\r\n tabIndex: \"0\",\r\n role: \"listbox\",\r\n });\r\n\r\n // add class to wrap element\r\n setAttributes(resultWrap, {\r\n addClass: `${prefix}-results-wrapper`,\r\n });\r\n\r\n // insert the results into the wrap element\r\n resultWrap.insertAdjacentElement(\"beforeend\", resultList);\r\n\r\n // insert the wrap element after the search input\r\n root.parentNode.insertBefore(resultWrap, root.nextSibling);\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLDivElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport {\r\n addAriaToAllLiElements,\r\n createElement,\r\n followActiveElement,\r\n getFirstElementFromLiAndAddToInput,\r\n isObject,\r\n isPromise,\r\n output,\r\n scrollResultsToTop,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n};\r\n","/**\r\n * Key codes\r\n */\r\nconst keyCodes = {\r\n ESC: 27,\r\n ENTER: 13,\r\n UP: 38,\r\n DOWN: 40,\r\n TAB: 9,\r\n};\r\n\r\nexport default keyCodes;\r\n","import {\r\n addAriaToAllLiElements,\r\n createElement,\r\n followActiveElement,\r\n getFirstElementFromLiAndAddToInput,\r\n isObject,\r\n isPromise,\r\n output,\r\n scrollResultsToTop,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n} from \"./utils/function\";\r\n\r\nimport keyCodes from \"./utils/keyCodes\";\r\n\r\n/**\r\n * @class Autocomplete\r\n */\r\nexport default class Autocomplete {\r\n /**\r\n * Constructor\r\n *\r\n * @param {String} element\r\n * @param {Object} object\r\n */\r\n constructor(\r\n element,\r\n {\r\n delay = 500,\r\n clearButton = true,\r\n howManyCharacters = 1,\r\n selectFirst = false,\r\n insertToInput = false,\r\n showAllValues = false,\r\n cache = false,\r\n disableCloseOnSelect = false,\r\n classGroup,\r\n classPreventClosing,\r\n classPrefix,\r\n ariaLabelClear,\r\n onSearch,\r\n onResults = () => {},\r\n onSubmit = () => {},\r\n onOpened = () => {},\r\n onReset = () => {},\r\n onRender = () => {},\r\n onClose = () => {},\r\n noResults = () => {},\r\n onSelectedItem = () => {},\r\n }\r\n ) {\r\n this._id = element;\r\n this._root = document.getElementById(element);\r\n this._onSearch = isPromise(onSearch)\r\n ? onSearch\r\n : ({ currentValue, element }) =>\r\n Promise.resolve(onSearch({ currentValue, element }));\r\n this._onResults = onResults;\r\n this._onRender = onRender;\r\n this._onSubmit = onSubmit;\r\n this._onSelected = onSelectedItem;\r\n this._onOpened = onOpened;\r\n this._onReset = onReset;\r\n this._noResults = noResults;\r\n this._onClose = onClose;\r\n\r\n this._delay = delay;\r\n this._characters = howManyCharacters;\r\n this._clearButton = clearButton;\r\n this._selectFirst = selectFirst;\r\n this._toInput = insertToInput;\r\n this._showAll = showAllValues;\r\n this._classGroup = classGroup;\r\n this._prevClosing = classPreventClosing;\r\n this._clearBtnAriLabel = ariaLabelClear\r\n ? ariaLabelClear\r\n : \"clear the search query\";\r\n this._prefix = classPrefix ? `${classPrefix}-auto` : \"auto\";\r\n this._disable = disableCloseOnSelect;\r\n\r\n // default config\r\n this._cache = cache;\r\n this._outputUl = `${this._prefix}-${this._id}-results`;\r\n this._cacheData = `data-cache-auto-${this._id}`;\r\n this._isLoading = `${this._prefix}-is-loading`;\r\n this._isActive = `${this._prefix}-is-active`;\r\n this._activeList = `${this._prefix}-selected`;\r\n this._selectedOption = `${this._prefix}-selected-option`;\r\n this._err = `${this._prefix}-error`;\r\n this._regex = /[|\\\\{}()[\\]^$+*?.]/g;\r\n this._timeout = null;\r\n\r\n this._resultWrap = createElement(\"div\");\r\n this._resultList = createElement(\"ul\");\r\n this._cBtn = createElement(\"button\");\r\n\r\n this._initial();\r\n }\r\n\r\n /**\r\n * Initial function\r\n */\r\n _initial = () => {\r\n this._clearbutton();\r\n\r\n output(\r\n this._root,\r\n this._resultList,\r\n this._outputUl,\r\n this._resultWrap,\r\n this._prefix\r\n );\r\n\r\n // default aria\r\n // this.reset();\r\n this._root.addEventListener(\"input\", this._handleInput);\r\n\r\n // show all values on click root input\r\n this._showAll && this._root.addEventListener(\"click\", this._handleInput);\r\n\r\n // calback functions\r\n this._onRender({\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n };\r\n\r\n /**\r\n * Actions on input\r\n *\r\n * @param {String} type - set attribute depending on type\r\n * @param {String} target\r\n */\r\n _cacheAct = (type, target) => {\r\n if (!this._cache) return;\r\n\r\n if (type === \"update\") {\r\n this._root.setAttribute(this._cacheData, target.value);\r\n } else if (type === \"remove\") {\r\n this._root.removeAttribute(this._cacheData);\r\n } else {\r\n this._root.value = this._root.getAttribute(this._cacheData);\r\n }\r\n };\r\n\r\n /**\r\n * Handle input\r\n *\r\n * @param {Event} object\r\n */\r\n _handleInput = ({ target, type }) => {\r\n if (\r\n this._root.getAttribute(\"aria-expanded\") === \"true\" &&\r\n type === \"click\"\r\n ) {\r\n return;\r\n }\r\n\r\n // replace all special characters\r\n const regex = target.value.replace(this._regex, \"\\\\$&\");\r\n\r\n // update data attribute cache\r\n this._cacheAct(\"update\", target);\r\n\r\n const delay = this._showAll ? 0 : this._delay;\r\n // clear timeout\r\n clearTimeout(this._timeout);\r\n this._timeout = setTimeout(() => {\r\n this._searchItem(regex.trim());\r\n }, delay);\r\n };\r\n\r\n /**\r\n * Default aria\r\n */\r\n _reset = () => {\r\n // set attributes to root - input\r\n setAttributes(this._root, {\r\n \"aria-owns\": `${this._id}-list`,\r\n \"aria-expanded\": \"false\",\r\n \"aria-autocomplete\": \"list\",\r\n \"aria-activedescendant\": \"\",\r\n role: \"combobox\",\r\n removeClass: \"auto-expanded\",\r\n });\r\n\r\n // remove class isActive\r\n this._resultWrap.classList.remove(this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n // scrollResultsToTop(this.resultList, this.resultWrap);\r\n\r\n // remove result when lengh = 0 and insertToInput is false\r\n if ((this._matches?.length == 0 && !this._toInput) || this._showAll) {\r\n this._resultList.innerHTML = \"\";\r\n }\r\n\r\n // set index\r\n this._index = this._selectFirst ? 0 : -1;\r\n\r\n // callback function\r\n this._onClose();\r\n };\r\n\r\n /**\r\n * The async function gets the text from the search\r\n * and returns the matching array\r\n *\r\n * @param {String} value\r\n */\r\n _searchItem = (value) => {\r\n this._value = value;\r\n\r\n // if searching show loading icon\r\n this._onLoading(true);\r\n\r\n // hide button clear\r\n showBtnToClearData(this._cBtn, this.destroy);\r\n\r\n // if there is no value and clearButton is true\r\n if (value.length == 0 && this._clearButton) {\r\n this._cBtn.classList.add(\"hidden\");\r\n }\r\n\r\n // if declare characters more then value.len and showAll is false\r\n // remove class isActive\r\n if (this._characters > value.length && !this._showAll) {\r\n this._onLoading();\r\n return;\r\n }\r\n\r\n // callblack function onSearch\r\n this._onSearch({ currentValue: value, element: this._root })\r\n .then((result) => {\r\n const rootValueLength = this._root.value.length;\r\n const resultLength = result.length;\r\n // set no result\r\n this._matches = Array.isArray(result)\r\n ? [...result]\r\n : JSON.parse(JSON.stringify(result));\r\n\r\n this._onLoading();\r\n this._error();\r\n\r\n // if use destroy() method\r\n if (resultLength == 0 && rootValueLength == 0) {\r\n this._cBtn.classList.add(\"hidden\");\r\n }\r\n\r\n if (resultLength == 0 && rootValueLength) {\r\n this._root.classList.remove(\"auto-expanded\");\r\n this._reset();\r\n this._noResults({\r\n element: this._root,\r\n currentValue: value,\r\n template: this._results,\r\n });\r\n this._events();\r\n } else if (resultLength > 0 || isObject(result)) {\r\n this._index = this._selectFirst ? 0 : -1;\r\n this._results();\r\n this._events();\r\n }\r\n })\r\n .catch(() => {\r\n this._onLoading();\r\n this._reset();\r\n });\r\n };\r\n\r\n /**\r\n * Set or remove loading class\r\n *\r\n * @param {Boolean} type\r\n */\r\n _onLoading = (type) =>\r\n this._root.parentNode.classList[type ? \"add\" : \"remove\"](this._isLoading);\r\n\r\n /**\r\n * Set error class to the root element\r\n */\r\n _error = () => this._root.classList.remove(this._err);\r\n\r\n /**\r\n * Events\r\n */\r\n _events = () => {\r\n // handle click on keydown [up, down, enter, tab, esc]\r\n this._root.addEventListener(\"keydown\", this._handleKeys);\r\n\r\n //\r\n this._root.addEventListener(\"click\", this._handleShowItems);\r\n\r\n // temporarily disabled mouseleave\r\n [\"mousemove\", \"click\"].map((eventType) => {\r\n this._resultList.addEventListener(eventType, this._handleMouse);\r\n });\r\n\r\n // close expanded items\r\n document.addEventListener(\"click\", this._handleDocClick);\r\n };\r\n\r\n /**\r\n * Results\r\n *\r\n * @param {HTMLElement|String} template - html or string returned from the function,\r\n * look at the example - https://github.com/tomik23/autocomplete/blob/master/docs/js/examples/no-results.js#L30\r\n */\r\n _results = (template) => {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add all found records to otput ul\r\n this._resultList.innerHTML =\r\n this._matches.length === 0\r\n ? this._onResults({\r\n currentValue: this._value,\r\n matches: 0,\r\n template,\r\n })\r\n : this._onResults({\r\n currentValue: this._value,\r\n matches: this._matches,\r\n classGroup: this._classGroup,\r\n });\r\n\r\n this._resultWrap.classList.add(this._isActive);\r\n\r\n const checkIfClassGroupExist = this._classGroup\r\n ? `:not(.${this._classGroup})`\r\n : \"\";\r\n\r\n this._itemsLi = document.querySelectorAll(\r\n `#${this._outputUl} > li${checkIfClassGroupExist}`\r\n );\r\n\r\n // adding role, tabindex and aria\r\n addAriaToAllLiElements(this._itemsLi);\r\n\r\n // action on open results\r\n this._onOpened({\r\n type: \"results\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n\r\n // select first element\r\n this._selectFirstEl();\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n };\r\n\r\n /**\r\n * Hangle click on document\r\n *\r\n * @param {Event} object\r\n */\r\n _handleDocClick = ({ target }) => {\r\n let disableClose = null;\r\n\r\n // if 'target' is a ul and 'disableCloseOnSelect'\r\n // is a 'true' set 'disableClose' on true\r\n if (\r\n (target.closest(\"ul\") && this._disable) ||\r\n // when class classDisableClose\r\n // then do not not close results\r\n target.closest(`.${this._prevClosing}`)\r\n ) {\r\n disableClose = true;\r\n }\r\n\r\n if (target.id !== this._id && !disableClose) {\r\n this._reset();\r\n return;\r\n }\r\n };\r\n\r\n /**\r\n * Select first element\r\n */\r\n _selectFirstEl = () => {\r\n this._remAria(document.querySelector(`.${this._activeList}`));\r\n\r\n if (!this._selectFirst) {\r\n return;\r\n }\r\n\r\n const { firstElementChild } = this._resultList;\r\n\r\n const classSelectFirst =\r\n this._classGroup && this._matches.length > 0 && this._selectFirst\r\n ? firstElementChild.nextElementSibling\r\n : firstElementChild;\r\n\r\n // calback function onSelect when first element is true\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set attribute to first element\r\n setAttributes(classSelectFirst, {\r\n id: `${this._selectedOption}-0`,\r\n addClass: this._activeList,\r\n \"aria-selected\": \"true\",\r\n });\r\n\r\n // set aria active descendant\r\n setAriaActivedescendant(this._root, `${this._selectedOption}-0`);\r\n };\r\n\r\n /**\r\n * show items when items.length > 0 and is not empty\r\n */\r\n _handleShowItems = () => {\r\n // if resultWrap is not active and resultList is not empty\r\n if (\r\n this._resultList.textContent.length > 0 &&\r\n !this._resultWrap.classList.contains(this._isActive)\r\n ) {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add isActive class to resultWrap\r\n this._resultWrap.classList.add(this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n\r\n // select first element\r\n this._selectFirstEl();\r\n\r\n // callback function\r\n this._onOpened({\r\n type: \"showItems\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Adding text from the list when li is clicking\r\n * or adding aria-selected to li elements\r\n *\r\n * @param {Event} event\r\n */\r\n _handleMouse = (event) => {\r\n event.preventDefault();\r\n\r\n const { target, type } = event;\r\n const targetClosest = target.closest(\"li\");\r\n const targetClosestRole = targetClosest?.hasAttribute(\"role\");\r\n const activeClass = this._activeList;\r\n const activeClassElement = document.querySelector(`.${activeClass}`);\r\n\r\n if (!targetClosest || !targetClosestRole) {\r\n return;\r\n }\r\n\r\n // click on li get element\r\n if (type === \"click\") {\r\n // get text from clicked li\r\n this._getTextFromLi(targetClosest);\r\n }\r\n\r\n if (\r\n type === \"mousemove\" &&\r\n !targetClosest.classList.contains(activeClass)\r\n ) {\r\n this._remAria(activeClassElement);\r\n\r\n // add aria to li\r\n this._setAria(targetClosest);\r\n this._index = this._indexLiSelected(targetClosest);\r\n\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Get text from li on enter or click\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _getTextFromLi = (element) => {\r\n if (!element || this._matches.length === 0) {\r\n // set default settings\r\n !this._disable && this._reset();\r\n\r\n return;\r\n }\r\n\r\n // get first element from li and set it to root\r\n getFirstElementFromLiAndAddToInput(element, this._root);\r\n\r\n // onSubmit passing text to function\r\n this._onSubmit({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n results: this._resultList,\r\n });\r\n\r\n // set default settings\r\n if (!this._disable) {\r\n this._remAria(element);\r\n this._reset();\r\n }\r\n\r\n // show clearBtn when select element\r\n this._clearButton && this._cBtn.classList.remove(\"hidden\");\r\n\r\n // remove cache\r\n this._cacheAct(\"remove\");\r\n };\r\n\r\n /**\r\n * Return which li element was selected\r\n * by hovering the mouse over\r\n *\r\n * @param {HTMLElement} target\r\n * @returns {Number}\r\n */\r\n _indexLiSelected = (target) =>\r\n // get index of li element\r\n Array.prototype.indexOf.call(this._itemsLi, target);\r\n\r\n /**\r\n * Navigating the elements li and enter\r\n *\r\n * @param {Event} event\r\n */\r\n _handleKeys = (event) => {\r\n const { keyCode } = event;\r\n\r\n const resultList = this._resultWrap.classList.contains(this._isActive);\r\n\r\n const matchesLength = this._matches.length + 1;\r\n this._selectedLi = document.querySelector(`.${this._activeList}`);\r\n\r\n // switch between keys\r\n switch (keyCode) {\r\n case keyCodes.UP:\r\n case keyCodes.DOWN:\r\n // Wrong cursor position in the input field #62\r\n // Prevents the cursor from moving to the beginning\r\n // of input as the cursor hovers over the results.\r\n event.preventDefault();\r\n\r\n if ((matchesLength <= 1 && this._selectFirst) || !resultList) {\r\n return;\r\n }\r\n\r\n // if keyCode is up\r\n if (keyCode === keyCodes.UP) {\r\n if (this._index < 0) {\r\n this._index = matchesLength - 1;\r\n }\r\n this._index -= 1;\r\n } else {\r\n this._index += 1;\r\n if (this._index >= matchesLength) {\r\n this._index = 0;\r\n }\r\n }\r\n\r\n // remove aria-selected\r\n this._remAria(this._selectedLi);\r\n\r\n if (\r\n matchesLength > 0 &&\r\n this._index >= 0 &&\r\n this._index < matchesLength - 1\r\n ) {\r\n if (this._toInput && resultList) {\r\n getFirstElementFromLiAndAddToInput(\r\n this._itemsLi[this._index],\r\n this._root\r\n );\r\n }\r\n\r\n // callback function\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set aria-selected\r\n this._setAria(this._itemsLi[this._index]);\r\n } else {\r\n // catch action\r\n this._cacheAct();\r\n setAriaActivedescendant(this._root);\r\n\r\n this._onSelected({\r\n index: null,\r\n element: this._root,\r\n object: null,\r\n });\r\n }\r\n\r\n break;\r\n // keycode enter\r\n case keyCodes.ENTER:\r\n this._getTextFromLi(this._selectedLi);\r\n break;\r\n\r\n // keycode escape and keycode tab\r\n case keyCodes.TAB:\r\n case keyCodes.ESC:\r\n event.stopPropagation(); // #120\r\n this._reset();\r\n\r\n break;\r\n default:\r\n break;\r\n }\r\n };\r\n\r\n /**\r\n * Set aria label on item li\r\n *\r\n * @param {HTMLElement} target\r\n */\r\n _setAria = (target) => {\r\n const selectedOption = `${this._selectedOption}-${this._indexLiSelected(\r\n target\r\n )}`;\r\n\r\n // set aria to li\r\n setAttributes(target, {\r\n id: selectedOption,\r\n \"aria-selected\": \"true\",\r\n addClass: this._activeList,\r\n });\r\n\r\n setAriaActivedescendant(this._root, selectedOption);\r\n\r\n // scrollIntoView when press up/down arrows\r\n followActiveElement(\r\n target,\r\n this._outputUl,\r\n this._classGroup,\r\n this._resultList\r\n );\r\n };\r\n\r\n /**\r\n * Remove aria label from item li\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _remAria = (element) => {\r\n if (!element) return;\r\n\r\n // remove aria from li\r\n setAttributes(element, {\r\n id: \"\",\r\n removeClass: this._activeList,\r\n \"aria-selected\": \"false\",\r\n });\r\n };\r\n\r\n /**\r\n * Create clear button and\r\n * removing text from the input field\r\n */\r\n _clearbutton = () => {\r\n // stop when clear button is disabled\r\n if (!this._clearButton) return;\r\n\r\n // add aria to clear button\r\n setAttributes(this._cBtn, {\r\n class: `${this._prefix}-clear hidden`,\r\n type: \"button\",\r\n title: this._clearBtnAriLabel,\r\n \"aria-label\": this._clearBtnAriLabel,\r\n });\r\n\r\n // insert clear button after input - root\r\n this._root.insertAdjacentElement(\"afterend\", this._cBtn);\r\n };\r\n\r\n /**\r\n * Clicking on the clear button\r\n * publick destroy method\r\n */\r\n destroy = () => {\r\n // if clear button is true then add class hidden\r\n this._clearButton && this._cBtn.classList.add(\"hidden\");\r\n // clear value searchId\r\n this._root.value = \"\";\r\n // set focus\r\n this._root.focus();\r\n // remove li from ul\r\n this._resultList.textContent = \"\";\r\n // set default aria\r\n this._reset();\r\n // remove error if exist\r\n this._error();\r\n\r\n // callback function\r\n this._onReset(this._root);\r\n\r\n // remove listener\r\n this._root.removeEventListener(\"keydown\", this._handleKeys);\r\n this._root.removeEventListener(\"click\", this._handleShowItems);\r\n // remove listener on click on document\r\n document.removeEventListener(\"click\", this._handleDocClick);\r\n };\r\n}\r\n"],"names":["setAttributes","el","object","key","classList","add","remove","setAttribute","getFirstElementFromLiAndAddToInput","element","root","value","firstElementChild","getFirstElement","textContent","trim","scrollResultsToTop","resultList","resultWrap","scrollTop","offsetTop","offsetHeight","setAriaActivedescendant","type","followActiveElement","target","outputUl","classGroup","previusElement","previousSibling","previusElementHeight","getAttribute","allLi","document","querySelectorAll","height","slice","call","map","getClassGroupHeight","offsetBottom","createElement","keyCodes","constructor","delay","clearButton","howManyCharacters","selectFirst","insertToInput","showAllValues","cache","disableCloseOnSelect","classPreventClosing","classPrefix","ariaLabelClear","onSearch","onResults","onSubmit","onOpened","onReset","onRender","onClose","noResults","onSelectedItem","_initial","prefix","_clearbutton","this","_root","_resultList","_outputUl","_resultWrap","_prefix","id","tabIndex","role","addClass","insertAdjacentElement","parentNode","insertBefore","nextSibling","addEventListener","_handleInput","_showAll","_onRender","results","_cacheAct","_cache","_cacheData","removeAttribute","_ref2","regex","replace","_regex","_delay","clearTimeout","_timeout","setTimeout","_searchItem","_reset","_id","removeClass","_isActive","_matches","length","_toInput","innerHTML","_index","_selectFirst","_onClose","_value","_onLoading","destroy","showBtnToClearData","_cBtn","_clearButton","_characters","_onSearch","currentValue","then","result","rootValueLength","resultLength","Array","isArray","JSON","parse","stringify","_error","_noResults","template","_results","_events","Object","isObject","catch","_isLoading","_err","_handleKeys","_handleShowItems","eventType","_handleMouse","_handleDocClick","_onResults","matches","_classGroup","checkIfClassGroupExist","_itemsLi","itemsLi","i","tabindex","addAriaToAllLiElements","_onOpened","_selectFirstEl","_ref3","disableClose","closest","_disable","_prevClosing","_remAria","querySelector","_activeList","classSelectFirst","nextElementSibling","_onSelected","index","_selectedOption","contains","event","preventDefault","targetClosest","targetClosestRole","hasAttribute","activeClass","activeClassElement","_getTextFromLi","_setAria","_indexLiSelected","_onSubmit","prototype","indexOf","keyCode","matchesLength","_selectedLi","stopPropagation","selectedOption","class","title","_clearBtnAriLabel","focus","_onReset","removeEventListener","getElementById","Boolean","_ref4","Promise","resolve"],"mappings":"yCAKA,MAkBMA,EAAgB,CAACC,EAAIC,SACpB,IAAIC,KAAOD,EACF,aAARC,EACFF,EAAGG,UAAUC,IAAIH,EAAOC,IACP,gBAARA,EACTF,EAAGG,UAAUE,OAAOJ,EAAOC,IAE3BF,EAAGM,aAAaJ,EAAKD,EAAOC,KAoB5BK,EAAqC,CAACC,EAASC,IAElDA,EAAKC,MAXiBF,CAAAA,GAAYA,EAAQG,mBAAqBH,EAWlDI,CAAgBJ,GAASK,YAAYC,OAO/CC,EAAqB,CAACC,EAAYC,KAGtCD,EAAWE,UAAYF,EAAWG,UAAYF,EAAWG,cAyCrDC,EAA0B,CAACZ,EAAMa,KACrCb,EAAKH,aAAa,wBAAyBgB,GAAQ,KA8B/CC,EAAsB,CAACC,EAAQC,EAAUC,EAAYV,WACnDW,EAAiBX,EAAWY,gBAE5BC,EAAuBF,EAAiBA,EAAeP,aAAe,KAEhC,KAAxCI,EAAOM,aAAa,mBACtBd,EAAWE,UACTM,EAAOL,UA3Be,EAACM,EAAUC,WAE/BK,EAAQC,SAASC,qBACjBR,gBAAsBC,WAExBQ,EAAS,WACVC,MAAMC,KAAKL,GAAOM,IAAKrC,GAAQkC,GAAUlC,EAAGoB,cAGxCc,GAkBgBI,CAAoBb,EAAUC,IAGjDF,EAAOL,UAAYU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,QAEdyD,EAAMyH,aAENxH,EAAYvD,YAAc,QAE1BqF,SAEA6B,SAGA8D,GAAS3H,KAAKC,QAGdA,EAAM2H,oBAAoB,UAAW5H,KAAKuE,QAC1CtE,EAAM2H,oBAAoB,QAAS5H,KAAKwE,GAE7C1G,SAAS8J,oBAAoB,QAAS5H,KAAK2E,UAlqBtC1C,EAAM3F,OACN2D,EAAQnC,SAAS+J,eAAevL,QAChC4G,GFvCU1G,EEuCY4C,EFvCF0I,QAAQtL,GAA+B,mBAAfA,EAAM4G,MEwCnDhE,EACA2I,QAAC5E,aAAEA,EAAF7G,QAAgBA,YACf0L,QAAQC,QAAQ7I,EAAS,CAAE+D,aAAAA,EAAc7G,QAAAA,YAC1CsI,GAAavF,OACb4B,EAAYxB,OACZsH,GAAYzH,OACZ2G,GAAcrG,OACdyF,GAAY9F,OACZoI,GAAWnI,OACXsE,EAAanE,OACb+C,EAAWhD,OAEXiC,EAASlD,OACTwE,EAActE,OACdqE,EAAetE,OACf+D,EAAe7D,OACf0D,EAAWzD,OACXmC,EAAWlC,OACXgG,GAActH,OACdmI,GAAe1G,OACfwI,GAAoBtI,GAErB,8BACCkB,EAAUnB,EAAiBA,UAAqB,YAChDwG,GAAW1G,OAGXoC,EAASrC,OACToB,EAAeH,KAAKK,MAAWL,KAAKiC,kBACpCZ,qBAAgCrB,KAAKiC,OACrCoC,EAAgBrE,KAAKK,qBACrB8B,EAAenC,KAAKK,oBACpByF,GAAiB9F,KAAKK,mBACtB8F,GAAqBnG,KAAKK,0BAC1BiE,EAAUtE,KAAKK,gBACfqB,EAAS,2BACTG,EAAW,UAEXzB,EAAc9B,EAAc,YAC5B4B,EAAc5B,EAAc,WAC5ByE,EAAQzE,EAAc,eAEtBuB"} \ No newline at end of file +{"version":3,"file":"autocomplete.min.js","sources":["../../sources/js/utils/function.js","../../sources/js/utils/keyCodes.js","../../sources/js/script.js"],"sourcesContent":["/**\r\n * Check is a Object\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isObject = (value) =>\r\n value && typeof value === \"object\" && value.constructor === Object;\r\n\r\n/**\r\n * Check if is a Promise\r\n * https://stackoverflow.com/a/53955664/10424385\r\n *\r\n * @param {Object} value\r\n * @returns {Boolean}\r\n */\r\nconst isPromise = (value) => Boolean(value && typeof value.then === \"function\");\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n if (key === \"addClass\") {\r\n classList(el, \"add\", object[key]);\r\n } else if (key === \"removeClass\") {\r\n classList(el, \"remove\", object[key]);\r\n } else {\r\n el.setAttribute(key, object[key]);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Get first element from child\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {HTMLELement}\r\n */\r\nconst getFirstElement = (element) =>\r\n (element.firstElementChild || element).textContent.trim();\r\n\r\n/**\r\n * Scroll to top result-list\r\n * @param {HTMLElement} resultList\r\n * @param {HTMLElement} resultWrap\r\n */\r\nconst scrollResultsToTop = (resultList, resultWrap) => {\r\n // if there is an overflow of ul element, after\r\n // opening we always move ul to the top of the results\r\n resultList.scrollTop = resultList.offsetTop - resultWrap.offsetHeight;\r\n};\r\n\r\n/**\r\n * Adding role, tabindex, aria and call handleMouse\r\n *\r\n * @param {HTMLElement} itemsLi\r\n */\r\nconst addAriaToAllLiElements = (itemsLi) => {\r\n // add role to all li elements\r\n for (let i = 0; i < itemsLi.length; i++) {\r\n setAttributes(itemsLi[i], {\r\n role: \"option\",\r\n tabindex: \"-1\",\r\n \"aria-selected\": \"false\",\r\n \"aria-setsize\": itemsLi.length,\r\n \"aria-posinset\": i,\r\n });\r\n }\r\n};\r\n\r\n/**\r\n * Show btn to clear data\r\n *\r\n * @param {HTMLElement} clearButton - button to clear data\r\n * @param {Function} destroy - destroy function\r\n */\r\nconst showBtnToClearData = (clearButton = false, destroy) => {\r\n if (!clearButton) return;\r\n\r\n classList(clearButton, \"remove\", \"hidden\");\r\n // add event to clear button\r\n onEvent(clearButton, \"click\", destroy);\r\n};\r\n\r\n/**\r\n * ClassList add/remove/contains\r\n *\r\n * @param {HTMLElement} element - html element\r\n * @param {String} action - add/remove/contains\r\n * @param {String} className - class name\r\n */\r\nconst classList = (element, action, className) =>\r\n element.classList[action](className);\r\n\r\n/**\r\n * Set aria-activedescendant\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {String} type\r\n */\r\nconst setAriaActivedescendant = (root, type) => {\r\n setAttributes(root, {\r\n \"aria-activedescendant\": type || \"\",\r\n });\r\n};\r\n\r\n/**\r\n * Get height of ul without group class\r\n *\r\n * @param {String} outputUl\r\n * @param {String} classGroup\r\n * @returns {Number}\r\n */\r\nconst getClassGroupHeight = (outputUl, classGroup) => {\r\n // get height of ul without group class\r\n const allLiElements = document.querySelectorAll(\r\n `#${outputUl} > li:not(.${classGroup})`\r\n );\r\n let height = 0;\r\n [].slice.call(allLiElements).map((el) => (height += el.offsetHeight));\r\n\r\n // return height\r\n return height;\r\n};\r\n\r\n/**\r\n * Scroll into view when press up/down arrows\r\n *\r\n * @param {HTMLElement} target\r\n * @param {HTMLElement} outputUl\r\n * @param {String} classGroup\r\n * @param {HTMLElement} resultList\r\n */\r\nconst followActiveElement = (target, outputUl, classGroup, resultList) => {\r\n const previusElement = resultList.previousSibling;\r\n\r\n const previusElementHeight = previusElement ? previusElement.offsetHeight : 0;\r\n\r\n if (target.getAttribute(\"aria-posinset\") == \"0\") {\r\n resultList.scrollTop =\r\n target.offsetTop - getClassGroupHeight(outputUl, classGroup);\r\n }\r\n\r\n if (target.offsetTop - previusElementHeight < resultList.scrollTop) {\r\n resultList.scrollTop = target.offsetTop - previusElementHeight;\r\n } else {\r\n const offsetBottom =\r\n target.offsetTop + target.offsetHeight - previusElementHeight;\r\n const scrollBottom = resultList.scrollTop + resultList.offsetHeight;\r\n if (offsetBottom > scrollBottom) {\r\n resultList.scrollTop = offsetBottom - resultList.offsetHeight;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Create output-list and put after search input\r\n *\r\n * @param {HTMLElement} root - search input\r\n * @param {HTMLElement} resultList - output-list ul\r\n * @param {String} outputUl - id name of output-list\r\n * @param {HTMLElement} resultWrap - wrapper ul element\r\n * @param {String} prefix - add prefix to all class auto\r\n */\r\nconst output = (root, resultList, outputUl, resultWrap, prefix) => {\r\n // set attribute to results-list\r\n setAttributes(resultList, {\r\n id: outputUl,\r\n tabIndex: \"0\",\r\n role: \"listbox\",\r\n });\r\n\r\n // add class to wrap element\r\n setAttributes(resultWrap, {\r\n addClass: `${prefix}-results-wrapper`,\r\n });\r\n\r\n // insert the results into the wrap element\r\n resultWrap.insertAdjacentElement(\"beforeend\", resultList);\r\n\r\n // insert the wrap element after the search input\r\n root.parentNode.insertBefore(resultWrap, root.nextSibling);\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLDivElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\n/**\r\n * Get element\r\n *\r\n * @param {String} element\r\n * @returns {HTMLElement}\r\n */\r\nconst select = (element) => document.querySelector(element);\r\n\r\n/**\r\n * Event listeners\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} action\r\n * @param {Function} callback\r\n */\r\nconst onEvent = (element, action, callback) => {\r\n element.addEventListener(action, callback);\r\n};\r\n\r\n/**\r\n * Remove event listeners\r\n */\r\nconst offEvent = (element, action, callback) => {\r\n element.removeEventListener(action, callback);\r\n};\r\n\r\nexport {\r\n addAriaToAllLiElements,\r\n classList,\r\n createElement,\r\n followActiveElement,\r\n getFirstElement,\r\n isObject,\r\n isPromise,\r\n offEvent,\r\n onEvent,\r\n output,\r\n scrollResultsToTop,\r\n select,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n};\r\n","/**\r\n * Key codes\r\n */\r\nconst keyCodes = {\r\n ESC: 27,\r\n ENTER: 13,\r\n UP: 38,\r\n DOWN: 40,\r\n TAB: 9,\r\n};\r\n\r\nexport default keyCodes;\r\n","import {\r\n addAriaToAllLiElements,\r\n classList,\r\n createElement,\r\n followActiveElement,\r\n getFirstElement,\r\n isObject,\r\n isPromise,\r\n offEvent,\r\n onEvent,\r\n output,\r\n scrollResultsToTop,\r\n select,\r\n setAriaActivedescendant,\r\n setAttributes,\r\n showBtnToClearData,\r\n} from \"./utils/function\";\r\n\r\nimport keyCodes from \"./utils/keyCodes\";\r\n\r\n/**\r\n * @class Autocomplete\r\n */\r\nexport default class Autocomplete {\r\n /**\r\n * Constructor\r\n *\r\n * @param {String} element\r\n * @param {Object} object\r\n */\r\n constructor(\r\n element,\r\n {\r\n delay = 500,\r\n clearButton = true,\r\n howManyCharacters = 1,\r\n selectFirst = false,\r\n insertToInput = false,\r\n showAllValues = false,\r\n cache = false,\r\n disableCloseOnSelect = false,\r\n classGroup,\r\n classPreventClosing,\r\n classPrefix,\r\n ariaLabelClear,\r\n onSearch,\r\n onResults = () => {},\r\n onSubmit = () => {},\r\n onOpened = () => {},\r\n onReset = () => {},\r\n onRender = () => {},\r\n onClose = () => {},\r\n noResults = () => {},\r\n onSelectedItem = () => {},\r\n }\r\n ) {\r\n this._id = element;\r\n this._root = document.getElementById(element);\r\n this._onSearch = isPromise(onSearch)\r\n ? onSearch\r\n : ({ currentValue, element }) =>\r\n Promise.resolve(onSearch({ currentValue, element }));\r\n this._onResults = onResults;\r\n this._onRender = onRender;\r\n this._onSubmit = onSubmit;\r\n this._onSelected = onSelectedItem;\r\n this._onOpened = onOpened;\r\n this._onReset = onReset;\r\n this._noResults = noResults;\r\n this._onClose = onClose;\r\n\r\n this._delay = delay;\r\n this._characters = howManyCharacters;\r\n this._clearButton = clearButton;\r\n this._selectFirst = selectFirst;\r\n this._toInput = insertToInput;\r\n this._showAll = showAllValues;\r\n this._classGroup = classGroup;\r\n this._prevClosing = classPreventClosing;\r\n this._clearBtnAriLabel = ariaLabelClear\r\n ? ariaLabelClear\r\n : \"clear the search query\";\r\n this._prefix = classPrefix ? `${classPrefix}-auto` : \"auto\";\r\n this._disable = disableCloseOnSelect;\r\n\r\n // default config\r\n this._cache = cache;\r\n this._outputUl = `${this._prefix}-${this._id}-results`;\r\n this._cacheData = `data-cache-auto-${this._id}`;\r\n this._isLoading = `${this._prefix}-is-loading`;\r\n this._isActive = `${this._prefix}-is-active`;\r\n this._activeList = `${this._prefix}-selected`;\r\n this._selectedOption = `${this._prefix}-selected-option`;\r\n this._err = `${this._prefix}-error`;\r\n this._regex = /[|\\\\{}()[\\]^$+*?.]/g;\r\n this._timeout = null;\r\n\r\n this._resultWrap = createElement(\"div\");\r\n this._resultList = createElement(\"ul\");\r\n this._clearBtn = createElement(\"button\");\r\n\r\n this._initial();\r\n }\r\n\r\n /**\r\n * Initial function\r\n */\r\n _initial = () => {\r\n this._clearbutton();\r\n\r\n output(\r\n this._root,\r\n this._resultList,\r\n this._outputUl,\r\n this._resultWrap,\r\n this._prefix\r\n );\r\n\r\n // default aria\r\n onEvent(this._root, \"input\", this._handleInput);\r\n\r\n // show all values on click root input\r\n this._showAll && onEvent(this._root, \"click\", this._handleInput);\r\n\r\n // calback functions\r\n this._onRender({\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n };\r\n\r\n /**\r\n * Actions on input\r\n *\r\n * @param {String} type - set attribute depending on type\r\n * @param {String} target\r\n */\r\n _cacheAct = (type, target) => {\r\n if (!this._cache) return;\r\n\r\n if (type === \"update\") {\r\n this._root.setAttribute(this._cacheData, target.value);\r\n } else if (type === \"remove\") {\r\n this._root.removeAttribute(this._cacheData);\r\n } else {\r\n this._root.value = this._root.getAttribute(this._cacheData);\r\n }\r\n };\r\n\r\n /**\r\n * Handle input\r\n *\r\n * @param {Event} object\r\n */\r\n _handleInput = ({ target, type }) => {\r\n if (\r\n this._root.getAttribute(\"aria-expanded\") === \"true\" &&\r\n type === \"click\"\r\n ) {\r\n return;\r\n }\r\n\r\n // replace all special characters\r\n const regex = target.value.replace(this._regex, \"\\\\$&\");\r\n\r\n // update data attribute cache\r\n this._cacheAct(\"update\", target);\r\n\r\n const delay = this._showAll ? 0 : this._delay;\r\n // clear timeout\r\n clearTimeout(this._timeout);\r\n this._timeout = setTimeout(() => {\r\n this._searchItem(regex.trim());\r\n }, delay);\r\n };\r\n\r\n /**\r\n * Default aria\r\n */\r\n _reset = () => {\r\n // set attributes to root - input\r\n setAttributes(this._root, {\r\n \"aria-owns\": `${this._id}-list`,\r\n \"aria-expanded\": \"false\",\r\n \"aria-autocomplete\": \"list\",\r\n \"aria-activedescendant\": \"\",\r\n role: \"combobox\",\r\n removeClass: \"auto-expanded\",\r\n });\r\n\r\n // remove class isActive\r\n classList(this._resultWrap, \"remove\", this._isActive);\r\n\r\n // set index\r\n this._index = this._selectFirst ? 0 : -1;\r\n\r\n // callback function\r\n this._onClose();\r\n };\r\n\r\n /**\r\n * The async function gets the text from the search\r\n * and returns the matching array\r\n *\r\n * @param {String} value\r\n */\r\n _searchItem = (value) => {\r\n this._value = value;\r\n\r\n // if searching show loading icon\r\n this._onLoading(true);\r\n\r\n // hide button clear\r\n showBtnToClearData(this._clearBtn, this.destroy);\r\n\r\n // if there is no value and clearButton is true\r\n if (value.length == 0 && this._clearButton) {\r\n classList(this._clearBtn, \"add\", \"hidden\");\r\n }\r\n\r\n // if declare characters more then value.len and showAll is false\r\n // remove class isActive\r\n if (this._characters > value.length && !this._showAll) {\r\n this._onLoading();\r\n return;\r\n }\r\n\r\n // callblack function onSearch\r\n this._onSearch({ currentValue: value, element: this._root })\r\n .then((result) => {\r\n const rootValueLength = this._root.value.length;\r\n const resultLength = result.length;\r\n // set no result\r\n this._matches = Array.isArray(result)\r\n ? result\r\n : JSON.parse(JSON.stringify(result));\r\n\r\n this._onLoading();\r\n this._error();\r\n\r\n // if use destroy() method\r\n if (resultLength == 0 && rootValueLength == 0) {\r\n classList(this._clearBtn, \"add\", \"hidden\");\r\n }\r\n\r\n if (resultLength == 0 && rootValueLength) {\r\n classList(this._root, \"remove\", \"auto-expanded\");\r\n this._reset();\r\n this._noResults({\r\n element: this._root,\r\n currentValue: value,\r\n template: this._results,\r\n });\r\n this._events();\r\n } else if (resultLength > 0 || isObject(result)) {\r\n this._index = this._selectFirst ? 0 : -1;\r\n this._results();\r\n this._events();\r\n }\r\n })\r\n .catch(() => {\r\n this._onLoading();\r\n this._reset();\r\n });\r\n };\r\n\r\n /**\r\n * Set or remove loading class\r\n *\r\n * @param {Boolean} type\r\n */\r\n _onLoading = (type) =>\r\n this._root.parentNode.classList[type ? \"add\" : \"remove\"](this._isLoading);\r\n\r\n /**\r\n * Set error class to the root element\r\n */\r\n _error = () => classList(this._root, \"remove\", this._err);\r\n\r\n /**\r\n * Events\r\n */\r\n _events = () => {\r\n // handle click on keydown [up, down, enter, tab, esc]\r\n onEvent(this._root, \"keydown\", this._handleKeys);\r\n\r\n onEvent(this._root, \"click\", this._handleShowItems);\r\n\r\n // temporarily disabled mouseleave\r\n [\"mousemove\", \"click\"].map((eventType) => {\r\n onEvent(this._resultList, eventType, this._handleMouse);\r\n });\r\n\r\n // close expanded items\r\n onEvent(document, \"click\", this._handleDocClick);\r\n };\r\n\r\n /**\r\n * Results\r\n *\r\n * @param {HTMLElement|String} template - html or string returned from the function,\r\n * look at the example - https://github.com/tomik23/autocomplete/blob/master/docs/js/examples/no-results.js#L30\r\n */\r\n _results = (template) => {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // clear result list\r\n this._resultList.textContent = \"\";\r\n\r\n // add all found records to otput ul\r\n const dataResults =\r\n this._matches.length === 0\r\n ? this._onResults({\r\n currentValue: this._value,\r\n matches: 0,\r\n template,\r\n })\r\n : this._onResults({\r\n currentValue: this._value,\r\n matches: this._matches,\r\n classGroup: this._classGroup,\r\n });\r\n\r\n // add data to ul\r\n this._resultList.insertAdjacentHTML(\"afterbegin\", dataResults);\r\n\r\n // add class isActive\r\n classList(this._resultWrap, \"add\", this._isActive);\r\n\r\n const checkIfClassGroupExist = this._classGroup\r\n ? `:not(.${this._classGroup})`\r\n : \"\";\r\n\r\n this._itemsLi = document.querySelectorAll(\r\n `#${this._outputUl} > li${checkIfClassGroupExist}`\r\n );\r\n\r\n // adding role, tabindex and aria\r\n addAriaToAllLiElements(this._itemsLi);\r\n\r\n // action on open results\r\n this._onOpened({\r\n type: \"results\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n\r\n // select first element\r\n this._selectFirstElement();\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n };\r\n\r\n /**\r\n * Hangle click on document\r\n *\r\n * @param {Event} object\r\n */\r\n _handleDocClick = ({ target }) => {\r\n let disableClose = null;\r\n\r\n // if 'target' is a ul and 'disableCloseOnSelect'\r\n // is a 'true' set 'disableClose' on true\r\n if (\r\n (target.closest(\"ul\") && this._disable) ||\r\n // when class classDisableClose\r\n // then do not not close results\r\n target.closest(`.${this._prevClosing}`)\r\n ) {\r\n disableClose = true;\r\n }\r\n\r\n if (target.id !== this._id && !disableClose) {\r\n this._reset();\r\n return;\r\n }\r\n };\r\n\r\n /**\r\n * Select first element\r\n */\r\n _selectFirstElement = () => {\r\n this._removeAria(select(`.${this._activeList}`));\r\n\r\n if (!this._selectFirst) {\r\n return;\r\n }\r\n\r\n const { firstElementChild } = this._resultList;\r\n\r\n const classSelectFirst =\r\n this._classGroup && this._matches.length > 0 && this._selectFirst\r\n ? firstElementChild.nextElementSibling\r\n : firstElementChild;\r\n\r\n // calback function onSelect when first element is true\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set attribute to first element\r\n setAttributes(classSelectFirst, {\r\n id: `${this._selectedOption}-0`,\r\n addClass: this._activeList,\r\n \"aria-selected\": \"true\",\r\n });\r\n\r\n // set aria active descendant\r\n setAriaActivedescendant(this._root, `${this._selectedOption}-0`);\r\n };\r\n\r\n /**\r\n * show items when items.length > 0 and is not empty\r\n */\r\n _handleShowItems = () => {\r\n // if resultWrap is not active and resultList is not empty\r\n if (\r\n this._resultList.textContent.length > 0 &&\r\n !classList(this._resultWrap, \"contains\", this._isActive)\r\n ) {\r\n // set attribute to root\r\n setAttributes(this._root, {\r\n \"aria-expanded\": \"true\",\r\n addClass: `${this._prefix}-expanded`,\r\n });\r\n\r\n // add isActive class to resultWrap\r\n classList(this._resultWrap, \"add\", this._isActive);\r\n\r\n // move the view item to the first item\r\n // this.resultList.scrollTop = 0;\r\n scrollResultsToTop(this._resultList, this._resultWrap);\r\n\r\n // select first element\r\n this._selectFirstElement();\r\n\r\n // callback function\r\n this._onOpened({\r\n type: \"showItems\",\r\n element: this._root,\r\n results: this._resultList,\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Adding text from the list when li is clicking\r\n * or adding aria-selected to li elements\r\n *\r\n * @param {Event} event\r\n */\r\n _handleMouse = (event) => {\r\n event.preventDefault();\r\n\r\n const { target, type } = event;\r\n const targetClosest = target.closest(\"li\");\r\n const targetClosestRole = targetClosest?.hasAttribute(\"role\");\r\n const activeClass = this._activeList;\r\n const activeClassElement = select(`.${activeClass}`);\r\n\r\n if (!targetClosest || !targetClosestRole) {\r\n return;\r\n }\r\n\r\n // click on li get element\r\n if (type === \"click\") {\r\n // get text from clicked li\r\n this._getTextFromLi(targetClosest);\r\n }\r\n\r\n if (\r\n type === \"mousemove\" &&\r\n !classList(targetClosest, \"contains\", activeClass)\r\n ) {\r\n this._removeAria(activeClassElement);\r\n\r\n // add aria to li\r\n this._setAria(targetClosest);\r\n this._index = this._indexLiSelected(targetClosest);\r\n\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Get text from li on enter or click\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _getTextFromLi = (element) => {\r\n if (!element || this._matches.length === 0) {\r\n // set default settings\r\n !this._disable && this._reset();\r\n\r\n return;\r\n }\r\n\r\n // get first element from li and set it to root\r\n this._root.value = getFirstElement(element);\r\n\r\n // onSubmit passing text to function\r\n this._onSubmit({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n results: this._resultList,\r\n });\r\n\r\n // set default settings\r\n if (!this._disable) {\r\n this._removeAria(element);\r\n this._reset();\r\n }\r\n\r\n // show clearBtn when select element\r\n this._clearButton && classList(this._clearBtn, \"remove\", \"hidden\");\r\n\r\n // remove cache\r\n this._cacheAct(\"remove\");\r\n };\r\n\r\n /**\r\n * Return which li element was selected\r\n * by hovering the mouse over\r\n *\r\n * @param {HTMLElement} target\r\n * @returns {Number}\r\n */\r\n _indexLiSelected = (target) =>\r\n // get index of li element\r\n Array.prototype.indexOf.call(this._itemsLi, target);\r\n\r\n /**\r\n * Navigating the elements li and enter\r\n *\r\n * @param {Event} event\r\n */\r\n _handleKeys = (event) => {\r\n const { keyCode } = event;\r\n\r\n const resultList = classList(this._resultWrap, \"contains\", this._isActive);\r\n\r\n const matchesLength = this._matches.length + 1;\r\n this._selectedLi = select(`.${this._activeList}`);\r\n\r\n // switch between keys\r\n switch (keyCode) {\r\n case keyCodes.UP:\r\n case keyCodes.DOWN:\r\n // Wrong cursor position in the input field #62\r\n // Prevents the cursor from moving to the beginning\r\n // of input as the cursor hovers over the results.\r\n event.preventDefault();\r\n\r\n if ((matchesLength <= 1 && this._selectFirst) || !resultList) {\r\n return;\r\n }\r\n\r\n // if keyCode is up\r\n if (keyCode === keyCodes.UP) {\r\n if (this._index < 0) {\r\n this._index = matchesLength - 1;\r\n }\r\n this._index -= 1;\r\n } else {\r\n this._index += 1;\r\n if (this._index >= matchesLength) {\r\n this._index = 0;\r\n }\r\n }\r\n\r\n // remove aria-selected\r\n this._removeAria(this._selectedLi);\r\n\r\n if (this._index >= 0 && this._index < matchesLength - 1) {\r\n if (this._toInput && resultList) {\r\n this._root.value = getFirstElement(this._itemsLi[this._index]);\r\n }\r\n\r\n // callback function\r\n this._onSelected({\r\n index: this._index,\r\n element: this._root,\r\n object: this._matches[this._index],\r\n });\r\n\r\n // set aria-selected\r\n this._setAria(this._itemsLi[this._index]);\r\n } else {\r\n // catch action\r\n this._cacheAct();\r\n setAriaActivedescendant(this._root);\r\n\r\n this._onSelected({\r\n index: null,\r\n element: this._root,\r\n object: null,\r\n });\r\n }\r\n\r\n break;\r\n // keycode enter\r\n case keyCodes.ENTER:\r\n this._getTextFromLi(this._selectedLi);\r\n break;\r\n\r\n // keycode escape and keycode tab\r\n case keyCodes.TAB:\r\n case keyCodes.ESC:\r\n event.stopPropagation(); // #120\r\n this._reset();\r\n\r\n break;\r\n default:\r\n break;\r\n }\r\n };\r\n\r\n /**\r\n * Set aria label on item li\r\n *\r\n * @param {HTMLElement} target\r\n */\r\n _setAria = (target) => {\r\n const selectedOption = `${this._selectedOption}-${this._indexLiSelected(\r\n target\r\n )}`;\r\n\r\n // set aria to li\r\n setAttributes(target, {\r\n id: selectedOption,\r\n \"aria-selected\": \"true\",\r\n addClass: this._activeList,\r\n });\r\n\r\n setAriaActivedescendant(this._root, selectedOption);\r\n\r\n // scrollIntoView when press up/down arrows\r\n followActiveElement(\r\n target,\r\n this._outputUl,\r\n this._classGroup,\r\n this._resultList\r\n );\r\n };\r\n\r\n /**\r\n * Remove aria label from item li\r\n *\r\n * @param {HTMLElement} element\r\n */\r\n _removeAria = (element) => {\r\n if (!element) return;\r\n\r\n // remove aria from li\r\n setAttributes(element, {\r\n id: \"\",\r\n removeClass: this._activeList,\r\n \"aria-selected\": \"false\",\r\n });\r\n };\r\n\r\n /**\r\n * Create clear button and\r\n * removing text from the input field\r\n */\r\n _clearbutton = () => {\r\n // stop when clear button is disabled\r\n if (!this._clearButton) return;\r\n\r\n // add aria to clear button\r\n setAttributes(this._clearBtn, {\r\n class: `${this._prefix}-clear hidden`,\r\n type: \"button\",\r\n title: this._clearBtnAriLabel,\r\n \"aria-label\": this._clearBtnAriLabel,\r\n });\r\n\r\n // insert clear button after input - root\r\n this._root.insertAdjacentElement(\"afterend\", this._clearBtn);\r\n };\r\n\r\n /**\r\n * Clicking on the clear button\r\n * publick destroy method\r\n */\r\n destroy = () => {\r\n // if clear button is true then add class hidden\r\n this._clearButton && classList(this._clearBtn, \"add\", \"hidden\");\r\n // clear value searchId\r\n this._root.value = \"\";\r\n // set focus\r\n this._root.focus();\r\n // remove li from ul\r\n this._resultList.textContent = \"\";\r\n // set default aria\r\n this._reset();\r\n // remove error if exist\r\n this._error();\r\n\r\n // callback function\r\n this._onReset(this._root);\r\n\r\n // remove listener\r\n offEvent(this._root, \"keydown\", this._handleKeys);\r\n offEvent(this._root, \"click\", this._handleShowItems);\r\n // remove listener on click on document\r\n offEvent(document, \"click\", this._handleDocClick);\r\n };\r\n}\r\n"],"names":["setAttributes","el","object","key","classList","setAttribute","getFirstElement","element","firstElementChild","textContent","trim","scrollResultsToTop","resultList","resultWrap","scrollTop","offsetTop","offsetHeight","action","className","setAriaActivedescendant","root","type","followActiveElement","target","outputUl","classGroup","previusElement","previousSibling","previusElementHeight","getAttribute","allLiElements","document","querySelectorAll","height","slice","call","map","getClassGroupHeight","offsetBottom","createElement","select","querySelector","onEvent","callback","addEventListener","offEvent","removeEventListener","keyCodes","constructor","delay","clearButton","howManyCharacters","selectFirst","insertToInput","showAllValues","cache","disableCloseOnSelect","classPreventClosing","classPrefix","ariaLabelClear","onSearch","onResults","onSubmit","onOpened","onReset","onRender","onClose","noResults","onSelectedItem","value","_initial","prefix","_clearbutton","this","_root","_resultList","_outputUl","_resultWrap","_prefix","id","tabIndex","role","addClass","insertAdjacentElement","parentNode","insertBefore","nextSibling","_handleInput","_showAll","_onRender","results","_cacheAct","_cache","_cacheData","removeAttribute","_ref2","regex","replace","_regex","_delay","clearTimeout","_timeout","setTimeout","_searchItem","_reset","_id","removeClass","_isActive","_index","_selectFirst","_onClose","_value","_onLoading","destroy","showBtnToClearData","_clearBtn","length","_clearButton","_characters","_onSearch","currentValue","then","result","rootValueLength","resultLength","_matches","Array","isArray","JSON","parse","stringify","_error","_noResults","template","_results","_events","Object","isObject","catch","_isLoading","_err","_handleKeys","_handleShowItems","eventType","_handleMouse","_handleDocClick","dataResults","_onResults","matches","_classGroup","insertAdjacentHTML","checkIfClassGroupExist","_itemsLi","itemsLi","i","tabindex","addAriaToAllLiElements","_onOpened","_selectFirstElement","_ref3","disableClose","closest","_disable","_prevClosing","_removeAria","_activeList","classSelectFirst","nextElementSibling","_onSelected","index","_selectedOption","event","preventDefault","targetClosest","targetClosestRole","hasAttribute","activeClass","activeClassElement","_getTextFromLi","_setAria","_indexLiSelected","_onSubmit","prototype","indexOf","keyCode","matchesLength","_selectedLi","_toInput","stopPropagation","selectedOption","class","title","_clearBtnAriLabel","focus","_onReset","getElementById","Boolean","_ref4","Promise","resolve"],"mappings":"yCAKA,MAkBMA,EAAgB,CAACC,EAAIC,SACpB,IAAIC,KAAOD,EACF,aAARC,EACFC,EAAUH,EAAI,MAAOC,EAAOC,IACX,gBAARA,EACTC,EAAUH,EAAI,SAAUC,EAAOC,IAE/BF,EAAGI,aAAaF,EAAKD,EAAOC,KAW5BG,EAAmBC,IACtBA,EAAQC,mBAAqBD,GAASE,YAAYC,OAO/CC,EAAqB,CAACC,EAAYC,KAGtCD,EAAWE,UAAYF,EAAWG,UAAYF,EAAWG,cA0CrDZ,EAAY,CAACG,EAASU,EAAQC,IAClCX,EAAQH,UAAUa,GAAQC,GAQtBC,EAA0B,CAACC,EAAMC,KACrCrB,EAAcoB,EAAM,yBACOC,GAAQ,MA+B/BC,EAAsB,CAACC,EAAQC,EAAUC,EAAYb,WACnDc,EAAiBd,EAAWe,gBAE5BC,EAAuBF,EAAiBA,EAAeV,aAAe,KAEhC,KAAxCO,EAAOM,aAAa,mBACtBjB,EAAWE,UACTS,EAAOR,UA3Be,EAACS,EAAUC,WAE/BK,EAAgBC,SAASC,qBACzBR,gBAAsBC,WAExBQ,EAAS,WACVC,MAAMC,KAAKL,GAAeM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,UAEXxB,EAActC,EAAc,YAC5BoC,EAAcpC,EAAc,WAC5B4E,EAAY5E,EAAc,eAE1B+B"} \ No newline at end of file diff --git a/sources/js/script.js b/sources/js/script.js index 3314495..3aab642 100644 --- a/sources/js/script.js +++ b/sources/js/script.js @@ -1,12 +1,16 @@ import { addAriaToAllLiElements, + classList, createElement, followActiveElement, - getFirstElementFromLiAndAddToInput, + getFirstElement, isObject, isPromise, + offEvent, + onEvent, output, scrollResultsToTop, + select, setAriaActivedescendant, setAttributes, showBtnToClearData, @@ -93,7 +97,7 @@ export default class Autocomplete { this._resultWrap = createElement("div"); this._resultList = createElement("ul"); - this._cBtn = createElement("button"); + this._clearBtn = createElement("button"); this._initial(); } @@ -113,11 +117,10 @@ export default class Autocomplete { ); // default aria - // this.reset(); - this._root.addEventListener("input", this._handleInput); + onEvent(this._root, "input", this._handleInput); // show all values on click root input - this._showAll && this._root.addEventListener("click", this._handleInput); + this._showAll && onEvent(this._root, "click", this._handleInput); // calback functions this._onRender({ @@ -186,16 +189,7 @@ export default class Autocomplete { }); // remove class isActive - this._resultWrap.classList.remove(this._isActive); - - // move the view item to the first item - // this.resultList.scrollTop = 0; - // scrollResultsToTop(this.resultList, this.resultWrap); - - // remove result when lengh = 0 and insertToInput is false - if ((this._matches?.length == 0 && !this._toInput) || this._showAll) { - this._resultList.innerHTML = ""; - } + classList(this._resultWrap, "remove", this._isActive); // set index this._index = this._selectFirst ? 0 : -1; @@ -217,11 +211,11 @@ export default class Autocomplete { this._onLoading(true); // hide button clear - showBtnToClearData(this._cBtn, this.destroy); + showBtnToClearData(this._clearBtn, this.destroy); // if there is no value and clearButton is true if (value.length == 0 && this._clearButton) { - this._cBtn.classList.add("hidden"); + classList(this._clearBtn, "add", "hidden"); } // if declare characters more then value.len and showAll is false @@ -238,7 +232,7 @@ export default class Autocomplete { const resultLength = result.length; // set no result this._matches = Array.isArray(result) - ? [...result] + ? result : JSON.parse(JSON.stringify(result)); this._onLoading(); @@ -246,11 +240,11 @@ export default class Autocomplete { // if use destroy() method if (resultLength == 0 && rootValueLength == 0) { - this._cBtn.classList.add("hidden"); + classList(this._clearBtn, "add", "hidden"); } if (resultLength == 0 && rootValueLength) { - this._root.classList.remove("auto-expanded"); + classList(this._root, "remove", "auto-expanded"); this._reset(); this._noResults({ element: this._root, @@ -281,25 +275,24 @@ export default class Autocomplete { /** * Set error class to the root element */ - _error = () => this._root.classList.remove(this._err); + _error = () => classList(this._root, "remove", this._err); /** * Events */ _events = () => { // handle click on keydown [up, down, enter, tab, esc] - this._root.addEventListener("keydown", this._handleKeys); + onEvent(this._root, "keydown", this._handleKeys); - // - this._root.addEventListener("click", this._handleShowItems); + onEvent(this._root, "click", this._handleShowItems); // temporarily disabled mouseleave ["mousemove", "click"].map((eventType) => { - this._resultList.addEventListener(eventType, this._handleMouse); + onEvent(this._resultList, eventType, this._handleMouse); }); // close expanded items - document.addEventListener("click", this._handleDocClick); + onEvent(document, "click", this._handleDocClick); }; /** @@ -315,8 +308,11 @@ export default class Autocomplete { addClass: `${this._prefix}-expanded`, }); + // clear result list + this._resultList.textContent = ""; + // add all found records to otput ul - this._resultList.innerHTML = + const dataResults = this._matches.length === 0 ? this._onResults({ currentValue: this._value, @@ -329,7 +325,11 @@ export default class Autocomplete { classGroup: this._classGroup, }); - this._resultWrap.classList.add(this._isActive); + // add data to ul + this._resultList.insertAdjacentHTML("afterbegin", dataResults); + + // add class isActive + classList(this._resultWrap, "add", this._isActive); const checkIfClassGroupExist = this._classGroup ? `:not(.${this._classGroup})` @@ -350,7 +350,7 @@ export default class Autocomplete { }); // select first element - this._selectFirstEl(); + this._selectFirstElement(); // move the view item to the first item // this.resultList.scrollTop = 0; @@ -385,8 +385,8 @@ export default class Autocomplete { /** * Select first element */ - _selectFirstEl = () => { - this._remAria(document.querySelector(`.${this._activeList}`)); + _selectFirstElement = () => { + this._removeAria(select(`.${this._activeList}`)); if (!this._selectFirst) { return; @@ -424,7 +424,7 @@ export default class Autocomplete { // if resultWrap is not active and resultList is not empty if ( this._resultList.textContent.length > 0 && - !this._resultWrap.classList.contains(this._isActive) + !classList(this._resultWrap, "contains", this._isActive) ) { // set attribute to root setAttributes(this._root, { @@ -433,14 +433,14 @@ export default class Autocomplete { }); // add isActive class to resultWrap - this._resultWrap.classList.add(this._isActive); + classList(this._resultWrap, "add", this._isActive); // move the view item to the first item // this.resultList.scrollTop = 0; scrollResultsToTop(this._resultList, this._resultWrap); // select first element - this._selectFirstEl(); + this._selectFirstElement(); // callback function this._onOpened({ @@ -464,7 +464,7 @@ export default class Autocomplete { const targetClosest = target.closest("li"); const targetClosestRole = targetClosest?.hasAttribute("role"); const activeClass = this._activeList; - const activeClassElement = document.querySelector(`.${activeClass}`); + const activeClassElement = select(`.${activeClass}`); if (!targetClosest || !targetClosestRole) { return; @@ -478,9 +478,9 @@ export default class Autocomplete { if ( type === "mousemove" && - !targetClosest.classList.contains(activeClass) + !classList(targetClosest, "contains", activeClass) ) { - this._remAria(activeClassElement); + this._removeAria(activeClassElement); // add aria to li this._setAria(targetClosest); @@ -508,7 +508,7 @@ export default class Autocomplete { } // get first element from li and set it to root - getFirstElementFromLiAndAddToInput(element, this._root); + this._root.value = getFirstElement(element); // onSubmit passing text to function this._onSubmit({ @@ -520,12 +520,12 @@ export default class Autocomplete { // set default settings if (!this._disable) { - this._remAria(element); + this._removeAria(element); this._reset(); } // show clearBtn when select element - this._clearButton && this._cBtn.classList.remove("hidden"); + this._clearButton && classList(this._clearBtn, "remove", "hidden"); // remove cache this._cacheAct("remove"); @@ -550,10 +550,10 @@ export default class Autocomplete { _handleKeys = (event) => { const { keyCode } = event; - const resultList = this._resultWrap.classList.contains(this._isActive); + const resultList = classList(this._resultWrap, "contains", this._isActive); const matchesLength = this._matches.length + 1; - this._selectedLi = document.querySelector(`.${this._activeList}`); + this._selectedLi = select(`.${this._activeList}`); // switch between keys switch (keyCode) { @@ -582,18 +582,11 @@ export default class Autocomplete { } // remove aria-selected - this._remAria(this._selectedLi); + this._removeAria(this._selectedLi); - if ( - matchesLength > 0 && - this._index >= 0 && - this._index < matchesLength - 1 - ) { + if (this._index >= 0 && this._index < matchesLength - 1) { if (this._toInput && resultList) { - getFirstElementFromLiAndAddToInput( - this._itemsLi[this._index], - this._root - ); + this._root.value = getFirstElement(this._itemsLi[this._index]); } // callback function @@ -668,7 +661,7 @@ export default class Autocomplete { * * @param {HTMLElement} element */ - _remAria = (element) => { + _removeAria = (element) => { if (!element) return; // remove aria from li @@ -688,7 +681,7 @@ export default class Autocomplete { if (!this._clearButton) return; // add aria to clear button - setAttributes(this._cBtn, { + setAttributes(this._clearBtn, { class: `${this._prefix}-clear hidden`, type: "button", title: this._clearBtnAriLabel, @@ -696,7 +689,7 @@ export default class Autocomplete { }); // insert clear button after input - root - this._root.insertAdjacentElement("afterend", this._cBtn); + this._root.insertAdjacentElement("afterend", this._clearBtn); }; /** @@ -705,7 +698,7 @@ export default class Autocomplete { */ destroy = () => { // if clear button is true then add class hidden - this._clearButton && this._cBtn.classList.add("hidden"); + this._clearButton && classList(this._clearBtn, "add", "hidden"); // clear value searchId this._root.value = ""; // set focus @@ -721,9 +714,9 @@ export default class Autocomplete { this._onReset(this._root); // remove listener - this._root.removeEventListener("keydown", this._handleKeys); - this._root.removeEventListener("click", this._handleShowItems); + offEvent(this._root, "keydown", this._handleKeys); + offEvent(this._root, "click", this._handleShowItems); // remove listener on click on document - document.removeEventListener("click", this._handleDocClick); + offEvent(document, "click", this._handleDocClick); }; } diff --git a/sources/js/utils/function.js b/sources/js/utils/function.js index fc80a41..c16008c 100644 --- a/sources/js/utils/function.js +++ b/sources/js/utils/function.js @@ -24,9 +24,9 @@ const isPromise = (value) => Boolean(value && typeof value.then === "function"); const setAttributes = (el, object) => { for (let key in object) { if (key === "addClass") { - el.classList.add(object[key]); + classList(el, "add", object[key]); } else if (key === "removeClass") { - el.classList.remove(object[key]); + classList(el, "remove", object[key]); } else { el.setAttribute(key, object[key]); } @@ -39,18 +39,8 @@ const setAttributes = (el, object) => { * @param {HTMLElement} element * @returns {HTMLELement} */ -const getFirstElement = (element) => element.firstElementChild || element; - -/** - * Set data from li to input - * - * @param {String} element - * @param {HTMLElement} root - * @returns {String} - */ -const getFirstElementFromLiAndAddToInput = (element, root) => - // get first element from li and add to input - (root.value = getFirstElement(element).textContent.trim()); +const getFirstElement = (element) => + (element.firstElementChild || element).textContent.trim(); /** * Scroll to top result-list @@ -90,11 +80,21 @@ const addAriaToAllLiElements = (itemsLi) => { const showBtnToClearData = (clearButton = false, destroy) => { if (!clearButton) return; - clearButton.classList.remove("hidden"); + classList(clearButton, "remove", "hidden"); // add event to clear button - clearButton.addEventListener("click", destroy); + onEvent(clearButton, "click", destroy); }; +/** + * ClassList add/remove/contains + * + * @param {HTMLElement} element - html element + * @param {String} action - add/remove/contains + * @param {String} className - class name + */ +const classList = (element, action, className) => + element.classList[action](className); + /** * Set aria-activedescendant * @@ -102,7 +102,9 @@ const showBtnToClearData = (clearButton = false, destroy) => { * @param {String} type */ const setAriaActivedescendant = (root, type) => { - root.setAttribute("aria-activedescendant", type || ""); + setAttributes(root, { + "aria-activedescendant": type || "", + }); }; /** @@ -114,11 +116,11 @@ const setAriaActivedescendant = (root, type) => { */ const getClassGroupHeight = (outputUl, classGroup) => { // get height of ul without group class - const allLi = document.querySelectorAll( + const allLiElements = document.querySelectorAll( `#${outputUl} > li:not(.${classGroup})` ); let height = 0; - [].slice.call(allLi).map((el) => (height += el.offsetHeight)); + [].slice.call(allLiElements).map((el) => (height += el.offsetHeight)); // return height return height; @@ -191,15 +193,45 @@ const output = (root, resultList, outputUl, resultWrap, prefix) => { */ const createElement = (type) => document.createElement(type); +/** + * Get element + * + * @param {String} element + * @returns {HTMLElement} + */ +const select = (element) => document.querySelector(element); + +/** + * Event listeners + * + * @param {HTMLElement} element + * @param {String} action + * @param {Function} callback + */ +const onEvent = (element, action, callback) => { + element.addEventListener(action, callback); +}; + +/** + * Remove event listeners + */ +const offEvent = (element, action, callback) => { + element.removeEventListener(action, callback); +}; + export { addAriaToAllLiElements, + classList, createElement, followActiveElement, - getFirstElementFromLiAndAddToInput, + getFirstElement, isObject, isPromise, + offEvent, + onEvent, output, scrollResultsToTop, + select, setAriaActivedescendant, setAttributes, showBtnToClearData,