@tarekraafat/autocomplete.js 10.2.4 → 10.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![npm](https://img.shields.io/npm/v/@tarekraafat/autocomplete.js)](https://badge.fury.io/js/%40tarekraafat%2Fautocomplete.js)
6
6
  ![100% Javascript](https://img.shields.io/github/languages/top/TarekRaafat/autoComplete.js?color=yellow)
7
7
  ![Zero Dependencies](https://img.shields.io/badge/Dependencies-0-blue.svg)
8
- ![Minified Size](https://badgen.net/bundlephobia/min/@tarekraafat/autocomplete.js)
8
+ [![Minified Size](https://badgen.net/bundlephobia/min/@tarekraafat/autocomplete.js@latest)](https://bundlephobia.com/package/@tarekraafat/autocomplete.js@latest)
9
9
  ![Yes Maintained](https://img.shields.io/badge/Maintained%3F-yes-success)
10
10
  [![](https://data.jsdelivr.com/v1/package/npm/@tarekraafat/autocomplete.js/badge)](https://www.jsdelivr.com/package/npm/@tarekraafat/autocomplete.js)
11
11
  ![npm](https://img.shields.io/npm/dm/@tarekraafat/autocomplete.js?label=npm)
@@ -51,13 +51,13 @@ autoComplete.js is a simple, pure vanilla Javascript library progressively desig
51
51
  `JS`
52
52
 
53
53
  ```html
54
- <script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.4/dist/autoComplete.min.js"></script>
54
+ <script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.7/dist/autoComplete.min.js"></script>
55
55
  ```
56
56
 
57
57
  `CSS`
58
58
 
59
59
  ```html
60
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.4/dist/css/autoComplete.min.css">
60
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.7/dist/css/autoComplete.min.css">
61
61
  ```
62
62
  #### Package Manager
63
63
 
@@ -2,21 +2,16 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
3
  typeof define === 'function' && define.amd ? define(factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.autoComplete = factory());
5
- }(this, (function () { 'use strict';
5
+ })(this, (function () { 'use strict';
6
6
 
7
7
  function ownKeys(object, enumerableOnly) {
8
8
  var keys = Object.keys(object);
9
9
 
10
10
  if (Object.getOwnPropertySymbols) {
11
11
  var symbols = Object.getOwnPropertySymbols(object);
12
-
13
- if (enumerableOnly) {
14
- symbols = symbols.filter(function (sym) {
15
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
16
- });
17
- }
18
-
19
- keys.push.apply(keys, symbols);
12
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
13
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
14
+ })), keys.push.apply(keys, symbols);
20
15
  }
21
16
 
22
17
  return keys;
@@ -24,19 +19,12 @@
24
19
 
25
20
  function _objectSpread2(target) {
26
21
  for (var i = 1; i < arguments.length; i++) {
27
- var source = arguments[i] != null ? arguments[i] : {};
28
-
29
- if (i % 2) {
30
- ownKeys(Object(source), true).forEach(function (key) {
31
- _defineProperty(target, key, source[key]);
32
- });
33
- } else if (Object.getOwnPropertyDescriptors) {
34
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
35
- } else {
36
- ownKeys(Object(source)).forEach(function (key) {
37
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
38
- });
39
- }
22
+ var source = null != arguments[i] ? arguments[i] : {};
23
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
24
+ _defineProperty(target, key, source[key]);
25
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
26
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
27
+ });
40
28
  }
41
29
 
42
30
  return target;
@@ -45,17 +33,11 @@
45
33
  function _typeof(obj) {
46
34
  "@babel/helpers - typeof";
47
35
 
48
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
49
- _typeof = function (obj) {
50
- return typeof obj;
51
- };
52
- } else {
53
- _typeof = function (obj) {
54
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
55
- };
56
- }
57
-
58
- return _typeof(obj);
36
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
37
+ return typeof obj;
38
+ } : function (obj) {
39
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
40
+ }, _typeof(obj);
59
41
  }
60
42
 
61
43
  function _defineProperty(obj, key, value) {
@@ -191,7 +173,7 @@
191
173
  return field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement ? field.value : field.innerHTML;
192
174
  };
193
175
  var format = function format(value, diacritics) {
194
- value = value.toString().toLowerCase();
176
+ value = String(value).toLowerCase();
195
177
  return diacritics ? value.normalize("NFD").replace(/[\u0300-\u036f]/g, "").normalize("NFC") : value;
196
178
  };
197
179
  var debounce = function debounce(callback, duration) {
@@ -250,7 +232,7 @@
250
232
  diacritics = _ref.diacritics,
251
233
  highlight = _ref.highlight;
252
234
  var nRecord = format(record, diacritics);
253
- record = record.toString();
235
+ record = String(record);
254
236
  query = format(query, diacritics);
255
237
  if (mode === "loose") {
256
238
  query = query.replace(/ /g, "");
@@ -419,12 +401,10 @@
419
401
  }
420
402
  };
421
403
  var next = function next(ctx) {
422
- var index = ctx.cursor + 1;
423
- goTo(index, ctx);
404
+ goTo(ctx.cursor + 1, ctx);
424
405
  };
425
406
  var previous = function previous(ctx) {
426
- var index = ctx.cursor - 1;
427
- goTo(index, ctx);
407
+ goTo(ctx.cursor - 1, ctx);
428
408
  };
429
409
  var select = function select(ctx, event, index) {
430
410
  index = index >= 0 ? index : ctx.cursor;
@@ -439,8 +419,7 @@
439
419
  var items = Array.from(ctx.list.querySelectorAll(itemTag));
440
420
  var item = event.target.closest(itemTag);
441
421
  if (item && item.nodeName === itemTag) {
442
- var index = items.indexOf(item);
443
- select(ctx, event, index);
422
+ select(ctx, event, items.indexOf(item));
444
423
  }
445
424
  };
446
425
  var navigate = function navigate(event, ctx) {
@@ -575,6 +554,7 @@
575
554
  }, resultsList["class"] && {
576
555
  "class": resultsList["class"]
577
556
  }));
557
+ addEvents(ctx);
578
558
  if (ctx.data.cache) {
579
559
  return getData(ctx).then(function ($await_2) {
580
560
  try {
@@ -585,7 +565,6 @@
585
565
  }, $error);
586
566
  }
587
567
  function $If_1() {
588
- addEvents(ctx);
589
568
  eventEmitter("init", ctx);
590
569
  return $return();
591
570
  }
@@ -627,7 +606,7 @@
627
606
  prototype.select = function (index) {
628
607
  select(this, null, index);
629
608
  };
630
- autoComplete.search = prototype.search = function (query, record, options) {
609
+ prototype.search = function (query, record, options) {
631
610
  return search(query, record, options);
632
611
  };
633
612
  }
@@ -654,4 +633,4 @@
654
633
 
655
634
  return autoComplete;
656
635
 
657
- })));
636
+ }));
Binary file
@@ -1 +1 @@
1
- var t,e;t=this,e=function(){"use strict";function t(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function e(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?t(Object(i),!0).forEach((function(t){r(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||o(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var a=function(t){return"string"==typeof t?document.querySelector(t):t()},u=function(t,e){var n="string"==typeof t?document.createElement(t):t;for(var r in e){var i=e[r];if("inside"===r)i.append(n);else if("dest"===r)a(i[0]).insertAdjacentElement(i[1],n);else if("around"===r){var o=i;o.parentNode.insertBefore(n,o),n.append(o),null!=o.getAttribute("autofocus")&&o.focus()}else r in n?n[r]=i:n.setAttribute(r,i)}return n},c=function(t,e){return t=t.toString().toLowerCase(),e?t.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):t},l=function(t,n){return u("mark",e({innerHTML:t},"string"==typeof n&&{class:n})).outerHTML},f=function(t,e){e.input.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:e.feedback,cancelable:!0}))},p=function(t,e,n){var r=n||{},i=r.mode,o=r.diacritics,s=r.highlight,a=c(e,o);if(e=e.toString(),t=c(t,o),"loose"===i){var u=(t=t.replace(/ /g,"")).length,f=0,p=Array.from(e).map((function(e,n){return f<u&&a[n]===t[f]&&(e=s?l(e,s):e,f++),e})).join("");if(f===u)return p}else{var d=a.indexOf(t);if(~d)return t=e.substring(d,d+t.length),d=s?e.replace(t,l(t,s)):e}},d=function(t,e){return new Promise((function(n,r){var i;return(i=t.data).cache&&i.store?n():new Promise((function(t,n){return"function"==typeof i.src?i.src(e).then(t,n):t(i.src)})).then((function(e){try{return t.feedback=i.store=e,f("response",t),n()}catch(t){return r(t)}}),r)}))},h=function(t,e){var n=e.data,r=e.searchEngine,i=[];n.store.forEach((function(s,a){var u=function(n){var o=n?s[n]:s,a="function"==typeof r?r(t,o):p(t,o,{mode:r,diacritics:e.diacritics,highlight:e.resultItem.highlight});if(a){var u={match:a,value:s};n&&(u.key=n),i.push(u)}};if(n.keys){var c,l=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=o(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}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 s,a=!0,u=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}(n.keys);try{for(l.s();!(c=l.n()).done;)u(c.value)}catch(t){l.e(t)}finally{l.f()}}else u()})),n.filter&&(i=n.filter(i));var s=i.slice(0,e.resultsList.maxResults);e.feedback={query:t,matches:i,results:s},f("results",e)},m="aria-expanded",b="aria-activedescendant",v="aria-selected",y=function(t,n){t.feedback.selection=e({index:n},t.feedback.results[n])},g=function(t){t.isOpen||((t.wrapper||t.input).setAttribute(m,!0),t.list.removeAttribute("hidden"),t.isOpen=!0,f("open",t))},w=function(t){t.isOpen&&((t.wrapper||t.input).setAttribute(m,!1),t.input.setAttribute(b,""),t.list.setAttribute("hidden",""),t.isOpen=!1,f("close",t))},O=function(t,e){var n=e.resultItem,r=e.list.getElementsByTagName(n.tag),o=!!n.selected&&n.selected.split(" ");if(e.isOpen&&r.length){var s,a,u=e.cursor;t>=r.length&&(t=0),t<0&&(t=r.length-1),e.cursor=t,u>-1&&(r[u].removeAttribute(v),o&&(a=r[u].classList).remove.apply(a,i(o))),r[t].setAttribute(v,!0),o&&(s=r[t].classList).add.apply(s,i(o)),e.input.setAttribute(b,r[e.cursor].id),e.list.scrollTop=r[t].offsetTop-e.list.clientHeight+r[t].clientHeight+5,e.feedback.cursor=e.cursor,y(e,t),f("navigate",e)}},A=function(t){var e=t.cursor+1;O(e,t)},k=function(t){var e=t.cursor-1;O(e,t)},L=function(t,e,n){(n=n>=0?n:t.cursor)<0||(t.feedback.event=e,y(t,n),f("selection",t),w(t))};function j(t,n){var r=this;return new Promise((function(i,o){var s,a;return s=n||((a=t.input)instanceof HTMLInputElement||a instanceof HTMLTextAreaElement?a.value:a.innerHTML),function(t,e,n){return e?e(t):t.length>=n}(s=t.query?t.query(s):s,t.trigger,t.threshold)?d(t,s).then((function(n){try{return t.feedback instanceof Error?i():(h(s,t),t.resultsList&&function(t){var n=t.resultsList,r=t.list,i=t.resultItem,o=t.feedback,s=o.matches,a=o.results;if(t.cursor=-1,r.innerHTML="",s.length||n.noResults){var c=new DocumentFragment;a.forEach((function(t,n){var r=u(i.tag,e({id:"".concat(i.id,"_").concat(n),role:"option",innerHTML:t.match,inside:c},i.class&&{class:i.class}));i.element&&i.element(r,t)})),r.append(c),n.element&&n.element(r,o),g(t)}else w(t)}(t),c.call(r))}catch(t){return o(t)}}),o):(w(t),c.call(r));function c(){return i()}}))}var S=function(t,e){for(var n in t)for(var r in t[n])e(n,r)},T=function(t){var n,r,i,o=t.events,s=(n=function(){return j(t)},r=t.debounce,function(){clearTimeout(i),i=setTimeout((function(){return n()}),r)}),a=t.events=e({input:e({},o&&o.input)},t.resultsList&&{list:o?e({},o.list):{}}),u={input:{input:function(){s()},keydown:function(e){!function(t,e){switch(t.keyCode){case 40:case 38:t.preventDefault(),40===t.keyCode?A(e):k(e);break;case 13:e.submit||t.preventDefault(),e.cursor>=0&&L(e,t);break;case 9:e.resultsList.tabSelect&&e.cursor>=0&&L(e,t);break;case 27:e.input.value="",w(e)}}(e,t)},blur:function(){w(t)}},list:{mousedown:function(t){t.preventDefault()},click:function(e){!function(t,e){var n=e.resultItem.tag.toUpperCase(),r=Array.from(e.list.querySelectorAll(n)),i=t.target.closest(n);if(i&&i.nodeName===n){var o=r.indexOf(i);L(e,t,o)}}(e,t)}}};S(u,(function(e,n){(t.resultsList||"input"===n)&&(a[e][n]||(a[e][n]=u[e][n]))})),S(a,(function(e,n){t[e].addEventListener(n,a[e][n])}))};function E(t){var n=this;return new Promise((function(r,i){var o,s,a;if(o=t.placeHolder,a={role:"combobox","aria-owns":(s=t.resultsList).id,"aria-haspopup":!0,"aria-expanded":!1},u(t.input,e(e({"aria-controls":s.id,"aria-autocomplete":"both"},o&&{placeholder:o}),!t.wrapper&&e({},a))),t.wrapper&&(t.wrapper=u("div",e({around:t.input,class:t.name+"_wrapper"},a))),s&&(t.list=u(s.tag,e({dest:[s.destination,s.position],id:s.id,role:"listbox",hidden:"hidden"},s.class&&{class:s.class}))),t.data.cache)return d(t).then((function(t){try{return c.call(n)}catch(t){return i(t)}}),i);function c(){return T(t),f("init",t),r()}return c.call(n)}))}function x(t){var e=t.prototype;e.init=function(){E(this)},e.start=function(t){j(this,t)},e.unInit=function(){if(this.wrapper){var t=this.wrapper.parentNode;t.insertBefore(this.input,this.wrapper),t.removeChild(this.wrapper)}var e;S((e=this).events,(function(t,n){e[t].removeEventListener(n,e.events[t][n])}))},e.open=function(){g(this)},e.close=function(){w(this)},e.goTo=function(t){O(t,this)},e.next=function(){A(this)},e.previous=function(){k(this)},e.select=function(t){L(this,null,t)},t.search=e.search=function(t,e,n){return p(t,e,n)}}return function t(e){this.options=e,this.id=t.instances=(t.instances||0)+1,this.name="autoComplete",this.wrapper=1,this.threshold=1,this.debounce=0,this.resultsList={position:"afterend",tag:"ul",maxResults:5},this.resultItem={tag:"li"},function(t){var e=t.name,r=t.options,i=t.resultsList,o=t.resultItem;for(var s in r)if("object"===n(r[s]))for(var u in t[s]||(t[s]={}),r[s])t[s][u]=r[s][u];else t[s]=r[s];t.selector=t.selector||"#"+e,i.destination=i.destination||t.selector,i.id=i.id||e+"_list_"+t.id,o.id=o.id||e+"_result",t.input=a(t.selector)}(this),x.call(this,t),E(this)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).autoComplete=e();
1
+ var e,t;e=this,t=function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){r(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||o(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){if(e){if("string"==typeof e)return s(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)?s(e,t):void 0}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var u=function(e){return"string"==typeof e?document.querySelector(e):e()},a=function(e,t){var n="string"==typeof e?document.createElement(e):e;for(var r in t){var i=t[r];if("inside"===r)i.append(n);else if("dest"===r)u(i[0]).insertAdjacentElement(i[1],n);else if("around"===r){var o=i;o.parentNode.insertBefore(n,o),n.append(o),null!=o.getAttribute("autofocus")&&o.focus()}else r in n?n[r]=i:n.setAttribute(r,i)}return n},c=function(e,t){return e=String(e).toLowerCase(),t?e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):e},l=function(e,n){return a("mark",t({innerHTML:e},"string"==typeof n&&{class:n})).outerHTML},f=function(e,t){t.input.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:t.feedback,cancelable:!0}))},p=function(e,t,n){var r=n||{},i=r.mode,o=r.diacritics,s=r.highlight,u=c(t,o);if(t=String(t),e=c(e,o),"loose"===i){var a=(e=e.replace(/ /g,"")).length,f=0,p=Array.from(t).map((function(t,n){return f<a&&u[n]===e[f]&&(t=s?l(t,s):t,f++),t})).join("");if(f===a)return p}else{var d=u.indexOf(e);if(~d)return e=t.substring(d,d+e.length),d=s?t.replace(e,l(e,s)):t}},d=function(e,t){return new Promise((function(n,r){var i;return(i=e.data).cache&&i.store?n():new Promise((function(e,n){return"function"==typeof i.src?i.src(t).then(e,n):e(i.src)})).then((function(t){try{return e.feedback=i.store=t,f("response",e),n()}catch(e){return r(e)}}),r)}))},h=function(e,t){var n=t.data,r=t.searchEngine,i=[];n.store.forEach((function(s,u){var a=function(n){var o=n?s[n]:s,u="function"==typeof r?r(e,o):p(e,o,{mode:r,diacritics:t.diacritics,highlight:t.resultItem.highlight});if(u){var a={match:u,value:s};n&&(a.key=n),i.push(a)}};if(n.keys){var c,l=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=o(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}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 s,u=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return u=e.done,e},e:function(e){a=!0,s=e},f:function(){try{u||null==n.return||n.return()}finally{if(a)throw s}}}}(n.keys);try{for(l.s();!(c=l.n()).done;)a(c.value)}catch(e){l.e(e)}finally{l.f()}}else a()})),n.filter&&(i=n.filter(i));var s=i.slice(0,t.resultsList.maxResults);t.feedback={query:e,matches:i,results:s},f("results",t)},m="aria-expanded",b="aria-activedescendant",y="aria-selected",v=function(e,n){e.feedback.selection=t({index:n},e.feedback.results[n])},g=function(e){e.isOpen||((e.wrapper||e.input).setAttribute(m,!0),e.list.removeAttribute("hidden"),e.isOpen=!0,f("open",e))},w=function(e){e.isOpen&&((e.wrapper||e.input).setAttribute(m,!1),e.input.setAttribute(b,""),e.list.setAttribute("hidden",""),e.isOpen=!1,f("close",e))},O=function(e,t){var n=t.resultItem,r=t.list.getElementsByTagName(n.tag),o=!!n.selected&&n.selected.split(" ");if(t.isOpen&&r.length){var s,u,a=t.cursor;e>=r.length&&(e=0),e<0&&(e=r.length-1),t.cursor=e,a>-1&&(r[a].removeAttribute(y),o&&(u=r[a].classList).remove.apply(u,i(o))),r[e].setAttribute(y,!0),o&&(s=r[e].classList).add.apply(s,i(o)),t.input.setAttribute(b,r[t.cursor].id),t.list.scrollTop=r[e].offsetTop-t.list.clientHeight+r[e].clientHeight+5,t.feedback.cursor=t.cursor,v(t,e),f("navigate",t)}},A=function(e){O(e.cursor+1,e)},k=function(e){O(e.cursor-1,e)},L=function(e,t,n){(n=n>=0?n:e.cursor)<0||(e.feedback.event=t,v(e,n),f("selection",e),w(e))};function j(e,n){var r=this;return new Promise((function(i,o){var s,u;return s=n||((u=e.input)instanceof HTMLInputElement||u instanceof HTMLTextAreaElement?u.value:u.innerHTML),function(e,t,n){return t?t(e):e.length>=n}(s=e.query?e.query(s):s,e.trigger,e.threshold)?d(e,s).then((function(n){try{return e.feedback instanceof Error?i():(h(s,e),e.resultsList&&function(e){var n=e.resultsList,r=e.list,i=e.resultItem,o=e.feedback,s=o.matches,u=o.results;if(e.cursor=-1,r.innerHTML="",s.length||n.noResults){var c=new DocumentFragment;u.forEach((function(e,n){var r=a(i.tag,t({id:"".concat(i.id,"_").concat(n),role:"option",innerHTML:e.match,inside:c},i.class&&{class:i.class}));i.element&&i.element(r,e)})),r.append(c),n.element&&n.element(r,o),g(e)}else w(e)}(e),c.call(r))}catch(e){return o(e)}}),o):(w(e),c.call(r));function c(){return i()}}))}var S=function(e,t){for(var n in e)for(var r in e[n])t(n,r)},T=function(e){var n,r,i,o=e.events,s=(n=function(){return j(e)},r=e.debounce,function(){clearTimeout(i),i=setTimeout((function(){return n()}),r)}),u=e.events=t({input:t({},o&&o.input)},e.resultsList&&{list:o?t({},o.list):{}}),a={input:{input:function(){s()},keydown:function(t){!function(e,t){switch(e.keyCode){case 40:case 38:e.preventDefault(),40===e.keyCode?A(t):k(t);break;case 13:t.submit||e.preventDefault(),t.cursor>=0&&L(t,e);break;case 9:t.resultsList.tabSelect&&t.cursor>=0&&L(t,e);break;case 27:t.input.value="",w(t)}}(t,e)},blur:function(){w(e)}},list:{mousedown:function(e){e.preventDefault()},click:function(t){!function(e,t){var n=t.resultItem.tag.toUpperCase(),r=Array.from(t.list.querySelectorAll(n)),i=e.target.closest(n);i&&i.nodeName===n&&L(t,e,r.indexOf(i))}(t,e)}}};S(a,(function(t,n){(e.resultsList||"input"===n)&&(u[t][n]||(u[t][n]=a[t][n]))})),S(u,(function(t,n){e[t].addEventListener(n,u[t][n])}))};function E(e){var n=this;return new Promise((function(r,i){var o,s,u;if(o=e.placeHolder,u={role:"combobox","aria-owns":(s=e.resultsList).id,"aria-haspopup":!0,"aria-expanded":!1},a(e.input,t(t({"aria-controls":s.id,"aria-autocomplete":"both"},o&&{placeholder:o}),!e.wrapper&&t({},u))),e.wrapper&&(e.wrapper=a("div",t({around:e.input,class:e.name+"_wrapper"},u))),s&&(e.list=a(s.tag,t({dest:[s.destination,s.position],id:s.id,role:"listbox",hidden:"hidden"},s.class&&{class:s.class}))),T(e),e.data.cache)return d(e).then((function(e){try{return c.call(n)}catch(e){return i(e)}}),i);function c(){return f("init",e),r()}return c.call(n)}))}function x(e){var t=e.prototype;t.init=function(){E(this)},t.start=function(e){j(this,e)},t.unInit=function(){if(this.wrapper){var e=this.wrapper.parentNode;e.insertBefore(this.input,this.wrapper),e.removeChild(this.wrapper)}var t;S((t=this).events,(function(e,n){t[e].removeEventListener(n,t.events[e][n])}))},t.open=function(){g(this)},t.close=function(){w(this)},t.goTo=function(e){O(e,this)},t.next=function(){A(this)},t.previous=function(){k(this)},t.select=function(e){L(this,null,e)},t.search=function(e,t,n){return p(e,t,n)}}return function e(t){this.options=t,this.id=e.instances=(e.instances||0)+1,this.name="autoComplete",this.wrapper=1,this.threshold=1,this.debounce=0,this.resultsList={position:"afterend",tag:"ul",maxResults:5},this.resultItem={tag:"li"},function(e){var t=e.name,r=e.options,i=e.resultsList,o=e.resultItem;for(var s in r)if("object"===n(r[s]))for(var a in e[s]||(e[s]={}),r[s])e[s][a]=r[s][a];else e[s]=r[s];e.selector=e.selector||"#"+t,i.destination=i.destination||e.selector,i.id=i.id||t+"_list_"+e.id,o.id=o.id||t+"_result",e.input=u(e.selector)}(this),x.call(this,e),E(this)}},"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();
Binary file
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "10.2.4",
2
+ "version": "10.2.7",
3
3
  "name": "@tarekraafat/autocomplete.js",
