@algolia/autocomplete-plugin-recent-searches 1.3.0 → 1.5.1
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/dist/esm/addHighlightedAttribute.js +1 -1
- package/dist/esm/createLocalStorage.js +1 -1
- package/dist/esm/createLocalStorageRecentSearchesPlugin.d.ts +1 -1
- package/dist/esm/createLocalStorageRecentSearchesPlugin.js +30 -9
- package/dist/esm/createRecentSearchesPlugin.d.ts +1 -1
- package/dist/esm/createRecentSearchesPlugin.js +29 -20
- package/dist/esm/types/Highlighted.js +1 -0
- package/dist/esm/types/HistoryItem.js +1 -0
- package/dist/esm/types/RecentSearchesItem.js +1 -0
- package/dist/esm/types/Storage.js +1 -0
- package/dist/esm/types/StorageApi.js +1 -0
- package/dist/umd/index.development.js +79 -51
- package/dist/umd/index.development.js.map +1 -1
- package/dist/umd/index.production.js +2 -2
- package/dist/umd/index.production.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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; }
|
|
1
|
+
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; }
|
|
2
2
|
|
|
3
3
|
function _objectSpread(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; }
|
|
4
4
|
|
|
@@ -4,7 +4,7 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
|
|
|
4
4
|
|
|
5
5
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
6
|
|
|
7
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
8
|
|
|
9
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
10
|
|
|
@@ -34,5 +34,5 @@ export declare type CreateRecentSearchesLocalStorageOptions<TItem extends Recent
|
|
|
34
34
|
search?(params: SearchParams<TItem>): Array<Highlighted<TItem>>;
|
|
35
35
|
};
|
|
36
36
|
declare type LocalStorageRecentSearchesPluginOptions<TItem extends RecentSearchesItem> = Pick<CreateRecentSearchesPluginParams<TItem>, 'transformSource' | 'subscribe'> & CreateRecentSearchesLocalStorageOptions<TItem>;
|
|
37
|
-
export declare function createLocalStorageRecentSearchesPlugin<TItem extends RecentSearchesItem>(
|
|
37
|
+
export declare function createLocalStorageRecentSearchesPlugin<TItem extends RecentSearchesItem>(options: LocalStorageRecentSearchesPluginOptions<TItem>): AutocompletePlugin<TItem, RecentSearchesPluginData<TItem>>;
|
|
38
38
|
export {};
|
|
@@ -1,23 +1,44 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(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; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
1
7
|
import { LOCAL_STORAGE_KEY } from './constants';
|
|
2
8
|
import { createLocalStorage } from './createLocalStorage';
|
|
3
9
|
import { createRecentSearchesPlugin } from './createRecentSearchesPlugin';
|
|
4
10
|
import { search as defaultSearch } from './search';
|
|
5
|
-
export function createLocalStorageRecentSearchesPlugin(
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
limit =
|
|
9
|
-
transformSource =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export function createLocalStorageRecentSearchesPlugin(options) {
|
|
12
|
+
var _getOptions = getOptions(options),
|
|
13
|
+
key = _getOptions.key,
|
|
14
|
+
limit = _getOptions.limit,
|
|
15
|
+
transformSource = _getOptions.transformSource,
|
|
16
|
+
search = _getOptions.search,
|
|
17
|
+
subscribe = _getOptions.subscribe;
|
|
18
|
+
|
|
13
19
|
var storage = createLocalStorage({
|
|
14
20
|
key: [LOCAL_STORAGE_KEY, key].join(':'),
|
|
15
21
|
limit: limit,
|
|
16
22
|
search: search
|
|
17
23
|
});
|
|
18
|
-
|
|
24
|
+
var recentSearchesPlugin = createRecentSearchesPlugin({
|
|
19
25
|
transformSource: transformSource,
|
|
20
26
|
storage: storage,
|
|
21
27
|
subscribe: subscribe
|
|
22
28
|
});
|
|
29
|
+
return _objectSpread(_objectSpread({}, recentSearchesPlugin), {}, {
|
|
30
|
+
name: 'aa.localStorageRecentSearchesPlugin',
|
|
31
|
+
__autocomplete_pluginOptions: options
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getOptions(options) {
|
|
36
|
+
return _objectSpread({
|
|
37
|
+
limit: 5,
|
|
38
|
+
search: defaultSearch,
|
|
39
|
+
transformSource: function transformSource(_ref) {
|
|
40
|
+
var source = _ref.source;
|
|
41
|
+
return source;
|
|
42
|
+
}
|
|
43
|
+
}, options);
|
|
23
44
|
}
|
|
@@ -33,4 +33,4 @@ export declare type CreateRecentSearchesPluginParams<TItem extends RecentSearche
|
|
|
33
33
|
}): AutocompleteSource<TItem>;
|
|
34
34
|
subscribe?(params: PluginSubscribeParams<TItem>): void;
|
|
35
35
|
};
|
|
36
|
-
export declare function createRecentSearchesPlugin<TItem extends RecentSearchesItem>(
|
|
36
|
+
export declare function createRecentSearchesPlugin<TItem extends RecentSearchesItem>(options: CreateRecentSearchesPluginParams<TItem>): AutocompletePlugin<TItem, RecentSearchesPluginData<TItem>>;
|
|
@@ -4,13 +4,13 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
|
|
|
4
4
|
|
|
5
5
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
6
|
|
|
7
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
8
|
|
|
9
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
10
|
|
|
11
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
12
12
|
|
|
13
|
-
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; }
|
|
13
|
+
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; }
|
|
14
14
|
|
|
15
15
|
function _objectSpread(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; }
|
|
16
16
|
|
|
@@ -44,20 +44,19 @@ function getDefaultSubcribe(store) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export function createRecentSearchesPlugin(
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
transformSource =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} : _ref3$transformSource,
|
|
54
|
-
subscribe = _ref3.subscribe;
|
|
47
|
+
export function createRecentSearchesPlugin(options) {
|
|
48
|
+
var _getOptions = getOptions(options),
|
|
49
|
+
storage = _getOptions.storage,
|
|
50
|
+
transformSource = _getOptions.transformSource,
|
|
51
|
+
subscribe = _getOptions.subscribe;
|
|
52
|
+
|
|
55
53
|
var store = createStorageApi(storage);
|
|
56
54
|
var lastItemsRef = createRef([]);
|
|
57
55
|
return {
|
|
56
|
+
name: 'aa.recentSearchesPlugin',
|
|
58
57
|
subscribe: subscribe !== null && subscribe !== void 0 ? subscribe : getDefaultSubcribe(store),
|
|
59
|
-
onSubmit: function onSubmit(
|
|
60
|
-
var state =
|
|
58
|
+
onSubmit: function onSubmit(_ref3) {
|
|
59
|
+
var state = _ref3.state;
|
|
61
60
|
var query = state.query;
|
|
62
61
|
|
|
63
62
|
if (query) {
|
|
@@ -68,11 +67,11 @@ export function createRecentSearchesPlugin(_ref3) {
|
|
|
68
67
|
store.addItem(recentItem);
|
|
69
68
|
}
|
|
70
69
|
},
|
|
71
|
-
getSources: function getSources(
|
|
72
|
-
var query =
|
|
73
|
-
setQuery =
|
|
74
|
-
refresh =
|
|
75
|
-
state =
|
|
70
|
+
getSources: function getSources(_ref4) {
|
|
71
|
+
var query = _ref4.query,
|
|
72
|
+
setQuery = _ref4.setQuery,
|
|
73
|
+
refresh = _ref4.refresh,
|
|
74
|
+
state = _ref4.state;
|
|
76
75
|
lastItemsRef.current = store.getAll(query);
|
|
77
76
|
|
|
78
77
|
function onRemove(id) {
|
|
@@ -93,8 +92,8 @@ export function createRecentSearchesPlugin(_ref3) {
|
|
|
93
92
|
return [transformSource({
|
|
94
93
|
source: {
|
|
95
94
|
sourceId: 'recentSearchesPlugin',
|
|
96
|
-
getItemInputValue: function getItemInputValue(
|
|
97
|
-
var item =
|
|
95
|
+
getItemInputValue: function getItemInputValue(_ref5) {
|
|
96
|
+
var item = _ref5.item;
|
|
98
97
|
return item.label;
|
|
99
98
|
},
|
|
100
99
|
getItems: function getItems() {
|
|
@@ -133,6 +132,16 @@ export function createRecentSearchesPlugin(_ref3) {
|
|
|
133
132
|
hitsPerPage: Math.max(1, ((_params$hitsPerPage = params.hitsPerPage) !== null && _params$hitsPerPage !== void 0 ? _params$hitsPerPage : 10) - lastItemsRef.current.length)
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
|
-
})
|
|
135
|
+
}),
|
|
136
|
+
__autocomplete_pluginOptions: options
|
|
137
137
|
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getOptions(options) {
|
|
141
|
+
return _objectSpread({
|
|
142
|
+
transformSource: function transformSource(_ref6) {
|
|
143
|
+
var source = _ref6.source;
|
|
144
|
+
return source;
|
|
145
|
+
}
|
|
146
|
+
}, options);
|
|
138
147
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,33 +1,22 @@
|
|
|
1
|
-
/*! @algolia/autocomplete-plugin-recent-searches 1.
|
|
1
|
+
/*! @algolia/autocomplete-plugin-recent-searches 1.5.1 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
5
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global[
|
|
6
|
-
}(this, (function (exports) { 'use strict';
|
|
7
|
-
|
|
8
|
-
function _defineProperty(obj, key, value) {
|
|
9
|
-
if (key in obj) {
|
|
10
|
-
Object.defineProperty(obj, key, {
|
|
11
|
-
value: value,
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true
|
|
15
|
-
});
|
|
16
|
-
} else {
|
|
17
|
-
obj[key] = value;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return obj;
|
|
21
|
-
}
|
|
5
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@algolia/autocomplete-plugin-recent-searches"] = {}));
|
|
6
|
+
})(this, (function (exports) { 'use strict';
|
|
22
7
|
|
|
23
8
|
function ownKeys(object, enumerableOnly) {
|
|
24
9
|
var keys = Object.keys(object);
|
|
25
10
|
|
|
26
11
|
if (Object.getOwnPropertySymbols) {
|
|
27
12
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
|
|
14
|
+
if (enumerableOnly) {
|
|
15
|
+
symbols = symbols.filter(function (sym) {
|
|
16
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
31
20
|
keys.push.apply(keys, symbols);
|
|
32
21
|
}
|
|
33
22
|
|
|
@@ -54,6 +43,21 @@
|
|
|
54
43
|
return target;
|
|
55
44
|
}
|
|
56
45
|
|
|
46
|
+
function _defineProperty(obj, key, value) {
|
|
47
|
+
if (key in obj) {
|
|
48
|
+
Object.defineProperty(obj, key, {
|
|
49
|
+
value: value,
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
obj[key] = value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return obj;
|
|
59
|
+
}
|
|
60
|
+
|
|
57
61
|
function _toConsumableArray(arr) {
|
|
58
62
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
59
63
|
}
|
|
@@ -63,7 +67,7 @@
|
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
function _iterableToArray(iter) {
|
|
66
|
-
if (typeof Symbol !== "undefined" && Symbol.iterator
|
|
70
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
function _unsupportedIterableToArray(o, minLen) {
|
|
@@ -299,20 +303,19 @@
|
|
|
299
303
|
};
|
|
300
304
|
}
|
|
301
305
|
|
|
302
|
-
function createRecentSearchesPlugin(
|
|
303
|
-
var
|
|
304
|
-
|
|
305
|
-
transformSource =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
} : _ref3$transformSource,
|
|
309
|
-
subscribe = _ref3.subscribe;
|
|
306
|
+
function createRecentSearchesPlugin(options) {
|
|
307
|
+
var _getOptions = getOptions$1(options),
|
|
308
|
+
storage = _getOptions.storage,
|
|
309
|
+
transformSource = _getOptions.transformSource,
|
|
310
|
+
subscribe = _getOptions.subscribe;
|
|
311
|
+
|
|
310
312
|
var store = createStorageApi(storage);
|
|
311
313
|
var lastItemsRef = createRef([]);
|
|
312
314
|
return {
|
|
315
|
+
name: 'aa.recentSearchesPlugin',
|
|
313
316
|
subscribe: subscribe !== null && subscribe !== void 0 ? subscribe : getDefaultSubcribe(store),
|
|
314
|
-
onSubmit: function onSubmit(
|
|
315
|
-
var state =
|
|
317
|
+
onSubmit: function onSubmit(_ref3) {
|
|
318
|
+
var state = _ref3.state;
|
|
316
319
|
var query = state.query;
|
|
317
320
|
|
|
318
321
|
if (query) {
|
|
@@ -323,11 +326,11 @@
|
|
|
323
326
|
store.addItem(recentItem);
|
|
324
327
|
}
|
|
325
328
|
},
|
|
326
|
-
getSources: function getSources(
|
|
327
|
-
var query =
|
|
328
|
-
setQuery =
|
|
329
|
-
refresh =
|
|
330
|
-
state =
|
|
329
|
+
getSources: function getSources(_ref4) {
|
|
330
|
+
var query = _ref4.query,
|
|
331
|
+
setQuery = _ref4.setQuery,
|
|
332
|
+
refresh = _ref4.refresh,
|
|
333
|
+
state = _ref4.state;
|
|
331
334
|
lastItemsRef.current = store.getAll(query);
|
|
332
335
|
|
|
333
336
|
function onRemove(id) {
|
|
@@ -348,8 +351,8 @@
|
|
|
348
351
|
return [transformSource({
|
|
349
352
|
source: {
|
|
350
353
|
sourceId: 'recentSearchesPlugin',
|
|
351
|
-
getItemInputValue: function getItemInputValue(
|
|
352
|
-
var item =
|
|
354
|
+
getItemInputValue: function getItemInputValue(_ref5) {
|
|
355
|
+
var item = _ref5.item;
|
|
353
356
|
return item.label;
|
|
354
357
|
},
|
|
355
358
|
getItems: function getItems() {
|
|
@@ -388,10 +391,20 @@
|
|
|
388
391
|
hitsPerPage: Math.max(1, ((_params$hitsPerPage = params.hitsPerPage) !== null && _params$hitsPerPage !== void 0 ? _params$hitsPerPage : 10) - lastItemsRef.current.length)
|
|
389
392
|
});
|
|
390
393
|
}
|
|
391
|
-
})
|
|
394
|
+
}),
|
|
395
|
+
__autocomplete_pluginOptions: options
|
|
392
396
|
};
|
|
393
397
|
}
|
|
394
398
|
|
|
399
|
+
function getOptions$1(options) {
|
|
400
|
+
return _objectSpread2({
|
|
401
|
+
transformSource: function transformSource(_ref6) {
|
|
402
|
+
var source = _ref6.source;
|
|
403
|
+
return source;
|
|
404
|
+
}
|
|
405
|
+
}, options);
|
|
406
|
+
}
|
|
407
|
+
|
|
395
408
|
function search(_ref) {
|
|
396
409
|
var query = _ref.query,
|
|
397
410
|
items = _ref.items,
|
|
@@ -416,24 +429,39 @@
|
|
|
416
429
|
});
|
|
417
430
|
}
|
|
418
431
|
|
|
419
|
-
function createLocalStorageRecentSearchesPlugin(
|
|
420
|
-
var
|
|
421
|
-
|
|
422
|
-
limit =
|
|
423
|
-
transformSource =
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
432
|
+
function createLocalStorageRecentSearchesPlugin(options) {
|
|
433
|
+
var _getOptions = getOptions(options),
|
|
434
|
+
key = _getOptions.key,
|
|
435
|
+
limit = _getOptions.limit,
|
|
436
|
+
transformSource = _getOptions.transformSource,
|
|
437
|
+
search = _getOptions.search,
|
|
438
|
+
subscribe = _getOptions.subscribe;
|
|
439
|
+
|
|
427
440
|
var storage = createLocalStorage({
|
|
428
441
|
key: [LOCAL_STORAGE_KEY, key].join(':'),
|
|
429
442
|
limit: limit,
|
|
430
|
-
search: search
|
|
443
|
+
search: search
|
|
431
444
|
});
|
|
432
|
-
|
|
445
|
+
var recentSearchesPlugin = createRecentSearchesPlugin({
|
|
433
446
|
transformSource: transformSource,
|
|
434
447
|
storage: storage,
|
|
435
448
|
subscribe: subscribe
|
|
436
449
|
});
|
|
450
|
+
return _objectSpread2(_objectSpread2({}, recentSearchesPlugin), {}, {
|
|
451
|
+
name: 'aa.localStorageRecentSearchesPlugin',
|
|
452
|
+
__autocomplete_pluginOptions: options
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function getOptions(options) {
|
|
457
|
+
return _objectSpread2({
|
|
458
|
+
limit: 5,
|
|
459
|
+
search: search,
|
|
460
|
+
transformSource: function transformSource(_ref) {
|
|
461
|
+
var source = _ref.source;
|
|
462
|
+
return source;
|
|
463
|
+
}
|
|
464
|
+
}, options);
|
|
437
465
|
}
|
|
438
466
|
|
|
439
467
|
exports.addHighlightedAttribute = addHighlightedAttribute;
|
|
@@ -444,5 +472,5 @@
|
|
|
444
472
|
|
|
445
473
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
446
474
|
|
|
447
|
-
}))
|
|
475
|
+
}));
|
|
448
476
|
//# sourceMappingURL=index.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.development.js","sources":["../../src/addHighlightedAttribute.ts","../../src/constants.ts","../../src/getLocalStorage.ts","../../src/createLocalStorage.ts","../../../autocomplete-shared/dist/esm/createRef.js","../../../autocomplete-shared/dist/esm/warn.js","../../src/createStorageApi.ts","../../src/getTemplates.tsx","../../src/createRecentSearchesPlugin.ts","../../src/search.ts","../../src/createLocalStorageRecentSearchesPlugin.ts"],"sourcesContent":["import { Highlighted, HistoryItem } from './types';\n\ntype HighlightParams<TItem> = {\n item: TItem;\n query: string;\n};\n\nexport function addHighlightedAttribute<TItem extends HistoryItem>({\n item,\n query,\n}: HighlightParams<TItem>): Highlighted<TItem> {\n return {\n ...item,\n _highlightResult: {\n label: {\n value: query\n ? item.label.replace(\n new RegExp(query.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'), 'gi'),\n (match) => {\n return `__aa-highlight__${match}__/aa-highlight__`;\n }\n )\n : item.label,\n },\n },\n };\n}\n","export const LOCAL_STORAGE_KEY = 'AUTOCOMPLETE_RECENT_SEARCHES';\nexport const LOCAL_STORAGE_KEY_TEST =\n '__AUTOCOMPLETE_RECENT_SEARCHES_PLUGIN_TEST_KEY__';\n","import { LOCAL_STORAGE_KEY_TEST } from './constants';\n\nfunction isLocalStorageSupported() {\n try {\n localStorage.setItem(LOCAL_STORAGE_KEY_TEST, '');\n localStorage.removeItem(LOCAL_STORAGE_KEY_TEST);\n\n return true;\n } catch (error) {\n return false;\n }\n}\n\ntype LocalStorageProps = {\n key: string;\n};\n\nexport function getLocalStorage<TItem>({ key }: LocalStorageProps) {\n if (!isLocalStorageSupported()) {\n return {\n setItem() {},\n getItem() {\n return [];\n },\n };\n }\n\n return {\n setItem(items: TItem[]) {\n return window.localStorage.setItem(key, JSON.stringify(items));\n },\n getItem(): TItem[] {\n const items = window.localStorage.getItem(key);\n\n return items ? (JSON.parse(items) as TItem[]) : [];\n },\n };\n}\n","import { CreateRecentSearchesLocalStorageOptions } from './createLocalStorageRecentSearchesPlugin';\nimport { getLocalStorage } from './getLocalStorage';\nimport { HistoryItem, Storage } from './types';\n\nexport type CreateLocalStorageProps<TItem extends HistoryItem> = Required<\n CreateRecentSearchesLocalStorageOptions<TItem>\n>;\n\nexport function createLocalStorage<TItem extends HistoryItem>({\n key,\n limit,\n search,\n}: CreateLocalStorageProps<TItem>): Storage<TItem> {\n const storage = getLocalStorage<TItem>({ key });\n\n return {\n onAdd(item) {\n storage.setItem([item, ...storage.getItem()]);\n },\n onRemove(id) {\n storage.setItem(storage.getItem().filter((x) => x.id !== id));\n },\n getAll(query = '') {\n return search({ query, items: storage.getItem(), limit }).slice(0, limit);\n },\n };\n}\n","export function createRef(initialValue) {\n return {\n current: initialValue\n };\n}","export var warnCache = {\n current: {}\n};\n/**\n * Logs a warning if the condition is not met.\n * This is used to log issues in development environment only.\n */\n\nexport function warn(condition, message) {\n if (!(process.env.NODE_ENV !== 'production')) {\n return;\n }\n\n if (condition) {\n return;\n }\n\n var sanitizedMessage = message.trim();\n var hasAlreadyPrinted = warnCache.current[sanitizedMessage];\n\n if (!hasAlreadyPrinted) {\n warnCache.current[sanitizedMessage] = true; // eslint-disable-next-line no-console\n\n console.warn(\"[Autocomplete] \".concat(sanitizedMessage));\n }\n}","import { HistoryItem, Storage, StorageApi } from './types';\n\nexport function createStorageApi<TItem extends HistoryItem>(\n storage: Storage<TItem>\n): StorageApi<TItem> {\n return {\n addItem(item) {\n storage.onRemove(item.id);\n storage.onAdd(item);\n },\n removeItem(id) {\n storage.onRemove(id);\n },\n getAll(query) {\n return storage.getAll(query);\n },\n };\n}\n","/** @jsx createElement */\nimport { SourceTemplates } from '@algolia/autocomplete-js';\n\nimport { RecentSearchesItem } from './types';\n\nexport type GetTemplatesParams<TItem extends RecentSearchesItem> = {\n onRemove(id: string): void;\n onTapAhead(item: TItem): void;\n};\n\nexport function getTemplates<TItem extends RecentSearchesItem>({\n onRemove,\n onTapAhead,\n}: GetTemplatesParams<TItem>): SourceTemplates<TItem> {\n return {\n item({ item, createElement, components }) {\n return (\n <div className=\"aa-ItemWrapper\">\n <div className=\"aa-ItemContent\">\n <div className=\"aa-ItemIcon aa-ItemIcon--noBorder\">\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M12.516 6.984v5.25l4.5 2.672-0.75 1.266-5.25-3.188v-6h1.5zM12 20.016q3.281 0 5.648-2.367t2.367-5.648-2.367-5.648-5.648-2.367-5.648 2.367-2.367 5.648 2.367 5.648 5.648 2.367zM12 2.016q4.125 0 7.055 2.93t2.93 7.055-2.93 7.055-7.055 2.93-7.055-2.93-2.93-7.055 2.93-7.055 7.055-2.93z\" />\n </svg>\n </div>\n <div className=\"aa-ItemContentBody\">\n <div className=\"aa-ItemContentTitle\">\n <components.ReverseHighlight hit={item} attribute=\"label\" />\n {item.category && (\n <span className=\"aa-ItemContentSubtitle aa-ItemContentSubtitle--inline\">\n <span className=\"aa-ItemContentSubtitleIcon\" /> in{' '}\n <span className=\"aa-ItemContentSubtitleCategory\">\n {item.category}\n </span>\n </span>\n )}\n </div>\n </div>\n </div>\n <div className=\"aa-ItemActions\">\n <button\n className=\"aa-ItemActionButton\"\n title=\"Remove this search\"\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onRemove(item.id);\n }}\n >\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z\" />\n </svg>\n </button>\n <button\n className=\"aa-ItemActionButton\"\n title={`Fill query with \"${item.label}\"`}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onTapAhead(item);\n }}\n >\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z\" />\n </svg>\n </button>\n </div>\n </div>\n );\n },\n };\n}\n","import { PluginSubscribeParams } from '@algolia/autocomplete-core';\nimport {\n AutocompleteSource,\n AutocompleteState,\n AutocompletePlugin,\n} from '@algolia/autocomplete-js';\nimport { createRef, MaybePromise, warn } from '@algolia/autocomplete-shared';\nimport { SearchOptions } from '@algolia/client-search';\n\nimport { createStorageApi } from './createStorageApi';\nimport { getTemplates } from './getTemplates';\nimport { RecentSearchesItem, Storage, StorageApi } from './types';\n\nexport interface RecentSearchesPluginData<TItem extends RecentSearchesItem>\n extends StorageApi<TItem> {\n /**\n * Optimized [Algolia search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/). This is useful when using the plugin along with the [Query Suggestions](createQuerySuggestionsPlugin) plugin.\n *\n * This function enhances the provided search parameters by:\n * - Excluding Query Suggestions that are already displayed in recent searches.\n * - Using a shared `hitsPerPage` value to get a group limit of Query Suggestions and recent searches.\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-getalgoliasearchparams\n */\n getAlgoliaSearchParams(params?: SearchOptions): SearchOptions;\n}\n\nexport type CreateRecentSearchesPluginParams<\n TItem extends RecentSearchesItem\n> = {\n /**\n * The storage to fetch from and save recent searches into.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-storage\n */\n storage: Storage<TItem>;\n /**\n * A function to transform the provided source.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-transformsource\n */\n transformSource?(params: {\n source: AutocompleteSource<TItem>;\n state: AutocompleteState<TItem>;\n onRemove(id: string): void;\n onTapAhead(item: TItem): void;\n }): AutocompleteSource<TItem>;\n subscribe?(params: PluginSubscribeParams<TItem>): void;\n};\n\nfunction getDefaultSubcribe<TItem extends RecentSearchesItem>(\n store: StorageApi<TItem>\n) {\n return function subscribe({ onSelect }: PluginSubscribeParams<TItem>) {\n onSelect(({ item, state, source }) => {\n const inputValue = source.getItemInputValue({ item, state });\n\n if (source.sourceId === 'querySuggestionsPlugin' && inputValue) {\n const recentItem: RecentSearchesItem = {\n id: inputValue,\n label: inputValue,\n category: (item as any).__autocomplete_qsCategory,\n };\n store.addItem(recentItem as TItem);\n }\n });\n };\n}\n\nexport function createRecentSearchesPlugin<TItem extends RecentSearchesItem>({\n storage,\n transformSource = ({ source }) => source,\n subscribe,\n}: CreateRecentSearchesPluginParams<TItem>): AutocompletePlugin<\n TItem,\n RecentSearchesPluginData<TItem>\n> {\n const store = createStorageApi<TItem>(storage);\n const lastItemsRef = createRef<MaybePromise<TItem[]>>([]);\n\n return {\n subscribe: subscribe ?? getDefaultSubcribe(store),\n onSubmit({ state }) {\n const { query } = state;\n\n if (query) {\n const recentItem: RecentSearchesItem = {\n id: query,\n label: query,\n };\n store.addItem(recentItem as TItem);\n }\n },\n getSources({ query, setQuery, refresh, state }) {\n lastItemsRef.current = store.getAll(query);\n\n function onRemove(id: string) {\n store.removeItem(id);\n refresh();\n }\n\n function onTapAhead(item: TItem) {\n setQuery(item.label);\n refresh();\n }\n\n return Promise.resolve(lastItemsRef.current).then((items) => {\n if (items.length === 0) {\n return [];\n }\n\n return [\n transformSource({\n source: {\n sourceId: 'recentSearchesPlugin',\n getItemInputValue({ item }) {\n return item.label;\n },\n getItems() {\n return items;\n },\n templates: getTemplates({ onRemove, onTapAhead }),\n },\n onRemove,\n onTapAhead,\n state: state as AutocompleteState<TItem>,\n }),\n ];\n });\n },\n data: {\n ...store,\n // @ts-ignore SearchOptions `facetFilters` is ReadonlyArray\n getAlgoliaSearchParams(params = {}) {\n // If the items returned by `store.getAll` are contained in a Promise,\n // we cannot provide the search params in time when this function is called\n // because we need to resolve the promise before getting the value.\n if (!Array.isArray(lastItemsRef.current)) {\n warn(\n false,\n 'The `getAlgoliaSearchParams` function is not supported with storages that return promises in `getAll`.'\n );\n return params;\n }\n\n return {\n ...params,\n facetFilters: [\n ...(params.facetFilters ?? []),\n // @TODO: we need to base the filter on the `query` attribute, not\n // `objectID`, because the Query Suggestions index cannot ensure\n // that the `objectID` will always be equal to the query.\n ...lastItemsRef.current.map((item) => [`objectID:-${item.label}`]),\n ],\n hitsPerPage: Math.max(\n 1,\n (params.hitsPerPage ?? 10) - lastItemsRef.current.length\n ),\n };\n },\n },\n };\n}\n","import { addHighlightedAttribute } from './addHighlightedAttribute';\nimport { Highlighted, RecentSearchesItem } from './types';\n\nexport type SearchParams<TItem extends RecentSearchesItem> = {\n query: string;\n items: TItem[];\n limit: number;\n};\n\nexport function search<TItem extends RecentSearchesItem>({\n query,\n items,\n limit,\n}: SearchParams<TItem>): Array<Highlighted<TItem>> {\n if (!query) {\n return items\n .slice(0, limit)\n .map((item) => addHighlightedAttribute({ item, query }));\n }\n\n return items\n .filter((item) => item.label.toLowerCase().includes(query.toLowerCase()))\n .slice(0, limit)\n .map((item) => addHighlightedAttribute({ item, query }));\n}\n","import { AutocompletePlugin } from '@algolia/autocomplete-js';\n\nimport { LOCAL_STORAGE_KEY } from './constants';\nimport { createLocalStorage } from './createLocalStorage';\nimport {\n createRecentSearchesPlugin,\n CreateRecentSearchesPluginParams,\n RecentSearchesPluginData,\n} from './createRecentSearchesPlugin';\nimport { search as defaultSearch, SearchParams } from './search';\nimport { Highlighted, RecentSearchesItem } from './types';\n\nexport type CreateRecentSearchesLocalStorageOptions<\n TItem extends RecentSearchesItem\n> = {\n /**\n * A local storage key to identify where to save and retrieve the recent searches.\n *\n * For example:\n * - \"navbar\"\n * - \"search\"\n * - \"main\"\n *\n * The plugin namespaces all keys to avoid collisions.\n *\n * @example \"top_searchbar\"\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-key\n */\n key: string;\n\n /**\n * The number of recent searches to display.\n *\n * @default 5\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-limit\n */\n limit?: number;\n\n /**\n * A search function to retrieve recent searches from.\n *\n * This function is called in [`storage.getAll`](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-storage) to retrieve recent searches and is useful to filter and highlight recent searches when typing a query.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-search\n */\n search?(params: SearchParams<TItem>): Array<Highlighted<TItem>>;\n};\n\ntype LocalStorageRecentSearchesPluginOptions<\n TItem extends RecentSearchesItem\n> = Pick<\n CreateRecentSearchesPluginParams<TItem>,\n 'transformSource' | 'subscribe'\n> &\n CreateRecentSearchesLocalStorageOptions<TItem>;\n\nexport function createLocalStorageRecentSearchesPlugin<\n TItem extends RecentSearchesItem\n>({\n key,\n limit = 5,\n transformSource,\n search = defaultSearch,\n subscribe,\n}: LocalStorageRecentSearchesPluginOptions<TItem>): AutocompletePlugin<\n TItem,\n RecentSearchesPluginData<TItem>\n> {\n const storage = createLocalStorage({\n key: [LOCAL_STORAGE_KEY, key].join(':'),\n limit,\n search,\n });\n\n return createRecentSearchesPlugin({\n transformSource,\n storage,\n subscribe,\n });\n}\n"],"names":["addHighlightedAttribute","item","query","_highlightResult","label","value","replace","RegExp","match","LOCAL_STORAGE_KEY","LOCAL_STORAGE_KEY_TEST","isLocalStorageSupported","localStorage","setItem","removeItem","error","getLocalStorage","key","getItem","items","window","JSON","stringify","parse","createLocalStorage","limit","search","storage","onAdd","onRemove","id","filter","x","getAll","slice","createRef","initialValue","current","warnCache","warn","condition","message","sanitizedMessage","trim","hasAlreadyPrinted","console","concat","createStorageApi","addItem","getTemplates","onTapAhead","createElement","components","category","event","preventDefault","stopPropagation","getDefaultSubcribe","store","subscribe","onSelect","state","source","inputValue","getItemInputValue","sourceId","recentItem","__autocomplete_qsCategory","createRecentSearchesPlugin","transformSource","lastItemsRef","onSubmit","getSources","setQuery","refresh","Promise","resolve","then","length","getItems","templates","data","getAlgoliaSearchParams","params","Array","isArray","process","facetFilters","map","hitsPerPage","Math","max","toLowerCase","includes","createLocalStorageRecentSearchesPlugin","defaultSearch","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOO,SAASA,uBAAT,OAGwC;EAAA,MAF7CC,IAE6C,QAF7CA,IAE6C;EAAA,MAD7CC,KAC6C,QAD7CA,KAC6C;EAC7C,2CACKD,IADL;EAEEE,IAAAA,gBAAgB,EAAE;EAChBC,MAAAA,KAAK,EAAE;EACLC,QAAAA,KAAK,EAAEH,KAAK,GACRD,IAAI,CAACG,KAAL,CAAWE,OAAX,CACE,IAAIC,MAAJ,CAAWL,KAAK,CAACI,OAAN,CAAc,uBAAd,EAAuC,MAAvC,CAAX,EAA2D,IAA3D,CADF,EAEE,UAACE,KAAD,EAAW;EACT,2CAA0BA,KAA1B;EACD,SAJH,CADQ,GAORP,IAAI,CAACG;EARJ;EADS;EAFpB;EAeD;;EC1BM,IAAMK,iBAAiB,GAAG,8BAA1B;EACA,IAAMC,sBAAsB,GACjC,kDADK;;ECCP,SAASC,uBAAT,GAAmC;EACjC,MAAI;EACFC,IAAAA,YAAY,CAACC,OAAb,CAAq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E,MAKT;EAAA,MAJApC,SAIA,QAJAA,SAIA;EACA,MAAMhC,OAAO,GAAGH,kBAAkB,CAAC;EACjCP,IAAAA,GAAG,EAAE,CAACR,iBAAD,EAAoBQ,GAApB,EAAyB+E,IAAzB,CAA8B,GAA9B,CAD4B;EAEjCvE,IAAAA,KAAK,EAALA,KAFiC;EAGjCC,IAAAA,MAAM,EAANA;EAHiC,GAAD,CAAlC;EAMA,SAAO0C,0BAA0B,CAAC;EAChCC,IAAAA,eAAe,EAAfA,eADgC;EAEhC1C,IAAAA,OAAO,EAAPA,OAFgC;EAGhCgC,IAAAA,SAAS,EAATA;EAHgC,GAAD,CAAjC;EAKD;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.development.js","sources":["../../src/addHighlightedAttribute.ts","../../src/constants.ts","../../src/getLocalStorage.ts","../../src/createLocalStorage.ts","../../../autocomplete-shared/dist/esm/createRef.js","../../../autocomplete-shared/dist/esm/warn.js","../../src/createStorageApi.ts","../../src/getTemplates.tsx","../../src/createRecentSearchesPlugin.ts","../../src/search.ts","../../src/createLocalStorageRecentSearchesPlugin.ts"],"sourcesContent":["import { Highlighted, HistoryItem } from './types';\n\ntype HighlightParams<TItem> = {\n item: TItem;\n query: string;\n};\n\nexport function addHighlightedAttribute<TItem extends HistoryItem>({\n item,\n query,\n}: HighlightParams<TItem>): Highlighted<TItem> {\n return {\n ...item,\n _highlightResult: {\n label: {\n value: query\n ? item.label.replace(\n new RegExp(query.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'), 'gi'),\n (match) => {\n return `__aa-highlight__${match}__/aa-highlight__`;\n }\n )\n : item.label,\n },\n },\n };\n}\n","export const LOCAL_STORAGE_KEY = 'AUTOCOMPLETE_RECENT_SEARCHES';\nexport const LOCAL_STORAGE_KEY_TEST =\n '__AUTOCOMPLETE_RECENT_SEARCHES_PLUGIN_TEST_KEY__';\n","import { LOCAL_STORAGE_KEY_TEST } from './constants';\n\nfunction isLocalStorageSupported() {\n try {\n localStorage.setItem(LOCAL_STORAGE_KEY_TEST, '');\n localStorage.removeItem(LOCAL_STORAGE_KEY_TEST);\n\n return true;\n } catch (error) {\n return false;\n }\n}\n\ntype LocalStorageProps = {\n key: string;\n};\n\nexport function getLocalStorage<TItem>({ key }: LocalStorageProps) {\n if (!isLocalStorageSupported()) {\n return {\n setItem() {},\n getItem() {\n return [];\n },\n };\n }\n\n return {\n setItem(items: TItem[]) {\n return window.localStorage.setItem(key, JSON.stringify(items));\n },\n getItem(): TItem[] {\n const items = window.localStorage.getItem(key);\n\n return items ? (JSON.parse(items) as TItem[]) : [];\n },\n };\n}\n","import { CreateRecentSearchesLocalStorageOptions } from './createLocalStorageRecentSearchesPlugin';\nimport { getLocalStorage } from './getLocalStorage';\nimport { HistoryItem, Storage } from './types';\n\nexport type CreateLocalStorageProps<TItem extends HistoryItem> = Required<\n CreateRecentSearchesLocalStorageOptions<TItem>\n>;\n\nexport function createLocalStorage<TItem extends HistoryItem>({\n key,\n limit,\n search,\n}: CreateLocalStorageProps<TItem>): Storage<TItem> {\n const storage = getLocalStorage<TItem>({ key });\n\n return {\n onAdd(item) {\n storage.setItem([item, ...storage.getItem()]);\n },\n onRemove(id) {\n storage.setItem(storage.getItem().filter((x) => x.id !== id));\n },\n getAll(query = '') {\n return search({ query, items: storage.getItem(), limit }).slice(0, limit);\n },\n };\n}\n","export function createRef(initialValue) {\n return {\n current: initialValue\n };\n}","export var warnCache = {\n current: {}\n};\n/**\n * Logs a warning if the condition is not met.\n * This is used to log issues in development environment only.\n */\n\nexport function warn(condition, message) {\n if (!(process.env.NODE_ENV !== 'production')) {\n return;\n }\n\n if (condition) {\n return;\n }\n\n var sanitizedMessage = message.trim();\n var hasAlreadyPrinted = warnCache.current[sanitizedMessage];\n\n if (!hasAlreadyPrinted) {\n warnCache.current[sanitizedMessage] = true; // eslint-disable-next-line no-console\n\n console.warn(\"[Autocomplete] \".concat(sanitizedMessage));\n }\n}","import { HistoryItem, Storage, StorageApi } from './types';\n\nexport function createStorageApi<TItem extends HistoryItem>(\n storage: Storage<TItem>\n): StorageApi<TItem> {\n return {\n addItem(item) {\n storage.onRemove(item.id);\n storage.onAdd(item);\n },\n removeItem(id) {\n storage.onRemove(id);\n },\n getAll(query) {\n return storage.getAll(query);\n },\n };\n}\n","/** @jsx createElement */\nimport { SourceTemplates } from '@algolia/autocomplete-js';\n\nimport { RecentSearchesItem } from './types';\n\nexport type GetTemplatesParams<TItem extends RecentSearchesItem> = {\n onRemove(id: string): void;\n onTapAhead(item: TItem): void;\n};\n\nexport function getTemplates<TItem extends RecentSearchesItem>({\n onRemove,\n onTapAhead,\n}: GetTemplatesParams<TItem>): SourceTemplates<TItem> {\n return {\n item({ item, createElement, components }) {\n return (\n <div className=\"aa-ItemWrapper\">\n <div className=\"aa-ItemContent\">\n <div className=\"aa-ItemIcon aa-ItemIcon--noBorder\">\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M12.516 6.984v5.25l4.5 2.672-0.75 1.266-5.25-3.188v-6h1.5zM12 20.016q3.281 0 5.648-2.367t2.367-5.648-2.367-5.648-5.648-2.367-5.648 2.367-2.367 5.648 2.367 5.648 5.648 2.367zM12 2.016q4.125 0 7.055 2.93t2.93 7.055-2.93 7.055-7.055 2.93-7.055-2.93-2.93-7.055 2.93-7.055 7.055-2.93z\" />\n </svg>\n </div>\n <div className=\"aa-ItemContentBody\">\n <div className=\"aa-ItemContentTitle\">\n <components.ReverseHighlight hit={item} attribute=\"label\" />\n {item.category && (\n <span className=\"aa-ItemContentSubtitle aa-ItemContentSubtitle--inline\">\n <span className=\"aa-ItemContentSubtitleIcon\" /> in{' '}\n <span className=\"aa-ItemContentSubtitleCategory\">\n {item.category}\n </span>\n </span>\n )}\n </div>\n </div>\n </div>\n <div className=\"aa-ItemActions\">\n <button\n className=\"aa-ItemActionButton\"\n title=\"Remove this search\"\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onRemove(item.id);\n }}\n >\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z\" />\n </svg>\n </button>\n <button\n className=\"aa-ItemActionButton\"\n title={`Fill query with \"${item.label}\"`}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onTapAhead(item);\n }}\n >\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z\" />\n </svg>\n </button>\n </div>\n </div>\n );\n },\n };\n}\n","import { PluginSubscribeParams } from '@algolia/autocomplete-core';\nimport {\n AutocompleteSource,\n AutocompleteState,\n AutocompletePlugin,\n} from '@algolia/autocomplete-js';\nimport { createRef, MaybePromise, warn } from '@algolia/autocomplete-shared';\nimport { SearchOptions } from '@algolia/client-search';\n\nimport { createStorageApi } from './createStorageApi';\nimport { getTemplates } from './getTemplates';\nimport { RecentSearchesItem, Storage, StorageApi } from './types';\n\nexport interface RecentSearchesPluginData<TItem extends RecentSearchesItem>\n extends StorageApi<TItem> {\n /**\n * Optimized [Algolia search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/). This is useful when using the plugin along with the [Query Suggestions](createQuerySuggestionsPlugin) plugin.\n *\n * This function enhances the provided search parameters by:\n * - Excluding Query Suggestions that are already displayed in recent searches.\n * - Using a shared `hitsPerPage` value to get a group limit of Query Suggestions and recent searches.\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-getalgoliasearchparams\n */\n getAlgoliaSearchParams(params?: SearchOptions): SearchOptions;\n}\n\nexport type CreateRecentSearchesPluginParams<\n TItem extends RecentSearchesItem\n> = {\n /**\n * The storage to fetch from and save recent searches into.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-storage\n */\n storage: Storage<TItem>;\n /**\n * A function to transform the provided source.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-transformsource\n */\n transformSource?(params: {\n source: AutocompleteSource<TItem>;\n state: AutocompleteState<TItem>;\n onRemove(id: string): void;\n onTapAhead(item: TItem): void;\n }): AutocompleteSource<TItem>;\n subscribe?(params: PluginSubscribeParams<TItem>): void;\n};\n\nfunction getDefaultSubcribe<TItem extends RecentSearchesItem>(\n store: StorageApi<TItem>\n) {\n return function subscribe({ onSelect }: PluginSubscribeParams<TItem>) {\n onSelect(({ item, state, source }) => {\n const inputValue = source.getItemInputValue({ item, state });\n\n if (source.sourceId === 'querySuggestionsPlugin' && inputValue) {\n const recentItem: RecentSearchesItem = {\n id: inputValue,\n label: inputValue,\n category: (item as any).__autocomplete_qsCategory,\n };\n store.addItem(recentItem as TItem);\n }\n });\n };\n}\n\nexport function createRecentSearchesPlugin<TItem extends RecentSearchesItem>(\n options: CreateRecentSearchesPluginParams<TItem>\n): AutocompletePlugin<TItem, RecentSearchesPluginData<TItem>> {\n const { storage, transformSource, subscribe } = getOptions(options);\n const store = createStorageApi<TItem>(storage);\n const lastItemsRef = createRef<MaybePromise<TItem[]>>([]);\n\n return {\n name: 'aa.recentSearchesPlugin',\n subscribe: subscribe ?? getDefaultSubcribe(store),\n onSubmit({ state }) {\n const { query } = state;\n\n if (query) {\n const recentItem: RecentSearchesItem = {\n id: query,\n label: query,\n };\n store.addItem(recentItem as TItem);\n }\n },\n getSources({ query, setQuery, refresh, state }) {\n lastItemsRef.current = store.getAll(query);\n\n function onRemove(id: string) {\n store.removeItem(id);\n refresh();\n }\n\n function onTapAhead(item: TItem) {\n setQuery(item.label);\n refresh();\n }\n\n return Promise.resolve(lastItemsRef.current).then((items) => {\n if (items.length === 0) {\n return [];\n }\n\n return [\n transformSource({\n source: {\n sourceId: 'recentSearchesPlugin',\n getItemInputValue({ item }) {\n return item.label;\n },\n getItems() {\n return items;\n },\n templates: getTemplates({ onRemove, onTapAhead }),\n },\n onRemove,\n onTapAhead,\n state: state as AutocompleteState<TItem>,\n }),\n ];\n });\n },\n data: {\n ...store,\n // @ts-ignore SearchOptions `facetFilters` is ReadonlyArray\n getAlgoliaSearchParams(params = {}) {\n // If the items returned by `store.getAll` are contained in a Promise,\n // we cannot provide the search params in time when this function is called\n // because we need to resolve the promise before getting the value.\n if (!Array.isArray(lastItemsRef.current)) {\n warn(\n false,\n 'The `getAlgoliaSearchParams` function is not supported with storages that return promises in `getAll`.'\n );\n return params;\n }\n\n return {\n ...params,\n facetFilters: [\n ...(params.facetFilters ?? []),\n // @TODO: we need to base the filter on the `query` attribute, not\n // `objectID`, because the Query Suggestions index cannot ensure\n // that the `objectID` will always be equal to the query.\n ...lastItemsRef.current.map((item) => [`objectID:-${item.label}`]),\n ],\n hitsPerPage: Math.max(\n 1,\n (params.hitsPerPage ?? 10) - lastItemsRef.current.length\n ),\n };\n },\n },\n __autocomplete_pluginOptions: options,\n };\n}\n\nfunction getOptions<TItem extends RecentSearchesItem>(\n options: CreateRecentSearchesPluginParams<TItem>\n) {\n return {\n transformSource: ({ source }) => source,\n ...options,\n };\n}\n","import { addHighlightedAttribute } from './addHighlightedAttribute';\nimport { Highlighted, RecentSearchesItem } from './types';\n\nexport type SearchParams<TItem extends RecentSearchesItem> = {\n query: string;\n items: TItem[];\n limit: number;\n};\n\nexport function search<TItem extends RecentSearchesItem>({\n query,\n items,\n limit,\n}: SearchParams<TItem>): Array<Highlighted<TItem>> {\n if (!query) {\n return items\n .slice(0, limit)\n .map((item) => addHighlightedAttribute({ item, query }));\n }\n\n return items\n .filter((item) => item.label.toLowerCase().includes(query.toLowerCase()))\n .slice(0, limit)\n .map((item) => addHighlightedAttribute({ item, query }));\n}\n","import { AutocompletePlugin } from '@algolia/autocomplete-js';\n\nimport { LOCAL_STORAGE_KEY } from './constants';\nimport { createLocalStorage } from './createLocalStorage';\nimport {\n createRecentSearchesPlugin,\n CreateRecentSearchesPluginParams,\n RecentSearchesPluginData,\n} from './createRecentSearchesPlugin';\nimport { search as defaultSearch, SearchParams } from './search';\nimport { Highlighted, RecentSearchesItem } from './types';\n\nexport type CreateRecentSearchesLocalStorageOptions<\n TItem extends RecentSearchesItem\n> = {\n /**\n * A local storage key to identify where to save and retrieve the recent searches.\n *\n * For example:\n * - \"navbar\"\n * - \"search\"\n * - \"main\"\n *\n * The plugin namespaces all keys to avoid collisions.\n *\n * @example \"top_searchbar\"\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-key\n */\n key: string;\n\n /**\n * The number of recent searches to display.\n *\n * @default 5\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-limit\n */\n limit?: number;\n\n /**\n * A search function to retrieve recent searches from.\n *\n * This function is called in [`storage.getAll`](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-storage) to retrieve recent searches and is useful to filter and highlight recent searches when typing a query.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-search\n */\n search?(params: SearchParams<TItem>): Array<Highlighted<TItem>>;\n};\n\ntype LocalStorageRecentSearchesPluginOptions<\n TItem extends RecentSearchesItem\n> = Pick<\n CreateRecentSearchesPluginParams<TItem>,\n 'transformSource' | 'subscribe'\n> &\n CreateRecentSearchesLocalStorageOptions<TItem>;\n\nexport function createLocalStorageRecentSearchesPlugin<\n TItem extends RecentSearchesItem\n>(\n options: LocalStorageRecentSearchesPluginOptions<TItem>\n): AutocompletePlugin<TItem, RecentSearchesPluginData<TItem>> {\n const { key, limit, transformSource, search, subscribe } = getOptions(\n options\n );\n const storage = createLocalStorage<TItem>({\n key: [LOCAL_STORAGE_KEY, key].join(':'),\n limit,\n search,\n });\n\n const recentSearchesPlugin = createRecentSearchesPlugin<TItem>({\n transformSource,\n storage,\n subscribe,\n });\n\n return {\n ...recentSearchesPlugin,\n name: 'aa.localStorageRecentSearchesPlugin',\n __autocomplete_pluginOptions: options,\n };\n}\n\nfunction getOptions<TItem extends RecentSearchesItem>(\n options: LocalStorageRecentSearchesPluginOptions<TItem>\n) {\n return {\n limit: 5,\n search: defaultSearch,\n transformSource: ({ source }) => source,\n ...options,\n };\n}\n"],"names":["addHighlightedAttribute","item","query","_highlightResult","label","value","replace","RegExp","match","LOCAL_STORAGE_KEY","LOCAL_STORAGE_KEY_TEST","isLocalStorageSupported","localStorage","setItem","removeItem","error","getLocalStorage","key","getItem","items","window","JSON","stringify","parse","createLocalStorage","limit","search","storage","onAdd","onRemove","id","filter","x","getAll","slice","createRef","initialValue","current","warnCache","warn","condition","message","sanitizedMessage","trim","hasAlreadyPrinted","console","concat","createStorageApi","addItem","getTemplates","onTapAhead","createElement","components","category","event","preventDefault","stopPropagation","getDefaultSubcribe","store","subscribe","onSelect","state","source","inputValue","getItemInputValue","sourceId","recentItem","__autocomplete_qsCategory","createRecentSearchesPlugin","options","getOptions","transformSource","lastItemsRef","name","onSubmit","getSources","setQuery","refresh","Promise","resolve","then","length","getItems","templates","data","getAlgoliaSearchParams","params","Array","isArray","process","facetFilters","map","hitsPerPage","Math","max","__autocomplete_pluginOptions","toLowerCase","includes","createLocalStorageRecentSearchesPlugin","join","recentSearchesPlugin","defaultSearch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOO,SAASA,uBAAT,OAGwC;EAAA,MAF7CC,IAE6C,QAF7CA,IAE6C;EAAA,MAD7CC,KAC6C,QAD7CA,KAC6C;EAC7C,2CACKD,IADL;EAEEE,IAAAA,gBAAgB,EAAE;EAChBC,MAAAA,KAAK,EAAE;EACLC,QAAAA,KAAK,EAAEH,KAAK,GACRD,IAAI,CAACG,KAAL,CAAWE,OAAX,CACE,IAAIC,MAAJ,CAAWL,KAAK,CAACI,OAAN,CAAc,uBAAd,EAAuC,MAAvC,CAAX,EAA2D,IAA3D,CADF,EAEE,UAACE,KAAD,EAAW;EACT,2CAA0BA,KAA1B;EACD,SAJH,CADQ,GAORP,IAAI,CAACG;EARJ;EADS;EAFpB;EAeD;;EC1BM,IAAMK,iBAAiB,GAAG,8BAA1B;EACA,IAAMC,sBAAsB,GACjC,kDADK;;ECCP,SAASC,uBAAT,GAAmC;EACjC,MAAI;EACFC,IAAAA,YAAY,CAACC,OAAb,CAAqBH,sBAArB,EAA6C,EAA7C;EACAE,IAAAA,YAAY,CAACE,UAAb,CAAwBJ,sBAAxB;EAEA,WAAO,IAAP;EACD,GALD,CAKE,O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E;EAAA,MAAQpD,GAAR,eAAQA,GAAR;EAAA,MAAaQ,KAAb,eAAaA,KAAb;EAAA,MAAoB8C,eAApB,eAAoBA,eAApB;EAAA,MAAqC7C,MAArC,eAAqCA,MAArC;EAAA,MAA6CiC,SAA7C,eAA6CA,SAA7C;;EAGA,MAAMhC,OAAO,GAAGH,kBAAkB,CAAQ;EACxCP,IAAAA,GAAG,EAAE,CAACR,iBAAD,EAAoBQ,GAApB,EAAyBkF,IAAzB,CAA8B,GAA9B,CADmC;EAExC1E,IAAAA,KAAK,EAALA,KAFwC;EAGxCC,IAAAA,MAAM,EAANA;EAHwC,GAAR,CAAlC;EAMA,MAAM0E,oBAAoB,GAAGhC,0BAA0B,CAAQ;EAC7DG,IAAAA,eAAe,EAAfA,eAD6D;EAE7D5C,IAAAA,OAAO,EAAPA,OAF6D;EAG7DgC,IAAAA,SAAS,EAATA;EAH6D,GAAR,CAAvD;EAMA,2CACKyC,oBADL;EAEE3B,IAAAA,IAAI,EAAE,qCAFR;EAGEsB,IAAAA,4BAA4B,EAAE1B;EAHhC;EAKD;;EAED,SAASC,UAAT,CACED,OADF,EAEE;EACA;EACE5C,IAAAA,KAAK,EAAE,CADT;EAEEC,IAAAA,MAAM,EAAE2E,MAFV;EAGE9B,IAAAA,eAAe,EAAE;EAAA,UAAGT,MAAH,QAAGA,MAAH;EAAA,aAAgBA,MAAhB;EAAA;EAHnB,KAIKO,OAJL;EAMD;;;;;;;;;;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! @algolia/autocomplete-plugin-recent-searches 1.
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/autocomplete-plugin-recent-searches"]={})}(this,(function(e){"use strict";function t(e,t
|
|
1
|
+
/*! @algolia/autocomplete-plugin-recent-searches 1.5.1 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/autocomplete-plugin-recent-searches"]={})}(this,(function(e){"use strict";function t(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 n(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return 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 o(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}(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 a(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}function i(e){var t=e.item,r=e.query;return n(n({},t),{},{_highlightResult:{label:{value:r?t.label.replace(new RegExp(r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),"gi"),(function(e){return"__aa-highlight__".concat(e,"__/aa-highlight__")})):t.label}}})}var c="AUTOCOMPLETE_RECENT_SEARCHES",u="__AUTOCOMPLETE_RECENT_SEARCHES_PLUGIN_TEST_KEY__";function l(e){var t=e.key;return function(){try{return localStorage.setItem(u,""),localStorage.removeItem(u),!0}catch(e){return!1}}()?{setItem:function(e){return window.localStorage.setItem(t,JSON.stringify(e))},getItem:function(){var e=window.localStorage.getItem(t);return e?JSON.parse(e):[]}}:{setItem:function(){},getItem:function(){return[]}}}function s(e){var t=e.onRemove,n=e.onTapAhead;return{item:function(e){var r=e.item,o=e.createElement,a=e.components;return o("div",{className:"aa-ItemWrapper"},o("div",{className:"aa-ItemContent"},o("div",{className:"aa-ItemIcon aa-ItemIcon--noBorder"},o("svg",{viewBox:"0 0 24 24",fill:"currentColor"},o("path",{d:"M12.516 6.984v5.25l4.5 2.672-0.75 1.266-5.25-3.188v-6h1.5zM12 20.016q3.281 0 5.648-2.367t2.367-5.648-2.367-5.648-5.648-2.367-5.648 2.367-2.367 5.648 2.367 5.648 5.648 2.367zM12 2.016q4.125 0 7.055 2.93t2.93 7.055-2.93 7.055-7.055 2.93-7.055-2.93-2.93-7.055 2.93-7.055 7.055-2.93z"}))),o("div",{className:"aa-ItemContentBody"},o("div",{className:"aa-ItemContentTitle"},o(a.ReverseHighlight,{hit:r,attribute:"label"}),r.category&&o("span",{className:"aa-ItemContentSubtitle aa-ItemContentSubtitle--inline"},o("span",{className:"aa-ItemContentSubtitleIcon"})," in"," ",o("span",{className:"aa-ItemContentSubtitleCategory"},r.category))))),o("div",{className:"aa-ItemActions"},o("button",{className:"aa-ItemActionButton",title:"Remove this search",onClick:function(e){e.preventDefault(),e.stopPropagation(),t(r.id)}},o("svg",{viewBox:"0 0 24 24",fill:"currentColor"},o("path",{d:"M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z"}))),o("button",{className:"aa-ItemActionButton",title:'Fill query with "'.concat(r.label,'"'),onClick:function(e){e.preventDefault(),e.stopPropagation(),n(r)}},o("svg",{viewBox:"0 0 24 24",fill:"currentColor"},o("path",{d:"M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z"})))))}}}function m(e){return function(t){(0,t.onSelect)((function(t){var n=t.item,r=t.state,o=t.source,a=o.getItemInputValue({item:n,state:r});if("querySuggestionsPlugin"===o.sourceId&&a){var i={id:a,label:a,category:n.__autocomplete_qsCategory};e.addItem(i)}}))}}function f(e){var t=function(e){return n({transformSource:function(e){return e.source}},e)}(e),r=t.storage,a=t.transformSource,i=t.subscribe,c=function(e){return{addItem:function(t){e.onRemove(t.id),e.onAdd(t)},removeItem:function(t){e.onRemove(t)},getAll:function(t){return e.getAll(t)}}}(r),u={current:[]};return{name:"aa.recentSearchesPlugin",subscribe:null!=i?i:m(c),onSubmit:function(e){var t=e.state.query;if(t){var n={id:t,label:t};c.addItem(n)}},getSources:function(e){var t=e.query,n=e.setQuery,r=e.refresh,o=e.state;function i(e){c.removeItem(e),r()}function l(e){n(e.label),r()}return u.current=c.getAll(t),Promise.resolve(u.current).then((function(e){return 0===e.length?[]:[a({source:{sourceId:"recentSearchesPlugin",getItemInputValue:function(e){return e.item.label},getItems:function(){return e},templates:s({onRemove:i,onTapAhead:l})},onRemove:i,onTapAhead:l,state:o})]}))},data:n(n({},c),{},{getAlgoliaSearchParams:function(){var e,t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Array.isArray(u.current)?n(n({},r),{},{facetFilters:[].concat(o(null!==(e=r.facetFilters)&&void 0!==e?e:[]),o(u.current.map((function(e){return["objectID:-".concat(e.label)]})))),hitsPerPage:Math.max(1,(null!==(t=r.hitsPerPage)&&void 0!==t?t:10)-u.current.length)}):r}}),__autocomplete_pluginOptions:e}}function g(e){var t=e.query,n=e.items,r=e.limit;return t?n.filter((function(e){return e.label.toLowerCase().includes(t.toLowerCase())})).slice(0,r).map((function(e){return i({item:e,query:t})})):n.slice(0,r).map((function(e){return i({item:e,query:t})}))}function v(e){return n({limit:5,search:g,transformSource:function(e){return e.source}},e)}e.addHighlightedAttribute=i,e.createLocalStorageRecentSearchesPlugin=function(e){var t=v(e),r=t.key,a=t.limit,i=t.transformSource,u=t.search,s=t.subscribe,m=function(e){var t=e.key,n=e.limit,r=e.search,a=l({key:t});return{onAdd:function(e){a.setItem([e].concat(o(a.getItem())))},onRemove:function(e){a.setItem(a.getItem().filter((function(t){return t.id!==e})))},getAll:function(){return r({query:arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",items:a.getItem(),limit:n}).slice(0,n)}}}({key:[c,r].join(":"),limit:a,search:u});return n(n({},f({transformSource:i,storage:m,subscribe:s})),{},{name:"aa.localStorageRecentSearchesPlugin",__autocomplete_pluginOptions:e})},e.createRecentSearchesPlugin=f,e.getTemplates=s,e.search=g,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
3
3
|
//# sourceMappingURL=index.production.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../src/addHighlightedAttribute.ts","../../src/constants.ts","../../src/getLocalStorage.ts","../../src/getTemplates.tsx","../../src/createRecentSearchesPlugin.ts","../../src/createStorageApi.ts","../../../autocomplete-shared/dist/esm/createRef.js","../../src/search.ts","../../src/createLocalStorageRecentSearchesPlugin.ts","../../src/createLocalStorage.ts"],"sourcesContent":["import { Highlighted, HistoryItem } from './types';\n\ntype HighlightParams<TItem> = {\n item: TItem;\n query: string;\n};\n\nexport function addHighlightedAttribute<TItem extends HistoryItem>({\n item,\n query,\n}: HighlightParams<TItem>): Highlighted<TItem> {\n return {\n ...item,\n _highlightResult: {\n label: {\n value: query\n ? item.label.replace(\n new RegExp(query.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'), 'gi'),\n (match) => {\n return `__aa-highlight__${match}__/aa-highlight__`;\n }\n )\n : item.label,\n },\n },\n };\n}\n","export const LOCAL_STORAGE_KEY = 'AUTOCOMPLETE_RECENT_SEARCHES';\nexport const LOCAL_STORAGE_KEY_TEST =\n '__AUTOCOMPLETE_RECENT_SEARCHES_PLUGIN_TEST_KEY__';\n","import { LOCAL_STORAGE_KEY_TEST } from './constants';\n\nfunction isLocalStorageSupported() {\n try {\n localStorage.setItem(LOCAL_STORAGE_KEY_TEST, '');\n localStorage.removeItem(LOCAL_STORAGE_KEY_TEST);\n\n return true;\n } catch (error) {\n return false;\n }\n}\n\ntype LocalStorageProps = {\n key: string;\n};\n\nexport function getLocalStorage<TItem>({ key }: LocalStorageProps) {\n if (!isLocalStorageSupported()) {\n return {\n setItem() {},\n getItem() {\n return [];\n },\n };\n }\n\n return {\n setItem(items: TItem[]) {\n return window.localStorage.setItem(key, JSON.stringify(items));\n },\n getItem(): TItem[] {\n const items = window.localStorage.getItem(key);\n\n return items ? (JSON.parse(items) as TItem[]) : [];\n },\n };\n}\n","/** @jsx createElement */\nimport { SourceTemplates } from '@algolia/autocomplete-js';\n\nimport { RecentSearchesItem } from './types';\n\nexport type GetTemplatesParams<TItem extends RecentSearchesItem> = {\n onRemove(id: string): void;\n onTapAhead(item: TItem): void;\n};\n\nexport function getTemplates<TItem extends RecentSearchesItem>({\n onRemove,\n onTapAhead,\n}: GetTemplatesParams<TItem>): SourceTemplates<TItem> {\n return {\n item({ item, createElement, components }) {\n return (\n <div className=\"aa-ItemWrapper\">\n <div className=\"aa-ItemContent\">\n <div className=\"aa-ItemIcon aa-ItemIcon--noBorder\">\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M12.516 6.984v5.25l4.5 2.672-0.75 1.266-5.25-3.188v-6h1.5zM12 20.016q3.281 0 5.648-2.367t2.367-5.648-2.367-5.648-5.648-2.367-5.648 2.367-2.367 5.648 2.367 5.648 5.648 2.367zM12 2.016q4.125 0 7.055 2.93t2.93 7.055-2.93 7.055-7.055 2.93-7.055-2.93-2.93-7.055 2.93-7.055 7.055-2.93z\" />\n </svg>\n </div>\n <div className=\"aa-ItemContentBody\">\n <div className=\"aa-ItemContentTitle\">\n <components.ReverseHighlight hit={item} attribute=\"label\" />\n {item.category && (\n <span className=\"aa-ItemContentSubtitle aa-ItemContentSubtitle--inline\">\n <span className=\"aa-ItemContentSubtitleIcon\" /> in{' '}\n <span className=\"aa-ItemContentSubtitleCategory\">\n {item.category}\n </span>\n </span>\n )}\n </div>\n </div>\n </div>\n <div className=\"aa-ItemActions\">\n <button\n className=\"aa-ItemActionButton\"\n title=\"Remove this search\"\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onRemove(item.id);\n }}\n >\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z\" />\n </svg>\n </button>\n <button\n className=\"aa-ItemActionButton\"\n title={`Fill query with \"${item.label}\"`}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onTapAhead(item);\n }}\n >\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z\" />\n </svg>\n </button>\n </div>\n </div>\n );\n },\n };\n}\n","import { PluginSubscribeParams } from '@algolia/autocomplete-core';\nimport {\n AutocompleteSource,\n AutocompleteState,\n AutocompletePlugin,\n} from '@algolia/autocomplete-js';\nimport { createRef, MaybePromise, warn } from '@algolia/autocomplete-shared';\nimport { SearchOptions } from '@algolia/client-search';\n\nimport { createStorageApi } from './createStorageApi';\nimport { getTemplates } from './getTemplates';\nimport { RecentSearchesItem, Storage, StorageApi } from './types';\n\nexport interface RecentSearchesPluginData<TItem extends RecentSearchesItem>\n extends StorageApi<TItem> {\n /**\n * Optimized [Algolia search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/). This is useful when using the plugin along with the [Query Suggestions](createQuerySuggestionsPlugin) plugin.\n *\n * This function enhances the provided search parameters by:\n * - Excluding Query Suggestions that are already displayed in recent searches.\n * - Using a shared `hitsPerPage` value to get a group limit of Query Suggestions and recent searches.\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-getalgoliasearchparams\n */\n getAlgoliaSearchParams(params?: SearchOptions): SearchOptions;\n}\n\nexport type CreateRecentSearchesPluginParams<\n TItem extends RecentSearchesItem\n> = {\n /**\n * The storage to fetch from and save recent searches into.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-storage\n */\n storage: Storage<TItem>;\n /**\n * A function to transform the provided source.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-transformsource\n */\n transformSource?(params: {\n source: AutocompleteSource<TItem>;\n state: AutocompleteState<TItem>;\n onRemove(id: string): void;\n onTapAhead(item: TItem): void;\n }): AutocompleteSource<TItem>;\n subscribe?(params: PluginSubscribeParams<TItem>): void;\n};\n\nfunction getDefaultSubcribe<TItem extends RecentSearchesItem>(\n store: StorageApi<TItem>\n) {\n return function subscribe({ onSelect }: PluginSubscribeParams<TItem>) {\n onSelect(({ item, state, source }) => {\n const inputValue = source.getItemInputValue({ item, state });\n\n if (source.sourceId === 'querySuggestionsPlugin' && inputValue) {\n const recentItem: RecentSearchesItem = {\n id: inputValue,\n label: inputValue,\n category: (item as any).__autocomplete_qsCategory,\n };\n store.addItem(recentItem as TItem);\n }\n });\n };\n}\n\nexport function createRecentSearchesPlugin<TItem extends RecentSearchesItem>({\n storage,\n transformSource = ({ source }) => source,\n subscribe,\n}: CreateRecentSearchesPluginParams<TItem>): AutocompletePlugin<\n TItem,\n RecentSearchesPluginData<TItem>\n> {\n const store = createStorageApi<TItem>(storage);\n const lastItemsRef = createRef<MaybePromise<TItem[]>>([]);\n\n return {\n subscribe: subscribe ?? getDefaultSubcribe(store),\n onSubmit({ state }) {\n const { query } = state;\n\n if (query) {\n const recentItem: RecentSearchesItem = {\n id: query,\n label: query,\n };\n store.addItem(recentItem as TItem);\n }\n },\n getSources({ query, setQuery, refresh, state }) {\n lastItemsRef.current = store.getAll(query);\n\n function onRemove(id: string) {\n store.removeItem(id);\n refresh();\n }\n\n function onTapAhead(item: TItem) {\n setQuery(item.label);\n refresh();\n }\n\n return Promise.resolve(lastItemsRef.current).then((items) => {\n if (items.length === 0) {\n return [];\n }\n\n return [\n transformSource({\n source: {\n sourceId: 'recentSearchesPlugin',\n getItemInputValue({ item }) {\n return item.label;\n },\n getItems() {\n return items;\n },\n templates: getTemplates({ onRemove, onTapAhead }),\n },\n onRemove,\n onTapAhead,\n state: state as AutocompleteState<TItem>,\n }),\n ];\n });\n },\n data: {\n ...store,\n // @ts-ignore SearchOptions `facetFilters` is ReadonlyArray\n getAlgoliaSearchParams(params = {}) {\n // If the items returned by `store.getAll` are contained in a Promise,\n // we cannot provide the search params in time when this function is called\n // because we need to resolve the promise before getting the value.\n if (!Array.isArray(lastItemsRef.current)) {\n warn(\n false,\n 'The `getAlgoliaSearchParams` function is not supported with storages that return promises in `getAll`.'\n );\n return params;\n }\n\n return {\n ...params,\n facetFilters: [\n ...(params.facetFilters ?? []),\n // @TODO: we need to base the filter on the `query` attribute, not\n // `objectID`, because the Query Suggestions index cannot ensure\n // that the `objectID` will always be equal to the query.\n ...lastItemsRef.current.map((item) => [`objectID:-${item.label}`]),\n ],\n hitsPerPage: Math.max(\n 1,\n (params.hitsPerPage ?? 10) - lastItemsRef.current.length\n ),\n };\n },\n },\n };\n}\n","import { HistoryItem, Storage, StorageApi } from './types';\n\nexport function createStorageApi<TItem extends HistoryItem>(\n storage: Storage<TItem>\n): StorageApi<TItem> {\n return {\n addItem(item) {\n storage.onRemove(item.id);\n storage.onAdd(item);\n },\n removeItem(id) {\n storage.onRemove(id);\n },\n getAll(query) {\n return storage.getAll(query);\n },\n };\n}\n","export function createRef(initialValue) {\n return {\n current: initialValue\n };\n}","import { addHighlightedAttribute } from './addHighlightedAttribute';\nimport { Highlighted, RecentSearchesItem } from './types';\n\nexport type SearchParams<TItem extends RecentSearchesItem> = {\n query: string;\n items: TItem[];\n limit: number;\n};\n\nexport function search<TItem extends RecentSearchesItem>({\n query,\n items,\n limit,\n}: SearchParams<TItem>): Array<Highlighted<TItem>> {\n if (!query) {\n return items\n .slice(0, limit)\n .map((item) => addHighlightedAttribute({ item, query }));\n }\n\n return items\n .filter((item) => item.label.toLowerCase().includes(query.toLowerCase()))\n .slice(0, limit)\n .map((item) => addHighlightedAttribute({ item, query }));\n}\n","import { AutocompletePlugin } from '@algolia/autocomplete-js';\n\nimport { LOCAL_STORAGE_KEY } from './constants';\nimport { createLocalStorage } from './createLocalStorage';\nimport {\n createRecentSearchesPlugin,\n CreateRecentSearchesPluginParams,\n RecentSearchesPluginData,\n} from './createRecentSearchesPlugin';\nimport { search as defaultSearch, SearchParams } from './search';\nimport { Highlighted, RecentSearchesItem } from './types';\n\nexport type CreateRecentSearchesLocalStorageOptions<\n TItem extends RecentSearchesItem\n> = {\n /**\n * A local storage key to identify where to save and retrieve the recent searches.\n *\n * For example:\n * - \"navbar\"\n * - \"search\"\n * - \"main\"\n *\n * The plugin namespaces all keys to avoid collisions.\n *\n * @example \"top_searchbar\"\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-key\n */\n key: string;\n\n /**\n * The number of recent searches to display.\n *\n * @default 5\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-limit\n */\n limit?: number;\n\n /**\n * A search function to retrieve recent searches from.\n *\n * This function is called in [`storage.getAll`](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-storage) to retrieve recent searches and is useful to filter and highlight recent searches when typing a query.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-search\n */\n search?(params: SearchParams<TItem>): Array<Highlighted<TItem>>;\n};\n\ntype LocalStorageRecentSearchesPluginOptions<\n TItem extends RecentSearchesItem\n> = Pick<\n CreateRecentSearchesPluginParams<TItem>,\n 'transformSource' | 'subscribe'\n> &\n CreateRecentSearchesLocalStorageOptions<TItem>;\n\nexport function createLocalStorageRecentSearchesPlugin<\n TItem extends RecentSearchesItem\n>({\n key,\n limit = 5,\n transformSource,\n search = defaultSearch,\n subscribe,\n}: LocalStorageRecentSearchesPluginOptions<TItem>): AutocompletePlugin<\n TItem,\n RecentSearchesPluginData<TItem>\n> {\n const storage = createLocalStorage({\n key: [LOCAL_STORAGE_KEY, key].join(':'),\n limit,\n search,\n });\n\n return createRecentSearchesPlugin({\n transformSource,\n storage,\n subscribe,\n });\n}\n","import { CreateRecentSearchesLocalStorageOptions } from './createLocalStorageRecentSearchesPlugin';\nimport { getLocalStorage } from './getLocalStorage';\nimport { HistoryItem, Storage } from './types';\n\nexport type CreateLocalStorageProps<TItem extends HistoryItem> = Required<\n CreateRecentSearchesLocalStorageOptions<TItem>\n>;\n\nexport function createLocalStorage<TItem extends HistoryItem>({\n key,\n limit,\n search,\n}: CreateLocalStorageProps<TItem>): Storage<TItem> {\n const storage = getLocalStorage<TItem>({ key });\n\n return {\n onAdd(item) {\n storage.setItem([item, ...storage.getItem()]);\n },\n onRemove(id) {\n storage.setItem(storage.getItem().filter((x) => x.id !== id));\n },\n getAll(query = '') {\n return search({ query, items: storage.getItem(), limit }).slice(0, limit);\n },\n };\n}\n"],"names":["addHighlightedAttribute","item","query","_highlightResult","label","value","replace","RegExp","match","LOCAL_STORAGE_KEY","LOCAL_STORAGE_KEY_TEST","getLocalStorage","key","localStorage","setItem","removeItem","error","isLocalStorageSupported","items","window","JSON","stringify","getItem","parse","getTemplates","onRemove","onTapAhead","createElement","components","className","viewBox","fill","d","ReverseHighlight","hit","attribute","category","title","onClick","event","preventDefault","stopPropagation","id","getDefaultSubcribe","store","onSelect","state","source","inputValue","getItemInputValue","sourceId","recentItem","__autocomplete_qsCategory","addItem","createRecentSearchesPlugin","storage","transformSource","subscribe","onAdd","getAll","createStorageApi","lastItemsRef","current","onSubmit","getSources","setQuery","refresh","Promise","resolve","then","length","getItems","templates","data","getAlgoliaSearchParams","params","Array","isArray","facetFilters","map","hitsPerPage","Math","max","search","limit","filter","toLowerCase","includes","slice","defaultSearch","x","createLocalStorage","join"],"mappings":";wrDAOO,SAASA,SACdC,IAAAA,KACAC,IAAAA,oBAGKD,OACHE,iBAAkB,CAChBC,MAAO,CACLC,MAAOH,EACHD,EAAKG,MAAME,QACT,IAAIC,OAAOL,EAAMI,QAAQ,wBAAyB,QAAS,OAC3D,SAACE,mCAC2BA,0BAG9BP,EAAKG,UCtBV,IAAMK,EAAoB,+BACpBC,EACX,mDCeK,SAASC,SAAyBC,IAAAA,WAfzC,sBAEIC,aAAaC,QAAQJ,EAAwB,IAC7CG,aAAaE,WAAWL,IAEjB,EACP,MAAOM,UACA,GASJC,GASE,CACLH,iBAAQI,UACCC,OAAON,aAAaC,QAAQF,EAAKQ,KAAKC,UAAUH,KAEzDI,uBACQJ,EAAQC,OAAON,aAAaS,QAAQV,UAEnCM,EAASE,KAAKG,MAAML,GAAqB,KAf3C,CACLJ,qBACAQ,yBACS,KCZR,SAASE,SACdC,IAAAA,SACAC,IAAAA,iBAEO,CACLzB,qBAAOA,IAAAA,KAAM0B,IAAAA,cAAeC,IAAAA,kBAExBD,SAAKE,UAAU,kBACbF,SAAKE,UAAU,kBACbF,SAAKE,UAAU,qCACbF,SAAKG,QAAQ,YAAYC,KAAK,gBAC5BJ,UAAMK,EAAE,8RAGZL,SAAKE,UAAU,sBACbF,SAAKE,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D,IAAAA,OAEM5B,EAAU5C,EAAuB,CAAEC,IAAAA,UAElC,CACL8C,eAAMzD,GACJsD,EAAQzC,SAASb,YAASsD,EAAQjC,cAEpCG,kBAASiB,GACPa,EAAQzC,QAAQyC,EAAQjC,UAAU+D,QAAO,SAACK,UAAMA,EAAEhD,KAAOA,OAE3DiB,yBACSwB,EAAO,CAAEjF,6DADH,GACUgB,MAAOqC,EAAQjC,UAAW8D,MAAAA,IAASI,MAAM,EAAGJ,KD6CvDO,CAAmB,CACjC/E,IAAK,CAACH,EAAmBG,GAAKgF,KAAK,KACnCR,MAAAA,EACAD,OAAAA,IAMA1B,UAAAA"}
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../src/addHighlightedAttribute.ts","../../src/constants.ts","../../src/getLocalStorage.ts","../../src/getTemplates.tsx","../../src/createRecentSearchesPlugin.ts","../../src/createStorageApi.ts","../../../autocomplete-shared/dist/esm/createRef.js","../../src/search.ts","../../src/createLocalStorageRecentSearchesPlugin.ts","../../src/createLocalStorage.ts"],"sourcesContent":["import { Highlighted, HistoryItem } from './types';\n\ntype HighlightParams<TItem> = {\n item: TItem;\n query: string;\n};\n\nexport function addHighlightedAttribute<TItem extends HistoryItem>({\n item,\n query,\n}: HighlightParams<TItem>): Highlighted<TItem> {\n return {\n ...item,\n _highlightResult: {\n label: {\n value: query\n ? item.label.replace(\n new RegExp(query.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'), 'gi'),\n (match) => {\n return `__aa-highlight__${match}__/aa-highlight__`;\n }\n )\n : item.label,\n },\n },\n };\n}\n","export const LOCAL_STORAGE_KEY = 'AUTOCOMPLETE_RECENT_SEARCHES';\nexport const LOCAL_STORAGE_KEY_TEST =\n '__AUTOCOMPLETE_RECENT_SEARCHES_PLUGIN_TEST_KEY__';\n","import { LOCAL_STORAGE_KEY_TEST } from './constants';\n\nfunction isLocalStorageSupported() {\n try {\n localStorage.setItem(LOCAL_STORAGE_KEY_TEST, '');\n localStorage.removeItem(LOCAL_STORAGE_KEY_TEST);\n\n return true;\n } catch (error) {\n return false;\n }\n}\n\ntype LocalStorageProps = {\n key: string;\n};\n\nexport function getLocalStorage<TItem>({ key }: LocalStorageProps) {\n if (!isLocalStorageSupported()) {\n return {\n setItem() {},\n getItem() {\n return [];\n },\n };\n }\n\n return {\n setItem(items: TItem[]) {\n return window.localStorage.setItem(key, JSON.stringify(items));\n },\n getItem(): TItem[] {\n const items = window.localStorage.getItem(key);\n\n return items ? (JSON.parse(items) as TItem[]) : [];\n },\n };\n}\n","/** @jsx createElement */\nimport { SourceTemplates } from '@algolia/autocomplete-js';\n\nimport { RecentSearchesItem } from './types';\n\nexport type GetTemplatesParams<TItem extends RecentSearchesItem> = {\n onRemove(id: string): void;\n onTapAhead(item: TItem): void;\n};\n\nexport function getTemplates<TItem extends RecentSearchesItem>({\n onRemove,\n onTapAhead,\n}: GetTemplatesParams<TItem>): SourceTemplates<TItem> {\n return {\n item({ item, createElement, components }) {\n return (\n <div className=\"aa-ItemWrapper\">\n <div className=\"aa-ItemContent\">\n <div className=\"aa-ItemIcon aa-ItemIcon--noBorder\">\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M12.516 6.984v5.25l4.5 2.672-0.75 1.266-5.25-3.188v-6h1.5zM12 20.016q3.281 0 5.648-2.367t2.367-5.648-2.367-5.648-5.648-2.367-5.648 2.367-2.367 5.648 2.367 5.648 5.648 2.367zM12 2.016q4.125 0 7.055 2.93t2.93 7.055-2.93 7.055-7.055 2.93-7.055-2.93-2.93-7.055 2.93-7.055 7.055-2.93z\" />\n </svg>\n </div>\n <div className=\"aa-ItemContentBody\">\n <div className=\"aa-ItemContentTitle\">\n <components.ReverseHighlight hit={item} attribute=\"label\" />\n {item.category && (\n <span className=\"aa-ItemContentSubtitle aa-ItemContentSubtitle--inline\">\n <span className=\"aa-ItemContentSubtitleIcon\" /> in{' '}\n <span className=\"aa-ItemContentSubtitleCategory\">\n {item.category}\n </span>\n </span>\n )}\n </div>\n </div>\n </div>\n <div className=\"aa-ItemActions\">\n <button\n className=\"aa-ItemActionButton\"\n title=\"Remove this search\"\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onRemove(item.id);\n }}\n >\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z\" />\n </svg>\n </button>\n <button\n className=\"aa-ItemActionButton\"\n title={`Fill query with \"${item.label}\"`}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onTapAhead(item);\n }}\n >\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z\" />\n </svg>\n </button>\n </div>\n </div>\n );\n },\n };\n}\n","import { PluginSubscribeParams } from '@algolia/autocomplete-core';\nimport {\n AutocompleteSource,\n AutocompleteState,\n AutocompletePlugin,\n} from '@algolia/autocomplete-js';\nimport { createRef, MaybePromise, warn } from '@algolia/autocomplete-shared';\nimport { SearchOptions } from '@algolia/client-search';\n\nimport { createStorageApi } from './createStorageApi';\nimport { getTemplates } from './getTemplates';\nimport { RecentSearchesItem, Storage, StorageApi } from './types';\n\nexport interface RecentSearchesPluginData<TItem extends RecentSearchesItem>\n extends StorageApi<TItem> {\n /**\n * Optimized [Algolia search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/). This is useful when using the plugin along with the [Query Suggestions](createQuerySuggestionsPlugin) plugin.\n *\n * This function enhances the provided search parameters by:\n * - Excluding Query Suggestions that are already displayed in recent searches.\n * - Using a shared `hitsPerPage` value to get a group limit of Query Suggestions and recent searches.\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-getalgoliasearchparams\n */\n getAlgoliaSearchParams(params?: SearchOptions): SearchOptions;\n}\n\nexport type CreateRecentSearchesPluginParams<\n TItem extends RecentSearchesItem\n> = {\n /**\n * The storage to fetch from and save recent searches into.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-storage\n */\n storage: Storage<TItem>;\n /**\n * A function to transform the provided source.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-transformsource\n */\n transformSource?(params: {\n source: AutocompleteSource<TItem>;\n state: AutocompleteState<TItem>;\n onRemove(id: string): void;\n onTapAhead(item: TItem): void;\n }): AutocompleteSource<TItem>;\n subscribe?(params: PluginSubscribeParams<TItem>): void;\n};\n\nfunction getDefaultSubcribe<TItem extends RecentSearchesItem>(\n store: StorageApi<TItem>\n) {\n return function subscribe({ onSelect }: PluginSubscribeParams<TItem>) {\n onSelect(({ item, state, source }) => {\n const inputValue = source.getItemInputValue({ item, state });\n\n if (source.sourceId === 'querySuggestionsPlugin' && inputValue) {\n const recentItem: RecentSearchesItem = {\n id: inputValue,\n label: inputValue,\n category: (item as any).__autocomplete_qsCategory,\n };\n store.addItem(recentItem as TItem);\n }\n });\n };\n}\n\nexport function createRecentSearchesPlugin<TItem extends RecentSearchesItem>(\n options: CreateRecentSearchesPluginParams<TItem>\n): AutocompletePlugin<TItem, RecentSearchesPluginData<TItem>> {\n const { storage, transformSource, subscribe } = getOptions(options);\n const store = createStorageApi<TItem>(storage);\n const lastItemsRef = createRef<MaybePromise<TItem[]>>([]);\n\n return {\n name: 'aa.recentSearchesPlugin',\n subscribe: subscribe ?? getDefaultSubcribe(store),\n onSubmit({ state }) {\n const { query } = state;\n\n if (query) {\n const recentItem: RecentSearchesItem = {\n id: query,\n label: query,\n };\n store.addItem(recentItem as TItem);\n }\n },\n getSources({ query, setQuery, refresh, state }) {\n lastItemsRef.current = store.getAll(query);\n\n function onRemove(id: string) {\n store.removeItem(id);\n refresh();\n }\n\n function onTapAhead(item: TItem) {\n setQuery(item.label);\n refresh();\n }\n\n return Promise.resolve(lastItemsRef.current).then((items) => {\n if (items.length === 0) {\n return [];\n }\n\n return [\n transformSource({\n source: {\n sourceId: 'recentSearchesPlugin',\n getItemInputValue({ item }) {\n return item.label;\n },\n getItems() {\n return items;\n },\n templates: getTemplates({ onRemove, onTapAhead }),\n },\n onRemove,\n onTapAhead,\n state: state as AutocompleteState<TItem>,\n }),\n ];\n });\n },\n data: {\n ...store,\n // @ts-ignore SearchOptions `facetFilters` is ReadonlyArray\n getAlgoliaSearchParams(params = {}) {\n // If the items returned by `store.getAll` are contained in a Promise,\n // we cannot provide the search params in time when this function is called\n // because we need to resolve the promise before getting the value.\n if (!Array.isArray(lastItemsRef.current)) {\n warn(\n false,\n 'The `getAlgoliaSearchParams` function is not supported with storages that return promises in `getAll`.'\n );\n return params;\n }\n\n return {\n ...params,\n facetFilters: [\n ...(params.facetFilters ?? []),\n // @TODO: we need to base the filter on the `query` attribute, not\n // `objectID`, because the Query Suggestions index cannot ensure\n // that the `objectID` will always be equal to the query.\n ...lastItemsRef.current.map((item) => [`objectID:-${item.label}`]),\n ],\n hitsPerPage: Math.max(\n 1,\n (params.hitsPerPage ?? 10) - lastItemsRef.current.length\n ),\n };\n },\n },\n __autocomplete_pluginOptions: options,\n };\n}\n\nfunction getOptions<TItem extends RecentSearchesItem>(\n options: CreateRecentSearchesPluginParams<TItem>\n) {\n return {\n transformSource: ({ source }) => source,\n ...options,\n };\n}\n","import { HistoryItem, Storage, StorageApi } from './types';\n\nexport function createStorageApi<TItem extends HistoryItem>(\n storage: Storage<TItem>\n): StorageApi<TItem> {\n return {\n addItem(item) {\n storage.onRemove(item.id);\n storage.onAdd(item);\n },\n removeItem(id) {\n storage.onRemove(id);\n },\n getAll(query) {\n return storage.getAll(query);\n },\n };\n}\n","export function createRef(initialValue) {\n return {\n current: initialValue\n };\n}","import { addHighlightedAttribute } from './addHighlightedAttribute';\nimport { Highlighted, RecentSearchesItem } from './types';\n\nexport type SearchParams<TItem extends RecentSearchesItem> = {\n query: string;\n items: TItem[];\n limit: number;\n};\n\nexport function search<TItem extends RecentSearchesItem>({\n query,\n items,\n limit,\n}: SearchParams<TItem>): Array<Highlighted<TItem>> {\n if (!query) {\n return items\n .slice(0, limit)\n .map((item) => addHighlightedAttribute({ item, query }));\n }\n\n return items\n .filter((item) => item.label.toLowerCase().includes(query.toLowerCase()))\n .slice(0, limit)\n .map((item) => addHighlightedAttribute({ item, query }));\n}\n","import { AutocompletePlugin } from '@algolia/autocomplete-js';\n\nimport { LOCAL_STORAGE_KEY } from './constants';\nimport { createLocalStorage } from './createLocalStorage';\nimport {\n createRecentSearchesPlugin,\n CreateRecentSearchesPluginParams,\n RecentSearchesPluginData,\n} from './createRecentSearchesPlugin';\nimport { search as defaultSearch, SearchParams } from './search';\nimport { Highlighted, RecentSearchesItem } from './types';\n\nexport type CreateRecentSearchesLocalStorageOptions<\n TItem extends RecentSearchesItem\n> = {\n /**\n * A local storage key to identify where to save and retrieve the recent searches.\n *\n * For example:\n * - \"navbar\"\n * - \"search\"\n * - \"main\"\n *\n * The plugin namespaces all keys to avoid collisions.\n *\n * @example \"top_searchbar\"\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-key\n */\n key: string;\n\n /**\n * The number of recent searches to display.\n *\n * @default 5\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-limit\n */\n limit?: number;\n\n /**\n * A search function to retrieve recent searches from.\n *\n * This function is called in [`storage.getAll`](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createRecentSearchesPlugin/#param-storage) to retrieve recent searches and is useful to filter and highlight recent searches when typing a query.\n *\n * @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/#param-search\n */\n search?(params: SearchParams<TItem>): Array<Highlighted<TItem>>;\n};\n\ntype LocalStorageRecentSearchesPluginOptions<\n TItem extends RecentSearchesItem\n> = Pick<\n CreateRecentSearchesPluginParams<TItem>,\n 'transformSource' | 'subscribe'\n> &\n CreateRecentSearchesLocalStorageOptions<TItem>;\n\nexport function createLocalStorageRecentSearchesPlugin<\n TItem extends RecentSearchesItem\n>(\n options: LocalStorageRecentSearchesPluginOptions<TItem>\n): AutocompletePlugin<TItem, RecentSearchesPluginData<TItem>> {\n const { key, limit, transformSource, search, subscribe } = getOptions(\n options\n );\n const storage = createLocalStorage<TItem>({\n key: [LOCAL_STORAGE_KEY, key].join(':'),\n limit,\n search,\n });\n\n const recentSearchesPlugin = createRecentSearchesPlugin<TItem>({\n transformSource,\n storage,\n subscribe,\n });\n\n return {\n ...recentSearchesPlugin,\n name: 'aa.localStorageRecentSearchesPlugin',\n __autocomplete_pluginOptions: options,\n };\n}\n\nfunction getOptions<TItem extends RecentSearchesItem>(\n options: LocalStorageRecentSearchesPluginOptions<TItem>\n) {\n return {\n limit: 5,\n search: defaultSearch,\n transformSource: ({ source }) => source,\n ...options,\n };\n}\n","import { CreateRecentSearchesLocalStorageOptions } from './createLocalStorageRecentSearchesPlugin';\nimport { getLocalStorage } from './getLocalStorage';\nimport { HistoryItem, Storage } from './types';\n\nexport type CreateLocalStorageProps<TItem extends HistoryItem> = Required<\n CreateRecentSearchesLocalStorageOptions<TItem>\n>;\n\nexport function createLocalStorage<TItem extends HistoryItem>({\n key,\n limit,\n search,\n}: CreateLocalStorageProps<TItem>): Storage<TItem> {\n const storage = getLocalStorage<TItem>({ key });\n\n return {\n onAdd(item) {\n storage.setItem([item, ...storage.getItem()]);\n },\n onRemove(id) {\n storage.setItem(storage.getItem().filter((x) => x.id !== id));\n },\n getAll(query = '') {\n return search({ query, items: storage.getItem(), limit }).slice(0, limit);\n },\n };\n}\n"],"names":["addHighlightedAttribute","item","query","_highlightResult","label","value","replace","RegExp","match","LOCAL_STORAGE_KEY","LOCAL_STORAGE_KEY_TEST","getLocalStorage","key","localStorage","setItem","removeItem","error","isLocalStorageSupported","items","window","JSON","stringify","getItem","parse","getTemplates","onRemove","onTapAhead","createElement","components","className","viewBox","fill","d","ReverseHighlight","hit","attribute","category","title","onClick","event","preventDefault","stopPropagation","id","getDefaultSubcribe","store","onSelect","state","source","inputValue","getItemInputValue","sourceId","recentItem","__autocomplete_qsCategory","addItem","createRecentSearchesPlugin","options","transformSource","getOptions","storage","subscribe","onAdd","getAll","createStorageApi","lastItemsRef","current","name","onSubmit","getSources","setQuery","refresh","Promise","resolve","then","length","getItems","templates","data","getAlgoliaSearchParams","params","Array","isArray","facetFilters","map","hitsPerPage","Math","max","__autocomplete_pluginOptions","search","limit","filter","toLowerCase","includes","slice","defaultSearch","x","createLocalStorage","join"],"mappings":";2sDAOO,SAASA,SAC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KDyCvDO,CAA0B,CACxCnF,IAAK,CAACH,EAAmBG,GAAKoF,KAAK,KACnCR,MAAAA,EACAD,OAAAA,kBAG2BjC,EAAkC,CAC7DE,gBAAAA,EACAE,QAAAA,EACAC,UAAAA,SAKAM,KAAM,sCACNqB,6BAA8B/B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algolia/autocomplete-plugin-recent-searches",
|
|
3
3
|
"description": "A plugin to add recent searches to Algolia Autocomplete.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/algolia/autocomplete",
|
|
7
7
|
"repository": "algolia/autocomplete",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"watch": "watch \"yarn on:change\" --ignoreDirectoryPattern \"/dist/\""
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@algolia/autocomplete-core": "1.
|
|
35
|
-
"@algolia/autocomplete-js": "1.
|
|
36
|
-
"@algolia/autocomplete-preset-algolia": "1.
|
|
37
|
-
"@algolia/autocomplete-shared": "1.
|
|
34
|
+
"@algolia/autocomplete-core": "1.5.1",
|
|
35
|
+
"@algolia/autocomplete-js": "1.5.1",
|
|
36
|
+
"@algolia/autocomplete-preset-algolia": "1.5.1",
|
|
37
|
+
"@algolia/autocomplete-shared": "1.5.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@algolia/client-search": "4.9.1"
|