@tarekraafat/autocomplete.js
Advanced tools
Comparing version 9.0.5 to 9.1.0
@@ -7,2 +7,40 @@ (function (global, factory) { | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -45,36 +83,2 @@ if (!(instance instanceof Constructor)) { | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -154,3 +158,3 @@ if (!o) return; | ||
var inputComponent = (function (config) { | ||
var prepareInputField = (function (config) { | ||
config.inputField.setAttribute("role", "combobox"); | ||
@@ -163,2 +167,22 @@ config.inputField.setAttribute("aria-haspopup", true); | ||
var eventEmitter = (function (target, detail, name) { | ||
target.dispatchEvent(new CustomEvent(name, { | ||
bubbles: true, | ||
detail: detail, | ||
cancelable: true | ||
})); | ||
}); | ||
var ariaActive$2 = "aria-activedescendant"; | ||
var ariaExpanded$1 = "aria-expanded"; | ||
var closeList = function closeList(config, target) { | ||
var list = document.getElementById(config.resultsList.idName); | ||
if (list && target !== config.inputField) { | ||
list.remove(); | ||
config.inputField.removeAttribute(ariaActive$2); | ||
config.inputField.setAttribute(ariaExpanded$1, false); | ||
eventEmitter(config.inputField, null, "close"); | ||
} | ||
}; | ||
var createList = (function (config) { | ||
@@ -184,83 +208,28 @@ var list = document.createElement(config.resultsList.element); | ||
var eventEmitter = (function (target, detail, name) { | ||
target.dispatchEvent(new CustomEvent(name, { | ||
bubbles: true, | ||
detail: detail, | ||
cancelable: true | ||
})); | ||
}); | ||
var closeList = function closeList(config, target) { | ||
var list = document.getElementById(config.resultsList.idName); | ||
if (list && target !== config.inputField) { | ||
list.remove(); | ||
config.inputField.removeAttribute("aria-activedescendant"); | ||
config.inputField.setAttribute("aria-expanded", false); | ||
eventEmitter(config.inputField, null, "close"); | ||
} | ||
}; | ||
var generateList = function generateList(config, data, matches) { | ||
var list = document.getElementById(config.resultsList.idName); | ||
if (list) { | ||
list.innerHTML = ""; | ||
} else { | ||
list = createList(config); | ||
} | ||
config.inputField.setAttribute("aria-expanded", true); | ||
if (matches.length) { | ||
var _loop = function _loop(index) { | ||
var item = data.results[index]; | ||
var resultItem = createItem(item, index, config); | ||
resultItem.addEventListener("click", function (event) { | ||
var dataFeedback = { | ||
event: event, | ||
matches: matches, | ||
input: data.input, | ||
query: data.query, | ||
results: data.results, | ||
selection: _objectSpread2(_objectSpread2({}, item), {}, { | ||
index: index | ||
}) | ||
}; | ||
if (config.onSelection) config.onSelection(dataFeedback); | ||
}); | ||
list.appendChild(resultItem); | ||
}; | ||
for (var index = 0; index < data.results.length; index++) { | ||
_loop(index); | ||
} | ||
} else { | ||
if (!config.resultsList.noResults) { | ||
list.remove(); | ||
} else { | ||
config.resultsList.noResults(list, data.query); | ||
} | ||
} | ||
if (config.resultsList.container) config.resultsList.container(list); | ||
document.addEventListener("click", function (event) { | ||
return closeList(config, event.target); | ||
}); | ||
}; | ||
var keyboardEvent = "keydown"; | ||
var navigate = function navigate(config, dataFeedback) { | ||
var currentFocus = -1; | ||
var ariaSelected = "aria-selected"; | ||
var ariaActive$1 = "aria-activedescendant"; | ||
var navigation = (function (config, dataFeedback) { | ||
config.inputField.removeEventListener(keyboardEvent, config.nav); | ||
var cursor = -1; | ||
var update = function update(event, list, state) { | ||
event.preventDefault(); | ||
if (state) { | ||
currentFocus++; | ||
} else { | ||
currentFocus--; | ||
if (list.length) { | ||
if (state) { | ||
cursor++; | ||
} else { | ||
cursor--; | ||
} | ||
addActive(list); | ||
config.inputField.setAttribute(ariaActive$1, list[cursor].id); | ||
eventEmitter(event.srcElement, _objectSpread2(_objectSpread2({ | ||
event: event | ||
}, dataFeedback), {}, { | ||
selection: dataFeedback.results[cursor] | ||
}), "navigate"); | ||
} | ||
addActive(list); | ||
config.inputField.setAttribute("aria-activedescendant", list[currentFocus].id); | ||
eventEmitter(event.srcElement, _objectSpread2(_objectSpread2({ | ||
event: event | ||
}, dataFeedback), {}, { | ||
selection: dataFeedback.results[currentFocus] | ||
}), "navigate"); | ||
}; | ||
var removeActive = function removeActive(list) { | ||
for (var index = 0; index < list.length; index++) { | ||
list[index].removeAttribute("aria-selected"); | ||
list[index].removeAttribute(ariaSelected); | ||
if (config.resultItem.selected.className) list[index].classList.remove(config.resultItem.selected.className); | ||
@@ -270,21 +239,18 @@ } | ||
var addActive = function addActive(list) { | ||
if (!list) return false; | ||
removeActive(list); | ||
if (currentFocus >= list.length) currentFocus = 0; | ||
if (currentFocus < 0) currentFocus = list.length - 1; | ||
list[currentFocus].setAttribute("aria-selected", "true"); | ||
if (config.resultItem.selected.className) list[currentFocus].classList.add(config.resultItem.selected.className); | ||
if (cursor >= list.length) cursor = 0; | ||
if (cursor < 0) cursor = list.length - 1; | ||
list[cursor].setAttribute(ariaSelected, true); | ||
if (config.resultItem.selected.className) list[cursor].classList.add(config.resultItem.selected.className); | ||
}; | ||
var navigation = function navigation(event) { | ||
config.nav = function (event) { | ||
var list = document.getElementById(config.resultsList.idName); | ||
if (!list) { | ||
config.inputField.removeEventListener(keyboardEvent, navigate); | ||
} else { | ||
if (list) { | ||
list = list.getElementsByTagName(config.resultItem.element); | ||
switch (event.keyCode) { | ||
case 40: | ||
update(event, list, true); | ||
update(event, list, 1); | ||
break; | ||
case 38: | ||
update(event, list, false); | ||
update(event, list); | ||
break; | ||
@@ -297,4 +263,5 @@ case 27: | ||
event.preventDefault(); | ||
list[currentFocus].click(); | ||
closeList(config); | ||
if (cursor >= 0) { | ||
list[cursor].click(); | ||
} | ||
break; | ||
@@ -307,8 +274,62 @@ case 9: | ||
}; | ||
var navigate = config.resultsList.navigation || navigation; | ||
if (config.inputField.autoCompleteNavigate) config.inputField.removeEventListener(keyboardEvent, config.inputField.autoCompleteNavigate); | ||
config.inputField.autoCompleteNavigate = navigate; | ||
config.inputField.addEventListener(keyboardEvent, navigate); | ||
config.inputField.addEventListener(keyboardEvent, config.nav); | ||
}); | ||
var clickEvent = "click"; | ||
var ariaExpanded = "aria-expanded"; | ||
var ariaActive = "aria-activedescendant"; | ||
var resultsList = (function (config, data) { | ||
data.input; | ||
var query = data.query, | ||
matches = data.matches, | ||
results = data.results; | ||
var list = document.getElementById(config.resultsList.idName); | ||
if (list) { | ||
list.innerHTML = ""; | ||
config.inputField.removeAttribute(ariaActive); | ||
} else { | ||
list = createList(config); | ||
config.inputField.setAttribute(ariaExpanded, true); | ||
eventEmitter(config.inputField, data, "open"); | ||
} | ||
if (matches.length) { | ||
results.forEach(function (item, index) { | ||
var resultItem = createItem(item, index, config); | ||
resultItem.addEventListener(clickEvent, function (event) { | ||
var dataFeedback = _objectSpread2(_objectSpread2({ | ||
event: event | ||
}, data), {}, { | ||
selection: _objectSpread2(_objectSpread2({}, item), {}, { | ||
index: index | ||
}) | ||
}); | ||
if (config.onSelection) config.onSelection(dataFeedback); | ||
}); | ||
list.appendChild(resultItem); | ||
}); | ||
} else { | ||
if (!config.resultsList.noResults) { | ||
closeList(config); | ||
config.inputField.setAttribute(ariaExpanded, false); | ||
} else { | ||
config.resultsList.noResults(list, query); | ||
} | ||
} | ||
if (config.resultsList.container) config.resultsList.container(list, data); | ||
config.resultsList.navigation ? config.resultsList.navigation(list) : navigation(config, data); | ||
document.addEventListener(clickEvent, function (event) { | ||
return closeList(config, event.target); | ||
}); | ||
}); | ||
var getInputValue = function getInputValue(inputField) { | ||
return inputField instanceof HTMLInputElement || inputField instanceof HTMLTextAreaElement ? inputField.value.toLowerCase() : inputField.innerHTML.toLowerCase(); | ||
}; | ||
var prepareQueryValue = function prepareQueryValue(inputValue, config) { | ||
return config.query && config.query.manipulate ? config.query.manipulate(inputValue) : config.diacritics ? inputValue.normalize("NFD").replace(/[\u0300-\u036f]/g, "").normalize("NFC") : inputValue; | ||
}; | ||
var item = function item(className, value) { | ||
return "<span class=\"".concat(className, "\">").concat(value, "</span>"); | ||
}; | ||
var searchEngine = (function (query, record, config) { | ||
@@ -323,3 +344,3 @@ var recordLowerCase = config.diacritics ? record.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").normalize("NFC") : record.toLowerCase(); | ||
if (searchPosition < query.length && recordLowerCase[number] === query[searchPosition]) { | ||
recordChar = config.resultItem.highlight.render ? "<span class=\"".concat(config.resultItem.highlight.className, "\">").concat(recordChar, "</span>") : recordChar; | ||
recordChar = config.resultItem.highlight.render ? item(config.resultItem.highlight.className, recordChar) : recordChar; | ||
searchPosition++; | ||
@@ -336,3 +357,3 @@ } | ||
query = pattern.exec(record); | ||
var _match = config.resultItem.highlight.render ? record.replace(query, "<span class=\"".concat(config.resultItem.highlight.className, "\">").concat(query, "</span>")) : record; | ||
var _match = config.resultItem.highlight.render ? record.replace(query, item(config.resultItem.highlight.className, query)) : record; | ||
return _match; | ||
@@ -343,21 +364,13 @@ } | ||
var getInputValue = function getInputValue(inputField) { | ||
return inputField instanceof HTMLInputElement || inputField instanceof HTMLTextAreaElement ? inputField.value.toLowerCase() : inputField.innerHTML.toLowerCase(); | ||
}; | ||
var prepareQueryValue = function prepareQueryValue(inputValue, config) { | ||
return config.query && config.query.manipulate ? config.query.manipulate(inputValue) : config.diacritics ? inputValue.normalize("NFD").replace(/[\u0300-\u036f]/g, "").normalize("NFC") : inputValue; | ||
}; | ||
var checkTriggerCondition = function checkTriggerCondition(config, event, queryValue) { | ||
return config.trigger.condition ? config.trigger.condition(event, queryValue) : queryValue.length >= config.threshold && queryValue.replace(/ /g, "").length; | ||
}; | ||
var listMatchingResults = function listMatchingResults(config, query) { | ||
var resList = []; | ||
var _loop = function _loop(index) { | ||
var record = config.data.store[index]; | ||
var findMatches = (function (config, query) { | ||
var data = config.data, | ||
customSearchEngine = config.searchEngine; | ||
var results = []; | ||
data.store.forEach(function (record, index) { | ||
var search = function search(key) { | ||
var recordValue = (key ? record[key] : record).toString(); | ||
if (recordValue) { | ||
var match = typeof config.searchEngine === "function" ? config.searchEngine(query, recordValue) : searchEngine(query, recordValue, config); | ||
var match = typeof customSearchEngine === "function" ? customSearchEngine(query, recordValue) : searchEngine(query, recordValue, config); | ||
if (match && key) { | ||
resList.push({ | ||
results.push({ | ||
key: key, | ||
@@ -369,3 +382,3 @@ index: index, | ||
} else if (match && !key) { | ||
resList.push({ | ||
results.push({ | ||
index: index, | ||
@@ -378,4 +391,4 @@ match: match, | ||
}; | ||
if (config.data.key) { | ||
var _iterator = _createForOfIteratorHelper(config.data.key), | ||
if (data.key) { | ||
var _iterator = _createForOfIteratorHelper(data.key), | ||
_step; | ||
@@ -395,9 +408,10 @@ try { | ||
} | ||
}; | ||
for (var index = 0; index < config.data.store.length; index++) { | ||
_loop(index); | ||
} | ||
return resList; | ||
}; | ||
}); | ||
return results; | ||
}); | ||
var checkTriggerCondition = (function (config, event, queryValue) { | ||
return config.trigger.condition ? config.trigger.condition(event, queryValue) : queryValue.length >= config.threshold && queryValue.replace(/ /g, "").length; | ||
}); | ||
var debouncer = (function (callback, delay) { | ||
@@ -421,9 +435,7 @@ var inDebounce; | ||
placeHolder = config.placeHolder, | ||
_config$observer = config.observer, | ||
observer = _config$observer === void 0 ? false : _config$observer, | ||
observer = config.observer, | ||
_config$data = config.data, | ||
src = _config$data.src, | ||
key = _config$data.key, | ||
_config$data$cache = _config$data.cache, | ||
cache = _config$data$cache === void 0 ? false : _config$data$cache, | ||
cache = _config$data.cache, | ||
store = _config$data.store, | ||
@@ -436,4 +448,3 @@ results = _config$data.results, | ||
event = _config$trigger$event === void 0 ? ["input"] : _config$trigger$event, | ||
_config$trigger$condi = _config$trigger.condition, | ||
condition = _config$trigger$condi === void 0 ? false : _config$trigger$condi, | ||
condition = _config$trigger.condition, | ||
_config$threshold = config.threshold, | ||
@@ -443,6 +454,4 @@ threshold = _config$threshold === void 0 ? 1 : _config$threshold, | ||
debounce = _config$debounce === void 0 ? 0 : _config$debounce, | ||
_config$diacritics = config.diacritics, | ||
diacritics = _config$diacritics === void 0 ? false : _config$diacritics, | ||
_config$searchEngine = config.searchEngine, | ||
searchEngine = _config$searchEngine === void 0 ? "strict" : _config$searchEngine, | ||
diacritics = config.diacritics, | ||
searchEngine = config.searchEngine, | ||
feedback = config.feedback, | ||
@@ -453,5 +462,5 @@ _config$resultsList = config.resultsList; | ||
resultsListRender = _config$resultsList$r === void 0 ? true : _config$resultsList$r, | ||
_config$resultsList$c = _config$resultsList.container, | ||
container = _config$resultsList$c === void 0 ? false : _config$resultsList$c, | ||
destination = _config$resultsList.destination, | ||
container = _config$resultsList.container, | ||
_config$resultsList$d = _config$resultsList.destination, | ||
destination = _config$resultsList$d === void 0 ? selector : _config$resultsList$d, | ||
_config$resultsList$p = _config$resultsList.position, | ||
@@ -463,13 +472,10 @@ position = _config$resultsList$p === void 0 ? "afterend" : _config$resultsList$p, | ||
resultsListId = _config$resultsList$i === void 0 ? "autoComplete_list" : _config$resultsList$i, | ||
_config$resultsList$c2 = _config$resultsList.className, | ||
resultsListClass = _config$resultsList$c2 === void 0 ? "autoComplete_list" : _config$resultsList$c2, | ||
resultsListClass = _config$resultsList.className, | ||
_config$resultsList$m = _config$resultsList.maxResults, | ||
maxResults = _config$resultsList$m === void 0 ? 5 : _config$resultsList$m, | ||
_config$resultsList$n = _config$resultsList.navigation, | ||
navigation = _config$resultsList$n === void 0 ? false : _config$resultsList$n, | ||
navigation = _config$resultsList.navigation, | ||
noResults = _config$resultsList.noResults, | ||
_config$resultItem = config.resultItem; | ||
_config$resultItem = _config$resultItem === void 0 ? {} : _config$resultItem; | ||
var _config$resultItem$co = _config$resultItem.content, | ||
content = _config$resultItem$co === void 0 ? false : _config$resultItem$co, | ||
var content = _config$resultItem.content, | ||
_config$resultItem$el = _config$resultItem.element, | ||
@@ -482,6 +488,5 @@ resultItemElement = _config$resultItem$el === void 0 ? "li" : _config$resultItem$el, | ||
_config$resultItem$hi = _config$resultItem$hi === void 0 ? {} : _config$resultItem$hi; | ||
var _config$resultItem$hi2 = _config$resultItem$hi.render, | ||
highlightRender = _config$resultItem$hi2 === void 0 ? false : _config$resultItem$hi2, | ||
_config$resultItem$hi3 = _config$resultItem$hi.className, | ||
highlightClass = _config$resultItem$hi3 === void 0 ? "autoComplete_highlighted" : _config$resultItem$hi3, | ||
var highlightRender = _config$resultItem$hi.render, | ||
_config$resultItem$hi2 = _config$resultItem$hi.className, | ||
highlightClass = _config$resultItem$hi2 === void 0 ? "autoComplete_highlighted" : _config$resultItem$hi2, | ||
_config$resultItem$se = _config$resultItem.selected; | ||
@@ -515,3 +520,3 @@ _config$resultItem$se = _config$resultItem$se === void 0 ? {} : _config$resultItem$se; | ||
container: container, | ||
destination: destination || this.selector, | ||
destination: destination, | ||
position: position, | ||
@@ -545,3 +550,3 @@ element: resultsListElement, | ||
value: function start(input, query) { | ||
var results = this.data.results ? this.data.results(listMatchingResults(this, query)) : listMatchingResults(this, query); | ||
var results = this.data.results ? this.data.results(findMatches(this, query)) : findMatches(this, query); | ||
var dataFeedback = { | ||
@@ -555,5 +560,3 @@ input: input, | ||
if (!this.resultsList.render) return this.feedback(dataFeedback); | ||
generateList(this, dataFeedback, results); | ||
navigate(this, dataFeedback); | ||
eventEmitter(this.inputField, dataFeedback, "open"); | ||
resultsList(this, dataFeedback); | ||
} | ||
@@ -613,3 +616,3 @@ }, { | ||
var _this3 = this; | ||
inputComponent(this); | ||
prepareInputField(this); | ||
if (this.placeHolder) this.inputField.setAttribute("placeholder", this.placeHolder); | ||
@@ -620,3 +623,2 @@ this.hook = debouncer(function (event) { | ||
this.trigger.event.forEach(function (eventType) { | ||
_this3.inputField.removeEventListener(eventType, _this3.hook); | ||
_this3.inputField.addEventListener(eventType, _this3.hook); | ||
@@ -634,18 +636,9 @@ }); | ||
}; | ||
var callback = function callback(mutationsList, observer) { | ||
var _iterator = _createForOfIteratorHelper(mutationsList), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var mutation = _step.value; | ||
if (_this4.inputField) { | ||
observer.disconnect(); | ||
_this4.init(); | ||
} | ||
var callback = function callback(mutations, observer) { | ||
mutations.forEach(function (mutation) { | ||
if (_this4.inputField) { | ||
observer.disconnect(); | ||
_this4.init(); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
}); | ||
}; | ||
@@ -658,3 +651,6 @@ var observer = new MutationObserver(callback); | ||
value: function unInit() { | ||
this.inputField.removeEventListener("input", this.hook); | ||
var _this5 = this; | ||
this.trigger.event.forEach(function (eventType) { | ||
_this5.inputField.removeEventListener(eventType, _this5.hook); | ||
}); | ||
eventEmitter(this.inputField, null, "unInit"); | ||
@@ -661,0 +657,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var e,t;e=this,t=function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function i(e){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?n(Object(r),!0).forEach((function(n){t(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function s(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw o}}}}var o=function(e,t,n){e.dispatchEvent(new CustomEvent(n,{bubbles:!0,detail:t,cancelable:!0}))},a=function(e,t){var n=document.getElementById(e.resultsList.idName);n&&t!==e.inputField&&(n.remove(),e.inputField.removeAttribute("aria-activedescendant"),e.inputField.setAttribute("aria-expanded",!1),o(e.inputField,null,"close"))},l=function(e,t,n){var r=document.getElementById(e.resultsList.idName);if(r?r.innerHTML="":r=function(e){var t=document.createElement(e.resultsList.element);return t.setAttribute("id",e.resultsList.idName),t.setAttribute("class",e.resultsList.className),t.setAttribute("role","listbox"),("string"==typeof e.resultsList.destination?document.querySelector(e.resultsList.destination):e.resultsList.destination()).insertAdjacentElement(e.resultsList.position,t),t}(e),e.inputField.setAttribute("aria-expanded",!0),n.length)for(var s=function(s){var o=t.results[s],a=function(e,t,n){var i=document.createElement(n.resultItem.element);return i.setAttribute("id","".concat(n.resultItem.idName,"_").concat(t)),i.setAttribute("class",n.resultItem.className),i.setAttribute("role","option"),i.innerHTML=e.match,n.resultItem.content&&n.resultItem.content(e,i),i}(o,s,e);a.addEventListener("click",(function(r){var a={event:r,matches:n,input:t.input,query:t.query,results:t.results,selection:i(i({},o),{},{index:s})};e.onSelection&&e.onSelection(a)})),r.appendChild(a)},o=0;o<t.results.length;o++)s(o);else e.resultsList.noResults?e.resultsList.noResults(r,t.query):r.remove();e.resultsList.container&&e.resultsList.container(r),document.addEventListener("click",(function(t){return a(e,t.target)}))},u="keydown",c=function(e,t){var n=-1,r=function(r,a,l){r.preventDefault(),l?n++:n--,s(a),e.inputField.setAttribute("aria-activedescendant",a[n].id),o(r.srcElement,i(i({event:r},t),{},{selection:t.results[n]}),"navigate")},s=function(t){if(!t)return!1;!function(t){for(var n=0;n<t.length;n++)t[n].removeAttribute("aria-selected"),e.resultItem.selected.className&&t[n].classList.remove(e.resultItem.selected.className)}(t),n>=t.length&&(n=0),n<0&&(n=t.length-1),t[n].setAttribute("aria-selected","true"),e.resultItem.selected.className&&t[n].classList.add(e.resultItem.selected.className)},l=e.resultsList.navigation||function(t){var i=document.getElementById(e.resultsList.idName);if(i)switch(i=i.getElementsByTagName(e.resultItem.element),t.keyCode){case 40:r(t,i,!0);break;case 38:r(t,i,!1);break;case 27:e.inputField.value="",a(e);break;case 13:t.preventDefault(),i[n].click(),a(e);break;case 9:a(e)}else e.inputField.removeEventListener(u,l)};e.inputField.autoCompleteNavigate&&e.inputField.removeEventListener(u,e.inputField.autoCompleteNavigate),e.inputField.autoCompleteNavigate=l,e.inputField.addEventListener(u,l)},d=function(e,t){for(var n=[],i=function(i){var r=e.data.store[i],o=function(s){var o=(s?r[s]:r).toString();if(o){var a="function"==typeof e.searchEngine?e.searchEngine(t,o):function(e,t,n){var i=n.diacritics?t.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):t.toLowerCase();if("loose"===n.searchEngine){e=e.replace(/ /g,"");for(var r=[],s=0,o=0;o<i.length;o++){var a=t[o];s<e.length&&i[o]===e[s]&&(a=n.resultItem.highlight.render?'<span class="'.concat(n.resultItem.highlight.className,'">').concat(a,"</span>"):a,s++),r.push(a)}if(s===e.length)return r.join("")}else if(i.includes(e)){var l=new RegExp(e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i");return e=l.exec(t),n.resultItem.highlight.render?t.replace(e,'<span class="'.concat(n.resultItem.highlight.className,'">').concat(e,"</span>")):t}}(t,o,e);a&&s?n.push({key:s,index:i,match:a,value:r}):a&&!s&&n.push({index:i,match:a,value:r})}};if(e.data.key){var a,l=s(e.data.key);try{for(l.s();!(a=l.n()).done;)o(a.value)}catch(e){l.e(e)}finally{l.f()}}else o()},r=0;r<e.data.store.length;r++)i(r);return n};return function(){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=e.selector,i=void 0===n?"#autoComplete":n,r=e.placeHolder,s=e.observer,o=void 0!==s&&s,a=e.data,l=a.src,u=a.key,c=a.cache,d=void 0!==c&&c,h=a.store,f=a.results,m=e.query,p=e.trigger,v=(p=void 0===p?{}:p).event,g=void 0===v?["input"]:v,b=p.condition,y=void 0!==b&&b,L=e.threshold,F=void 0===L?1:L,N=e.debounce,E=void 0===N?0:N,k=e.diacritics,w=void 0!==k&&k,I=e.searchEngine,A=void 0===I?"strict":I,O=e.feedback,C=e.resultsList,j=(C=void 0===C?{}:C).render,x=void 0===j||j,S=C.container,P=void 0!==S&&S,T=C.destination,q=C.position,H=void 0===q?"afterend":q,D=C.element,R=void 0===D?"ul":D,M=C.idName,_=void 0===M?"autoComplete_list":M,z=C.className,B=void 0===z?"autoComplete_list":z,$=C.maxResults,U=void 0===$?5:$,G=C.navigation,J=void 0!==G&&G,K=C.noResults,Q=e.resultItem,V=(Q=void 0===Q?{}:Q).content,W=void 0!==V&&V,X=Q.element,Y=void 0===X?"li":X,Z=Q.idName,ee=Q.className,te=void 0===ee?"autoComplete_result":ee,ne=Q.highlight,ie=(ne=void 0===ne?{}:ne).render,re=void 0!==ie&&ie,se=ne.className,oe=void 0===se?"autoComplete_highlighted":se,ae=Q.selected,le=(ae=void 0===ae?{}:ae).className,ue=void 0===le?"autoComplete_selected":le,ce=e.onSelection;this.selector=i,this.observer=o,this.placeHolder=r,this.data={src:l,key:u,cache:d,store:h,results:f},this.query=m,this.trigger={event:g,condition:y},this.threshold=F,this.debounce=E,this.diacritics=w,this.searchEngine=A,this.feedback=O,this.resultsList={render:x,container:P,destination:T||this.selector,position:H,element:R,idName:_,className:B,maxResults:U,navigation:J,noResults:K},this.resultItem={content:W,element:Y,idName:Z,className:te,highlight:{render:re,className:oe},selected:{className:ue}},this.onSelection=ce,this.inputField="string"==typeof this.selector?document.querySelector(this.selector):this.selector(),this.observer?this.preInit():this.init()}var n,i,r;return n=t,(i=[{key:"start",value:function(e,t){var n=this.data.results?this.data.results(d(this,t)):d(this,t),i={input:e,query:t,matches:n,results:n.slice(0,this.resultsList.maxResults)};if(o(this.inputField,i,"results"),!this.resultsList.render)return this.feedback(i);l(this,i,n),c(this,i),o(this.inputField,i,"open")}},{key:"dataStore",value:function(){var e=this;return new Promise((function(t,n){return e.data.cache&&e.data.store?t(null):new Promise((function(t,n){return"function"==typeof e.data.src?e.data.src().then(t,n):t(e.data.src)})).then((function(i){try{return e.data.store=i,o(e.inputField,e.data.store,"fetch"),t()}catch(e){return n(e)}}),n)}))}},{key:"compose",value:function(e){var t=this;return new Promise((function(n,i){var r,s,o,l,u;return o=t.inputField,r=o instanceof HTMLInputElement||o instanceof HTMLTextAreaElement?o.value.toLowerCase():o.innerHTML.toLowerCase(),l=r,s=(u=t).query&&u.query.manipulate?u.query.manipulate(l):u.diacritics?l.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):l,function(e,t,n){return e.trigger.condition?e.trigger.condition(t,n):n.length>=e.threshold&&n.replace(/ /g,"").length}(t,e,s)?t.dataStore().then((function(e){try{return t.start(r,s),c.call(t)}catch(e){return i(e)}}),i):(a(t),c.call(t));function c(){return n()}}))}},{key:"init",value:function(){var e,t,n,i,r=this;(e=this).inputField.setAttribute("role","combobox"),e.inputField.setAttribute("aria-haspopup",!0),e.inputField.setAttribute("aria-expanded",!1),e.inputField.setAttribute("aria-controls",e.resultsList.idName),e.inputField.setAttribute("aria-autocomplete","both"),this.placeHolder&&this.inputField.setAttribute("placeholder",this.placeHolder),this.hook=(t=function(e){r.compose(e)},n=this.debounce,function(){var e=this,r=arguments;clearTimeout(i),i=setTimeout((function(){return t.apply(e,r)}),n)}),this.trigger.event.forEach((function(e){r.inputField.removeEventListener(e,r.hook),r.inputField.addEventListener(e,r.hook)})),o(this.inputField,null,"init")}},{key:"preInit",value:function(){var e=this;new MutationObserver((function(t,n){var i,r=s(t);try{for(r.s();!(i=r.n()).done;)i.value,e.inputField&&(n.disconnect(),e.init())}catch(e){r.e(e)}finally{r.f()}})).observe(document,{childList:!0,subtree:!0})}},{key:"unInit",value:function(){this.inputField.removeEventListener("input",this.hook),o(this.inputField,null,"unInit")}}])&&e(n.prototype,i),r&&e(n,r),t}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).autoComplete=t(); | ||
var e,t;e=this,t=function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function t(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?e(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function n(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function s(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){u=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(u)throw a}}}}var a=function(e,t,n){e.dispatchEvent(new CustomEvent(n,{bubbles:!0,detail:t,cancelable:!0}))},o=function(e,t){var n=document.getElementById(e.resultsList.idName);n&&t!==e.inputField&&(n.remove(),e.inputField.removeAttribute("aria-activedescendant"),e.inputField.setAttribute("aria-expanded",!1),a(e.inputField,null,"close"))},u="keydown",l="aria-selected",c=function(e,n){e.inputField.removeEventListener(u,e.nav);var i=-1,r=function(r,o,u){r.preventDefault(),o.length&&(u?i++:i--,s(o),e.inputField.setAttribute("aria-activedescendant",o[i].id),a(r.srcElement,t(t({event:r},n),{},{selection:n.results[i]}),"navigate"))},s=function(t){!function(t){for(var n=0;n<t.length;n++)t[n].removeAttribute(l),e.resultItem.selected.className&&t[n].classList.remove(e.resultItem.selected.className)}(t),i>=t.length&&(i=0),i<0&&(i=t.length-1),t[i].setAttribute(l,!0),e.resultItem.selected.className&&t[i].classList.add(e.resultItem.selected.className)};e.nav=function(t){var n=document.getElementById(e.resultsList.idName);if(n)switch(n=n.getElementsByTagName(e.resultItem.element),t.keyCode){case 40:r(t,n,1);break;case 38:r(t,n);break;case 27:e.inputField.value="",o(e);break;case 13:t.preventDefault(),i>=0&&n[i].click();break;case 9:o(e)}},e.inputField.addEventListener(u,e.nav)},d="click",h="aria-expanded",f=function(e,n){n.input;var i=n.query,r=n.matches,s=n.results,u=document.getElementById(e.resultsList.idName);u?(u.innerHTML="",e.inputField.removeAttribute("aria-activedescendant")):(u=function(e){var t=document.createElement(e.resultsList.element);return t.setAttribute("id",e.resultsList.idName),t.setAttribute("class",e.resultsList.className),t.setAttribute("role","listbox"),("string"==typeof e.resultsList.destination?document.querySelector(e.resultsList.destination):e.resultsList.destination()).insertAdjacentElement(e.resultsList.position,t),t}(e),e.inputField.setAttribute(h,!0),a(e.inputField,n,"open")),r.length?s.forEach((function(i,r){var s=function(e,t,n){var i=document.createElement(n.resultItem.element);return i.setAttribute("id","".concat(n.resultItem.idName,"_").concat(t)),i.setAttribute("class",n.resultItem.className),i.setAttribute("role","option"),i.innerHTML=e.match,n.resultItem.content&&n.resultItem.content(e,i),i}(i,r,e);s.addEventListener(d,(function(s){var a=t(t({event:s},n),{},{selection:t(t({},i),{},{index:r})});e.onSelection&&e.onSelection(a)})),u.appendChild(s)})):e.resultsList.noResults?e.resultsList.noResults(u,i):(o(e),e.inputField.setAttribute(h,!1)),e.resultsList.container&&e.resultsList.container(u,n),e.resultsList.navigation?e.resultsList.navigation(u):c(e,n),document.addEventListener(d,(function(t){return o(e,t.target)}))},m=function(e,t){return'<span class="'.concat(e,'">').concat(t,"</span>")},p=function(e,t){var n=e.data,i=e.searchEngine,r=[];return n.store.forEach((function(a,o){var u=function(n){var s=(n?a[n]:a).toString();if(s){var u="function"==typeof i?i(t,s):function(e,t,n){var i=n.diacritics?t.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):t.toLowerCase();if("loose"===n.searchEngine){e=e.replace(/ /g,"");for(var r=[],s=0,a=0;a<i.length;a++){var o=t[a];s<e.length&&i[a]===e[s]&&(o=n.resultItem.highlight.render?m(n.resultItem.highlight.className,o):o,s++),r.push(o)}if(s===e.length)return r.join("")}else if(i.includes(e)){var u=new RegExp(e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i");return e=u.exec(t),n.resultItem.highlight.render?t.replace(e,m(n.resultItem.highlight.className,e)):t}}(t,s,e);u&&n?r.push({key:n,index:o,match:u,value:a}):u&&!n&&r.push({index:o,match:u,value:a})}};if(n.key){var l,c=s(n.key);try{for(c.s();!(l=c.n()).done;)u(l.value)}catch(e){c.e(e)}finally{c.f()}}else u()})),r};return function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var n=t.selector,i=void 0===n?"#autoComplete":n,r=t.placeHolder,s=t.observer,a=t.data,o=a.src,u=a.key,l=a.cache,c=a.store,d=a.results,h=t.query,f=t.trigger,m=(f=void 0===f?{}:f).event,p=void 0===m?["input"]:m,v=f.condition,b=t.threshold,g=void 0===b?1:b,y=t.debounce,L=void 0===y?0:y,E=t.diacritics,F=t.searchEngine,N=t.feedback,A=t.resultsList,k=(A=void 0===A?{}:A).render,w=void 0===k||k,I=A.container,O=A.destination,j=void 0===O?i:O,x=A.position,C=void 0===x?"afterend":x,S=A.element,P=void 0===S?"ul":S,T=A.idName,q=void 0===T?"autoComplete_list":T,H=A.className,D=A.maxResults,R=void 0===D?5:D,M=A.navigation,_=A.noResults,z=t.resultItem,B=(z=void 0===z?{}:z).content,$=z.element,U=void 0===$?"li":$,G=z.idName,J=z.className,K=void 0===J?"autoComplete_result":J,Q=z.highlight,V=(Q=void 0===Q?{}:Q).render,W=Q.className,X=void 0===W?"autoComplete_highlighted":W,Y=z.selected,Z=(Y=void 0===Y?{}:Y).className,ee=void 0===Z?"autoComplete_selected":Z,te=t.onSelection;this.selector=i,this.observer=s,this.placeHolder=r,this.data={src:o,key:u,cache:l,store:c,results:d},this.query=h,this.trigger={event:p,condition:v},this.threshold=g,this.debounce=L,this.diacritics=E,this.searchEngine=F,this.feedback=N,this.resultsList={render:w,container:I,destination:j,position:C,element:P,idName:q,className:H,maxResults:R,navigation:M,noResults:_},this.resultItem={content:B,element:U,idName:G,className:K,highlight:{render:V,className:X},selected:{className:ee}},this.onSelection=te,this.inputField="string"==typeof this.selector?document.querySelector(this.selector):this.selector(),this.observer?this.preInit():this.init()}var t,i,r;return t=e,(i=[{key:"start",value:function(e,t){var n=this.data.results?this.data.results(p(this,t)):p(this,t),i={input:e,query:t,matches:n,results:n.slice(0,this.resultsList.maxResults)};if(a(this.inputField,i,"results"),!this.resultsList.render)return this.feedback(i);f(this,i)}},{key:"dataStore",value:function(){var e=this;return new Promise((function(t,n){return e.data.cache&&e.data.store?t(null):new Promise((function(t,n){return"function"==typeof e.data.src?e.data.src().then(t,n):t(e.data.src)})).then((function(i){try{return e.data.store=i,a(e.inputField,e.data.store,"fetch"),t()}catch(e){return n(e)}}),n)}))}},{key:"compose",value:function(e){var t=this;return new Promise((function(n,i){var r,s,a,u,l;return a=t.inputField,r=a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement?a.value.toLowerCase():a.innerHTML.toLowerCase(),u=r,s=(l=t).query&&l.query.manipulate?l.query.manipulate(u):l.diacritics?u.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):u,function(e,t,n){return e.trigger.condition?e.trigger.condition(t,n):n.length>=e.threshold&&n.replace(/ /g,"").length}(t,e,s)?t.dataStore().then((function(e){try{return t.start(r,s),c.call(t)}catch(e){return i(e)}}),i):(o(t),c.call(t));function c(){return n()}}))}},{key:"init",value:function(){var e,t,n,i,r=this;(e=this).inputField.setAttribute("role","combobox"),e.inputField.setAttribute("aria-haspopup",!0),e.inputField.setAttribute("aria-expanded",!1),e.inputField.setAttribute("aria-controls",e.resultsList.idName),e.inputField.setAttribute("aria-autocomplete","both"),this.placeHolder&&this.inputField.setAttribute("placeholder",this.placeHolder),this.hook=(t=function(e){r.compose(e)},n=this.debounce,function(){var e=this,r=arguments;clearTimeout(i),i=setTimeout((function(){return t.apply(e,r)}),n)}),this.trigger.event.forEach((function(e){r.inputField.addEventListener(e,r.hook)})),a(this.inputField,null,"init")}},{key:"preInit",value:function(){var e=this;new MutationObserver((function(t,n){t.forEach((function(t){e.inputField&&(n.disconnect(),e.init())}))})).observe(document,{childList:!0,subtree:!0})}},{key:"unInit",value:function(){var e=this;this.trigger.event.forEach((function(t){e.inputField.removeEventListener(t,e.hook)})),a(this.inputField,null,"unInit")}}])&&n(t.prototype,i),r&&n(t,r),e}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).autoComplete=t(); |
{ | ||
"name": "@tarekraafat/autocomplete.js", | ||
"version": "9.0.5", | ||
"version": "9.1.0", | ||
"description": "Simple autocomplete pure vanilla Javascript library.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -24,3 +24,3 @@ # autoComplete.js :sparkles: | ||
> Simple autocomplete pure vanilla Javascript library. :rocket: <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">Live Demo</a> **v9.0** | ||
> Simple autocomplete pure vanilla Javascript library. :rocket: <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">Live Demo</a> **v9.1** | ||
@@ -51,3 +51,3 @@ autoComplete.js is a simple pure vanilla Javascript library that's progressively designed for speed, high versatility and seamless integration with a wide range of projects & systems. <sub><sup>(Made for a better developer experience)</sub></pub> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@9.0.5/dist/js/autoComplete.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@9.1.0/dist/js/autoComplete.min.js"></script> | ||
``` | ||
@@ -58,3 +58,3 @@ | ||
```html | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@9.0.5/dist/css/autoComplete.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@9.1.0/dist/css/autoComplete.min.css"> | ||
``` | ||
@@ -61,0 +61,0 @@ #### Package Manager |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59577
959