@tarekraafat/autocomplete.js 10.2.6 → 10.2.8
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 +3 -3
- package/dist/autoComplete.js +123 -151
- 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 +20 -11
- package/src/autoComplete.js +5 -4
- package/src/controllers/dataController.js +6 -1
- package/src/controllers/listController.js +5 -0
- 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.8/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.8/dist/css/autoComplete.min.css">
|
|
61
61
|
```
|
|
62
62
|
#### Package Manager
|
|
63
63
|
|
|
@@ -118,4 +118,4 @@ General questions or new ideas for `autoComplete.js` please start a discussion o
|
|
|
118
118
|
|
|
119
119
|
Released under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).
|
|
120
120
|
|
|
121
|
-
©
|
|
121
|
+
© 2022 [Tarek Raafat](http://www.tarekraafat.com)
|
package/dist/autoComplete.js
CHANGED
|
@@ -2,166 +2,132 @@
|
|
|
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
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return keys;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function _objectSpread2(target) {
|
|
26
|
-
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
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return target;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function _typeof(obj) {
|
|
46
|
-
"@babel/helpers - typeof";
|
|
47
|
-
|
|
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);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function _defineProperty(obj, key, value) {
|
|
62
|
-
if (key in obj) {
|
|
63
|
-
Object.defineProperty(obj, key, {
|
|
64
|
-
value: value,
|
|
65
|
-
enumerable: true,
|
|
66
|
-
configurable: true,
|
|
67
|
-
writable: true
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
obj[key] = value;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return obj;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function _toConsumableArray(arr) {
|
|
77
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function _arrayWithoutHoles(arr) {
|
|
81
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function _iterableToArray(iter) {
|
|
85
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
89
|
-
if (!o) return;
|
|
90
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
91
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
92
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
93
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
94
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function _arrayLikeToArray(arr, len) {
|
|
98
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
99
|
-
|
|
100
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
101
|
-
|
|
102
|
-
return arr2;
|
|
7
|
+
function _arrayLikeToArray(r, a) {
|
|
8
|
+
(null == a || a > r.length) && (a = r.length);
|
|
9
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
10
|
+
return n;
|
|
103
11
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
12
|
+
function _arrayWithoutHoles(r) {
|
|
13
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
107
14
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var i = 0;
|
|
116
|
-
|
|
117
|
-
var F = function () {};
|
|
118
|
-
|
|
15
|
+
function _createForOfIteratorHelper(r, e) {
|
|
16
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
17
|
+
if (!t) {
|
|
18
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
19
|
+
t && (r = t);
|
|
20
|
+
var n = 0,
|
|
21
|
+
F = function () {};
|
|
119
22
|
return {
|
|
120
23
|
s: F,
|
|
121
24
|
n: function () {
|
|
122
|
-
|
|
123
|
-
done:
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
value: o[i++]
|
|
25
|
+
return n >= r.length ? {
|
|
26
|
+
done: !0
|
|
27
|
+
} : {
|
|
28
|
+
done: !1,
|
|
29
|
+
value: r[n++]
|
|
128
30
|
};
|
|
129
31
|
},
|
|
130
|
-
e: function (
|
|
131
|
-
throw
|
|
32
|
+
e: function (r) {
|
|
33
|
+
throw r;
|
|
132
34
|
},
|
|
133
35
|
f: F
|
|
134
36
|
};
|
|
135
37
|
}
|
|
136
|
-
|
|
137
38
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
138
39
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
err;
|
|
40
|
+
var o,
|
|
41
|
+
a = !0,
|
|
42
|
+
u = !1;
|
|
143
43
|
return {
|
|
144
44
|
s: function () {
|
|
145
|
-
|
|
45
|
+
t = t.call(r);
|
|
146
46
|
},
|
|
147
47
|
n: function () {
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
return step;
|
|
48
|
+
var r = t.next();
|
|
49
|
+
return a = r.done, r;
|
|
151
50
|
},
|
|
152
|
-
e: function (
|
|
153
|
-
|
|
154
|
-
err = e;
|
|
51
|
+
e: function (r) {
|
|
52
|
+
u = !0, o = r;
|
|
155
53
|
},
|
|
156
54
|
f: function () {
|
|
157
55
|
try {
|
|
158
|
-
|
|
56
|
+
a || null == t.return || t.return();
|
|
159
57
|
} finally {
|
|
160
|
-
if (
|
|
58
|
+
if (u) throw o;
|
|
161
59
|
}
|
|
162
60
|
}
|
|
163
61
|
};
|
|
164
62
|
}
|
|
63
|
+
function _defineProperty(e, r, t) {
|
|
64
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
65
|
+
value: t,
|
|
66
|
+
enumerable: !0,
|
|
67
|
+
configurable: !0,
|
|
68
|
+
writable: !0
|
|
69
|
+
}) : e[r] = t, e;
|
|
70
|
+
}
|
|
71
|
+
function _iterableToArray(r) {
|
|
72
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
73
|
+
}
|
|
74
|
+
function _nonIterableSpread() {
|
|
75
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
76
|
+
}
|
|
77
|
+
function ownKeys(e, r) {
|
|
78
|
+
var t = Object.keys(e);
|
|
79
|
+
if (Object.getOwnPropertySymbols) {
|
|
80
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
81
|
+
r && (o = o.filter(function (r) {
|
|
82
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
83
|
+
})), t.push.apply(t, o);
|
|
84
|
+
}
|
|
85
|
+
return t;
|
|
86
|
+
}
|
|
87
|
+
function _objectSpread2(e) {
|
|
88
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
89
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
90
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
91
|
+
_defineProperty(e, r, t[r]);
|
|
92
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
93
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return e;
|
|
97
|
+
}
|
|
98
|
+
function _toConsumableArray(r) {
|
|
99
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
100
|
+
}
|
|
101
|
+
function _toPrimitive(t, r) {
|
|
102
|
+
if ("object" != typeof t || !t) return t;
|
|
103
|
+
var e = t[Symbol.toPrimitive];
|
|
104
|
+
if (void 0 !== e) {
|
|
105
|
+
var i = e.call(t, r || "default");
|
|
106
|
+
if ("object" != typeof i) return i;
|
|
107
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
108
|
+
}
|
|
109
|
+
return ("string" === r ? String : Number)(t);
|
|
110
|
+
}
|
|
111
|
+
function _toPropertyKey(t) {
|
|
112
|
+
var i = _toPrimitive(t, "string");
|
|
113
|
+
return "symbol" == typeof i ? i : i + "";
|
|
114
|
+
}
|
|
115
|
+
function _typeof(o) {
|
|
116
|
+
"@babel/helpers - typeof";
|
|
117
|
+
|
|
118
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
119
|
+
return typeof o;
|
|
120
|
+
} : function (o) {
|
|
121
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
122
|
+
}, _typeof(o);
|
|
123
|
+
}
|
|
124
|
+
function _unsupportedIterableToArray(r, a) {
|
|
125
|
+
if (r) {
|
|
126
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
127
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
128
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
165
131
|
|
|
166
132
|
var select$1 = function select(element) {
|
|
167
133
|
return typeof element === "string" ? document.querySelector(element) : element();
|
|
@@ -191,7 +157,7 @@
|
|
|
191
157
|
return field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement ? field.value : field.innerHTML;
|
|
192
158
|
};
|
|
193
159
|
var format = function format(value, diacritics) {
|
|
194
|
-
value = value
|
|
160
|
+
value = String(value).toLowerCase();
|
|
195
161
|
return diacritics ? value.normalize("NFD").replace(/[\u0300-\u036f]/g, "").normalize("NFC") : value;
|
|
196
162
|
};
|
|
197
163
|
var debounce = function debounce(callback, duration) {
|
|
@@ -216,9 +182,9 @@
|
|
|
216
182
|
|
|
217
183
|
var configure = (function (ctx) {
|
|
218
184
|
var name = ctx.name,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
185
|
+
options = ctx.options,
|
|
186
|
+
resultsList = ctx.resultsList,
|
|
187
|
+
resultItem = ctx.resultItem;
|
|
222
188
|
for (var option in options) {
|
|
223
189
|
if (_typeof(options[option]) === "object") {
|
|
224
190
|
if (!ctx[option]) ctx[option] = {};
|
|
@@ -246,11 +212,11 @@
|
|
|
246
212
|
|
|
247
213
|
var search = (function (query, record, options) {
|
|
248
214
|
var _ref = options || {},
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
215
|
+
mode = _ref.mode,
|
|
216
|
+
diacritics = _ref.diacritics,
|
|
217
|
+
highlight = _ref.highlight;
|
|
252
218
|
var nRecord = format(record, diacritics);
|
|
253
|
-
record = record
|
|
219
|
+
record = String(record);
|
|
254
220
|
query = format(query, diacritics);
|
|
255
221
|
if (mode === "loose") {
|
|
256
222
|
query = query.replace(/ /g, "");
|
|
@@ -281,12 +247,17 @@
|
|
|
281
247
|
if (data.cache && data.store) return $return();
|
|
282
248
|
return new Promise(function ($return, $error) {
|
|
283
249
|
if (typeof data.src === "function") {
|
|
284
|
-
return
|
|
250
|
+
return new Promise(function ($return, $error) {
|
|
251
|
+
if (data.src.constructor.name === "AsyncFunction") {
|
|
252
|
+
return data.src(query).then($return, $error);
|
|
253
|
+
}
|
|
254
|
+
return $return(data.src(query));
|
|
255
|
+
}).then($return, $error);
|
|
285
256
|
}
|
|
286
257
|
return $return(data.src);
|
|
287
|
-
}).then(function ($
|
|
258
|
+
}).then(function ($await_7) {
|
|
288
259
|
try {
|
|
289
|
-
ctx.feedback = data.store = $
|
|
260
|
+
ctx.feedback = data.store = $await_7;
|
|
290
261
|
eventEmitter("response", ctx);
|
|
291
262
|
return $return();
|
|
292
263
|
} catch ($boundEx) {
|
|
@@ -297,7 +268,7 @@
|
|
|
297
268
|
};
|
|
298
269
|
var findMatches = function findMatches(query, ctx) {
|
|
299
270
|
var data = ctx.data,
|
|
300
|
-
|
|
271
|
+
searchEngine = ctx.searchEngine;
|
|
301
272
|
var matches = [];
|
|
302
273
|
data.store.forEach(function (value, index) {
|
|
303
274
|
var find = function find(key) {
|
|
@@ -317,7 +288,7 @@
|
|
|
317
288
|
};
|
|
318
289
|
if (data.keys) {
|
|
319
290
|
var _iterator = _createForOfIteratorHelper(data.keys),
|
|
320
|
-
|
|
291
|
+
_step;
|
|
321
292
|
try {
|
|
322
293
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
323
294
|
var key = _step.value;
|
|
@@ -352,11 +323,11 @@
|
|
|
352
323
|
};
|
|
353
324
|
var render = function render(ctx) {
|
|
354
325
|
var resultsList = ctx.resultsList,
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
326
|
+
list = ctx.list,
|
|
327
|
+
resultItem = ctx.resultItem,
|
|
328
|
+
feedback = ctx.feedback;
|
|
358
329
|
var matches = feedback.matches,
|
|
359
|
-
|
|
330
|
+
results = feedback.results;
|
|
360
331
|
ctx.cursor = -1;
|
|
361
332
|
list.innerHTML = "";
|
|
362
333
|
if (matches.length || resultsList.noResults) {
|
|
@@ -456,6 +427,7 @@
|
|
|
456
427
|
break;
|
|
457
428
|
case 27:
|
|
458
429
|
ctx.input.value = "";
|
|
430
|
+
eventEmitter('clear', ctx);
|
|
459
431
|
close(ctx);
|
|
460
432
|
break;
|
|
461
433
|
}
|
|
@@ -651,4 +623,4 @@
|
|
|
651
623
|
|
|
652
624
|
return autoComplete;
|
|
653
625
|
|
|
654
|
-
}))
|
|
626
|
+
}));
|
package/dist/autoComplete.js.gz
CHANGED
|
Binary file
|
package/dist/autoComplete.min.js
CHANGED
|
@@ -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
|
|
1
|
+
var t,e;t=this,e=function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function e(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(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 r(t){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?n(Object(i),!0).forEach((function(n){e(t,n,i[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function i(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||s(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(t){return o="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},o(t)}function s(e,n){if(e){if("string"==typeof e)return t(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}var u=function(t){return"string"==typeof t?document.querySelector(t):t()},a=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)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(t,e){return t=String(t).toLowerCase(),e?t.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):t},l=function(t,e){return a("mark",r({innerHTML:t},"string"==typeof e&&{class:e})).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,u=c(e,o);if(e=String(e),t=c(t,o),"loose"===i){var a=(t=t.replace(/ /g,"")).length,f=0,p=Array.from(e).map((function(e,n){return f<a&&u[n]===t[f]&&(e=s?l(e,s):e,f++),e})).join("");if(f===a)return p}else{var d=u.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?new Promise((function(t,n){return"AsyncFunction"===i.src.constructor.name?i.src(e).then(t,n):t(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(o,u){var a=function(n){var s=n?o[n]:o,u="function"==typeof r?r(t,s):p(t,s,{mode:r,diacritics:e.diacritics,highlight:e.resultItem.highlight});if(u){var a={match:u,value:o};n&&(a.key=n),i.push(a)}};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=s(t))||e){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 o,u=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return u=t.done,t},e:function(t){a=!0,o=t},f:function(){try{u||null==n.return||n.return()}finally{if(a)throw o}}}}(n.keys);try{for(l.s();!(c=l.n()).done;)a(c.value)}catch(t){l.e(t)}finally{l.f()}}else a()})),n.filter&&(i=n.filter(i));var o=i.slice(0,e.resultsList.maxResults);e.feedback={query:t,matches:i,results:o},f("results",e)},m="aria-expanded",v="aria-activedescendant",y="aria-selected",b=function(t,e){t.feedback.selection=r({index:e},t.feedback.results[e])},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(v,""),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,u,a=e.cursor;t>=r.length&&(t=0),t<0&&(t=r.length-1),e.cursor=t,a>-1&&(r[a].removeAttribute(y),o&&(u=r[a].classList).remove.apply(u,i(o))),r[t].setAttribute(y,!0),o&&(s=r[t].classList).add.apply(s,i(o)),e.input.setAttribute(v,r[e.cursor].id),e.list.scrollTop=r[t].offsetTop-e.list.clientHeight+r[t].clientHeight+5,e.feedback.cursor=e.cursor,b(e,t),f("navigate",e)}},A=function(t){O(t.cursor+1,t)},S=function(t){O(t.cursor-1,t)},j=function(t,e,n){(n=n>=0?n:t.cursor)<0||(t.feedback.event=e,b(t,n),f("selection",t),w(t))};function k(t,e){var n=this;return new Promise((function(i,o){var s,u;return s=e||((u=t.input)instanceof HTMLInputElement||u instanceof HTMLTextAreaElement?u.value:u.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(e){try{return t.feedback instanceof Error?i():(h(s,t),t.resultsList&&function(t){var e=t.resultsList,n=t.list,i=t.resultItem,o=t.feedback,s=o.matches,u=o.results;if(t.cursor=-1,n.innerHTML="",s.length||e.noResults){var c=new DocumentFragment;u.forEach((function(t,e){var n=a(i.tag,r({id:"".concat(i.id,"_").concat(e),role:"option",innerHTML:t.match,inside:c},i.class&&{class:i.class}));i.element&&i.element(n,t)})),n.append(c),e.element&&e.element(n,o),g(t)}else w(t)}(t),c.call(n))}catch(t){return o(t)}}),o):(w(t),c.call(n));function c(){return i()}}))}var L=function(t,e){for(var n in t)for(var r in t[n])e(n,r)},T=function(t){var e,n,i,o=t.events,s=(e=function(){return k(t)},n=t.debounce,function(){clearTimeout(i),i=setTimeout((function(){return e()}),n)}),u=t.events=r({input:r({},o&&o.input)},t.resultsList&&{list:o?r({},o.list):{}}),a={input:{input:function(){s()},keydown:function(e){!function(t,e){switch(t.keyCode){case 40:case 38:t.preventDefault(),40===t.keyCode?A(e):S(e);break;case 13:e.submit||t.preventDefault(),e.cursor>=0&&j(e,t);break;case 9:e.resultsList.tabSelect&&e.cursor>=0&&j(e,t);break;case 27:e.input.value="",f("clear",e),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);i&&i.nodeName===n&&j(e,t,r.indexOf(i))}(e,t)}}};L(a,(function(e,n){(t.resultsList||"input"===n)&&(u[e][n]||(u[e][n]=a[e][n]))})),L(u,(function(e,n){t[e].addEventListener(n,u[e][n])}))};function E(t){var e=this;return new Promise((function(n,i){var o,s,u;if(o=t.placeHolder,u={role:"combobox","aria-owns":(s=t.resultsList).id,"aria-haspopup":!0,"aria-expanded":!1},a(t.input,r(r({"aria-controls":s.id,"aria-autocomplete":"both"},o&&{placeholder:o}),!t.wrapper&&r({},u))),t.wrapper&&(t.wrapper=a("div",r({around:t.input,class:t.name+"_wrapper"},u))),s&&(t.list=a(s.tag,r({dest:[s.destination,s.position],id:s.id,role:"listbox",hidden:"hidden"},s.class&&{class:s.class}))),T(t),t.data.cache)return d(t).then((function(t){try{return c.call(e)}catch(t){return i(t)}}),i);function c(){return f("init",t),n()}return c.call(e)}))}function P(t){var e=t.prototype;e.init=function(){E(this)},e.start=function(t){k(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;L((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(){S(this)},e.select=function(t){j(this,null,t)},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,n=t.options,r=t.resultsList,i=t.resultItem;for(var s in n)if("object"===o(n[s]))for(var a in t[s]||(t[s]={}),n[s])t[s][a]=n[s][a];else t[s]=n[s];t.selector=t.selector||"#"+e,r.destination=r.destination||t.selector,r.id=r.id||e+"_list_"+t.id,i.id=i.id||e+"_result",t.input=u(t.selector)}(this),P.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();
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "10.2.
|
|
2
|
+
"version": "10.2.8",
|
|
3
3
|
"name": "@tarekraafat/autocomplete.js",
|
|
4
4
|
"description": "Simple autocomplete pure vanilla Javascript library.",
|
|
5
5
|
"keywords": [
|
|
@@ -55,24 +55,25 @@
|
|
|
55
55
|
"dist",
|
|
56
56
|
"src"
|
|
57
57
|
],
|
|
58
|
+
"type": "module",
|
|
58
59
|
"main": "dist/autoComplete.js",
|
|
59
60
|
"browser": "dist/autoComplete.min.js",
|
|
60
61
|
"unpkg": "dist/autoComplete.min.js",
|
|
61
62
|
"module": "dist/autoComplete.min.js",
|
|
62
63
|
"devDependencies": {
|
|
63
|
-
"@babel/core": "^7.
|
|
64
|
-
"@babel/preset-env": "^7.
|
|
65
|
-
"@rollup/plugin-babel": "^
|
|
66
|
-
"
|
|
67
|
-
"
|
|
64
|
+
"@babel/core": "^7.18.6",
|
|
65
|
+
"@babel/preset-env": "^7.18.6",
|
|
66
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
67
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
68
|
+
"acorn": "^8.7.1",
|
|
69
|
+
"rollup": "^4.24.0",
|
|
68
70
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
69
71
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
70
|
-
"rollup-plugin-gzip": "^
|
|
71
|
-
"rollup-plugin-livereload": "^2.0.
|
|
72
|
+
"rollup-plugin-gzip": "^4.0.1",
|
|
73
|
+
"rollup-plugin-livereload": "^2.0.5",
|
|
72
74
|
"rollup-plugin-nodent": "^0.2.2",
|
|
73
|
-
"rollup-plugin-serve": "^1.1.
|
|
74
|
-
"rollup-plugin-sizes": "^1.0.4"
|
|
75
|
-
"rollup-plugin-terser": "^7.0.2"
|
|
75
|
+
"rollup-plugin-serve": "^1.1.1",
|
|
76
|
+
"rollup-plugin-sizes": "^1.0.4"
|
|
76
77
|
},
|
|
77
78
|
"scripts": {
|
|
78
79
|
"dev": "NODE_ENV=development rollup -c -w",
|
|
@@ -234,6 +235,14 @@
|
|
|
234
235
|
{
|
|
235
236
|
"name": "sunshineplan",
|
|
236
237
|
"url": "https://github.com/sunshineplan"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"name": "xJeneKx",
|
|
241
|
+
"url": "https://github.com/xJeneKx"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"name": "alan-rudzinski",
|
|
245
|
+
"url": "https://github.com/alan-rudzinski"
|
|
237
246
|
}
|
|
238
247
|
],
|
|
239
248
|
"maintainers": [
|
package/src/autoComplete.js
CHANGED
|
@@ -6,14 +6,15 @@ import init from "./services/init";
|
|
|
6
6
|
* @class autoComplete
|
|
7
7
|
* @classdesc Creates a new instance of autoComplete.js with the given configuration.
|
|
8
8
|
*
|
|
9
|
-
* @see {@link https://tarekraafat.github.io/autoComplete.js/#/configuration}
|
|
9
|
+
* @see {@link https://tarekraafat.github.io/autoComplete.js/#/configuration} for more information on configuration options.
|
|
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.
|
|
@@ -11,7 +11,12 @@ const getData = async (ctx, query) => {
|
|
|
11
11
|
|
|
12
12
|
if (data.cache && data.store) return;
|
|
13
13
|
|
|
14
|
-
ctx.feedback = data.store =
|
|
14
|
+
ctx.feedback = data.store =
|
|
15
|
+
typeof data.src === "function"
|
|
16
|
+
? data.src.constructor.name === "AsyncFunction"
|
|
17
|
+
? await data.src(query)
|
|
18
|
+
: data.src(query)
|
|
19
|
+
: data.src;
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
22
|
* @emit {response} event on data request
|
|
@@ -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