@tarekraafat/autocomplete.js 10.2.6 → 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 +2 -2
- package/dist/autoComplete.js +18 -36
- package/dist/autoComplete.js.gz +0 -0
- package/dist/autoComplete.min.js +1 -1
- package/dist/autoComplete.min.js.gz +0 -0
- package/package.json +2 -2
- package/src/autoComplete.js +4 -3
- package/src/controllers/searchController.js +1 -1
- package/src/helpers/io.js +1 -1
package/README.md
CHANGED
|
@@ -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.
|
|
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.
|
|
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
|
|
package/dist/autoComplete.js
CHANGED
|
@@ -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
|
-
|
|
14
|
-
|
|
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]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
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
|
|
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
|
|
235
|
+
record = String(record);
|
|
254
236
|
query = format(query, diacritics);
|
|
255
237
|
if (mode === "loose") {
|
|
256
238
|
query = query.replace(/ /g, "");
|
|
@@ -651,4 +633,4 @@
|
|
|
651
633
|
|
|
652
634
|
return autoComplete;
|
|
653
635
|
|
|
654
|
-
}))
|
|
636
|
+
}));
|
package/dist/autoComplete.js.gz
CHANGED
|
Binary file
|
package/dist/autoComplete.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t
|
|
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.
|
|
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": "^
|
|
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",
|
package/src/autoComplete.js
CHANGED
|
@@ -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 {(
|
|
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.
|
|
@@ -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
|
|
16
|
+
record = String(record);
|
|
17
17
|
query = format(query, diacritics);
|
|
18
18
|
|
|
19
19
|
if (mode === "loose") {
|
package/src/helpers/io.js
CHANGED