4
4
  "description": "Simple autocomplete pure vanilla Javascript library.",
5
5
  "keywords": [
@@ -67,7 +67,7 @@
67
67
  "rollup": "^2.41.0",
68
68
  "rollup-plugin-analyzer": "^4.0.0",
69
69
  "rollup-plugin-cleanup": "^3.2.1",
70
- "rollup-plugin-gzip": "^2.5.0",
70
+ "rollup-plugin-gzip": "^3.0.1",
71
71
  "rollup-plugin-livereload": "^2.0.0",
72
72
  "rollup-plugin-nodent": "^0.2.2",
73
73
  "rollup-plugin-serve": "^1.1.0",
@@ -10,10 +10,11 @@ import init from "./services/init";
10
10
  * @example const autoCompleteJS = new autoComplete({config});
11
11
  *
12
12
  * @param {Object} config - Configuration options.
13
+ * @param {Number|String} [config.id] - Auto assigned instance unique identifier.
13
14
  * @param {String} [config.name=autoComplete] - Prepended to all created DOM element class names.
14
15
  * @param {(String|Function)} [config.selector=#autoComplete] - Must point to or return the relevant input field or element that autoComplete.js should act upon.
15
16
  * @param {Object} config.data - Data source.
16
- * @param {(Array|Function)} config.data.src - Values to search or an async or immediate function that returns an array of values to search.
17
+ * @param {(String[]|Object[]|Function)} config.data.src - Values to search or an async or immediate function that returns an array of values to search.
17
18
  * @param {String[]} [config.data.keys] - Only used if config.data.src is an array of objects. Specifies which keys in the objects autoComplete.js should search.
18
19
  * @param {Boolean} [config.data.cache=false] - If true, autoComplete.js fetches all config.data.src when initialized and never again.
19
20
  * @param {Function} [config.data.filter] - Used to filter and sort matching returns from config.data.src before showing them to the user. Signature: (Array), is given all the results from config.data.src that matches the query.
@@ -29,7 +30,7 @@ import init from "./services/init";
29
30
  * @param {String} [config.resultsList.tag=ul] - HTML tag to use for rendering the result container.
30
31
  * @param {String} [config.resultsList.id=autoComplete_list_index] - ID given to the result container.
31
32
  * @param {String} [config.resultsList.class] - Class names to give to the result container.
32
- * @param {(String|Function)} [config.resultsList.destination] - Selector that points to where you want to insert the result elements. Defaults to config.selector. Signature: ().
33
+ * @param {(String|Function)} [config.resultsList.destination=#autoComplete] - Selector that points to where you want to insert the result elements. Defaults to config.selector. Signature: ().
33
34
  * @param {String} [config.resultsList.position=afterend] - Position relative to config.selector where to insert the results list. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentElement#parameters}.
34
35
  * @param {Function} [config.resultsList.element] - Invoked before showing the results list. Allows manipulation of the DOM before it is added to the document. Signature: (list: HTMLElement, data: { query, matches, results }), where list is the container element.
35
36
  * @param {Number} [config.resultsList.maxResults=5] - Maximum number of results to render.
@@ -42,7 +43,7 @@ import init from "./services/init";
42
43
  * @param {Function} [config.resultItem.element] - Invoked before showing the results list. Allows manipulation of the DOM before it is added to the document. Signature: (item: HTMLElement, data: { match, value, [key] }).
43
44
  * @param {(Boolean|String)} [config.resultItem.highlight=false] - Enable to highlight matching characters using HTMLMarkElement, or a string of CSS classes to add to any generated mark elements.
44
45
  * @param {String} [config.resultItem.selected] - CSS classes to add and remove from result items the user navigates to using the keyboard.
45
- * @param {Boolean} [config.submit] - If enabled pressing enter will not prevent default behavior.
46
+ * @param {Boolean} [config.submit=false] - If enabled pressing enter will not prevent default behavior.
46
47
  * @param {Object} [config.events] - Allows adding custom or overriding internal event handling.
47
48
  * @param {Object} [config.events.input] - Maps event names to event handlers for the input element. Each key must be a valid event name, see {@link https://developer.mozilla.org/en-US/docs/Web/Events}, and each value must be an event handler function. Default handlers are keydown and blur.
48
49
  * @param {Object} [config.events.list] - Same as config.events.input, but for the result list container element. Default handlers are mousedown and click.
@@ -167,9 +167,8 @@ const goTo = (index, ctx) => {
167
167
  *
168
168
  * @param {Object} ctx - autoComplete.js context
169
169
  */
170
- const next = function (ctx) {
171
- const index = ctx.cursor + 1;
172
- goTo(index, ctx);
170
+ const next = (ctx) => {
171
+ goTo(ctx.cursor + 1, ctx);
173
172
  };
174
173
 
175
174
  /**
@@ -178,8 +177,7 @@ const next = function (ctx) {
178
177
  * @param {Object} ctx - autoComplete.js context
179
178
  */
180
179
  const previous = (ctx) => {
181
- const index = ctx.cursor - 1;
182
- goTo(index, ctx);
180
+ goTo(ctx.cursor - 1, ctx);
183
181
  };
184
182
 
185
183
  /**
@@ -221,9 +219,7 @@ const click = (event, ctx) => {
221
219
 
222
220
  // Check if clicked item is a "result" item
223
221
  if (item && item.nodeName === itemTag) {
224
- const index = items.indexOf(item);
225
-
226
- select(ctx, event, index);
222
+ select(ctx, event, items.indexOf(item));
227
223
  }
228
224
  };
229
225
 
@@ -233,7 +229,7 @@ const click = (event, ctx) => {
233
229
  * @param {Object} event - "keydown" press event Object
234
230
  * @param {Object} ctx - autoComplete.js context
235
231
  */
236
- const navigate = function (event, ctx) {
232
+ const navigate = (event, ctx) => {
237
233
  // Check pressed key
238
234
  switch (event.keyCode) {
239
235
  // Down/Up arrow
@@ -13,7 +13,7 @@ export default (query, record, options) => {
13
13
  const { mode, diacritics, highlight } = options || {};
14
14
 
15
15
  const nRecord = format(record, diacritics);
16
- record = record.toString();
16
+ record = String(record);
17
17
  query = format(query, diacritics);
18
18
 
19
19
  if (mode === "loose") {
package/src/helpers/io.js CHANGED
@@ -61,7 +61,7 @@ const getQuery = (field) =>
61
61
  * @returns {String} - Raw "input" value as a string
62
62
  */
63
63
  const format = (value, diacritics) => {
64
- value = value.toString().toLowerCase();
64
+ value = String(value).toLowerCase();
65
65
 
66
66
  return diacritics
67
67
  ? value
@@ -89,7 +89,7 @@ export default function (autoComplete) {
89
89
  *
90
90
  * @returns {String} - Matching data record
91
91
  */
92
- autoComplete.search = prototype.search = function (query, record, options) {
92
+ prototype.search = function (query, record, options) {
93
93
  return search(query, record, options);
94
94
  };
95
95
  }
@@ -39,12 +39,12 @@ export default async function (ctx) {
39
39
  ...(resultsList.class && { class: resultsList.class }),
40
40
  });
41
41
 
42
- // Get the data from store
43
- if (ctx.data.cache) await getData(ctx);
44
-
45
42
  // Attach Events listeners
46
43
  addEvents(ctx);
47
44
 
45
+ // Get the data from store
46
+ if (ctx.data.cache) await getData(ctx);
47
+
48
48
  /**
49
49
  * @emit {init} event on Initialization
50
50
  **/