Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algolia/autocomplete-plugin-recent-searches

Package Overview
Dependencies
Maintainers
61
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/autocomplete-plugin-recent-searches - npm Package Compare versions

Comparing version 1.0.0-alpha.40 to 1.0.0-alpha.41

4

dist/esm/createLocalStorageRecentSearchesPlugin.d.ts

@@ -23,4 +23,4 @@ import { AutocompletePlugin } from '@algolia/autocomplete-core';

};
declare type LocalStorageRecentSearchesPluginOptions<TItem extends RecentSearchesItem> = Pick<CreateRecentSearchesPluginParams<TItem>, 'getTemplates'> & CreateRecentSearchesLocalStorageOptions<TItem>;
export declare function createLocalStorageRecentSearchesPlugin<TItem extends RecentSearchesItem>({ key, limit, getTemplates, search, }: LocalStorageRecentSearchesPluginOptions<TItem>): AutocompletePlugin<TItem, RecentSearchesPluginData>;
declare type LocalStorageRecentSearchesPluginOptions<TItem extends RecentSearchesItem> = Pick<CreateRecentSearchesPluginParams<TItem>, 'transformSource'> & CreateRecentSearchesLocalStorageOptions<TItem>;
export declare function createLocalStorageRecentSearchesPlugin<TItem extends RecentSearchesItem>({ key, limit, transformSource, search, }: LocalStorageRecentSearchesPluginOptions<TItem>): AutocompletePlugin<TItem, RecentSearchesPluginData>;
export {};

@@ -7,3 +7,3 @@ import { createRecentSearchesPlugin } from './createRecentSearchesPlugin';

limit = _ref$limit === void 0 ? 5 : _ref$limit,
getTemplates = _ref.getTemplates,
transformSource = _ref.transformSource,
_ref$search = _ref.search,

@@ -17,5 +17,5 @@ search = _ref$search === void 0 ? defaultSearch : _ref$search;

return createRecentSearchesPlugin({
getTemplates: getTemplates,
transformSource: transformSource,
storage: storage
});
}
import { AutocompletePlugin } from '@algolia/autocomplete-core';
import { SourceTemplates } from '@algolia/autocomplete-js';
import { AutocompleteSource } from '@algolia/autocomplete-js';
import { SearchOptions } from '@algolia/client-search';
import { RecentSearchesStorage } from './createStore';
import { GetTemplatesParams } from './getTemplates';
import { RecentSearchesItem } from './types';

@@ -12,4 +11,7 @@ export declare type RecentSearchesPluginData = {

storage: RecentSearchesStorage<TItem>;
getTemplates?(params: GetTemplatesParams): SourceTemplates<TItem>;
transformSource?(params: {
source: AutocompleteSource<TItem>;
onRemove(id: string): void;
}): AutocompleteSource<TItem>;
};
export declare function createRecentSearchesPlugin<TItem extends RecentSearchesItem>({ storage, getTemplates, }: CreateRecentSearchesPluginParams<TItem>): AutocompletePlugin<TItem, RecentSearchesPluginData>;
export declare function createRecentSearchesPlugin<TItem extends RecentSearchesItem>({ storage, transformSource, }: CreateRecentSearchesPluginParams<TItem>): AutocompletePlugin<TItem, RecentSearchesPluginData>;

@@ -19,20 +19,21 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

import { warn } from '@algolia/autocomplete-shared';
import { createRef, warn } from '@algolia/autocomplete-shared';
import { createStore } from './createStore';
import { getTemplates as defaultGetTemplates } from './getTemplates';
import { getTemplates } from './getTemplates';
export function createRecentSearchesPlugin(_ref) {
var storage = _ref.storage,
_ref$getTemplates = _ref.getTemplates,
getTemplates = _ref$getTemplates === void 0 ? defaultGetTemplates : _ref$getTemplates;
_ref$transformSource = _ref.transformSource,
transformSource = _ref$transformSource === void 0 ? function (_ref2) {
var source = _ref2.source;
return source;
} : _ref$transformSource;
var store = createStore(storage);
var lastItemsRef = {
current: []
};
var lastItemsRef = createRef([]);
return {
subscribe: function subscribe(_ref2) {
var onSelect = _ref2.onSelect;
onSelect(function (_ref3) {
var item = _ref3.item,
state = _ref3.state,
source = _ref3.source;
subscribe: function subscribe(_ref3) {
var onSelect = _ref3.onSelect;
onSelect(function (_ref4) {
var item = _ref4.item,
state = _ref4.state,
source = _ref4.source;
var inputValue = source.getItemInputValue({

@@ -51,4 +52,4 @@ item: item,

},
onSubmit: function onSubmit(_ref4) {
var state = _ref4.state;
onSubmit: function onSubmit(_ref5) {
var state = _ref5.state;
var query = state.query;

@@ -63,6 +64,15 @@

},
getSources: function getSources(_ref5) {
var query = _ref5.query,
refresh = _ref5.refresh;
getSources: function getSources(_ref6) {
var query = _ref6.query,
refresh = _ref6.refresh;
lastItemsRef.current = store.getAll(query);
function onRemove(id) {
store.remove(id);
refresh();
}
var templates = getTemplates({
onRemove: onRemove
});
return Promise.resolve(lastItemsRef.current).then(function (items) {

@@ -73,17 +83,16 @@ if (items.length === 0) {

return [{
getItemInputValue: function getItemInputValue(_ref6) {
var item = _ref6.item;
return item.query;
return [transformSource({
source: {
sourceId: 'recentSearchesPlugin',
getItemInputValue: function getItemInputValue(_ref7) {
var item = _ref7.item;
return item.query;
},
getItems: function getItems() {
return items;
},
templates: templates
},
getItems: function getItems() {
return items;
},
templates: getTemplates({
onRemove: function onRemove(id) {
store.remove(id);
refresh();
}
})
}];
onRemove: onRemove
})];
});

@@ -90,0 +99,0 @@ },

@@ -28,4 +28,7 @@ /** @jsx createElement */

hit: item,
attribute: 'query'
}))), createElement("button", {
attribute: 'query',
createElement: createElement
}))), createElement("div", {
className: "aa-ItemActions"
}, createElement("button", {
className: "aa-ItemActionButton",

@@ -39,4 +42,4 @@ title: "Remove this search",

viewBox: "0 0 24 24",
width: "20",
height: "20",
width: "18",
height: "18",
fill: "none",

@@ -49,5 +52,5 @@ stroke: "currentColor"

strokeWidth: 2
}))));
})))));
}
};
}

@@ -1,2 +0,2 @@

/*! @algolia/autocomplete-plugin-recent-searches 1.0.0-alpha.40 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete.js */
/*! @algolia/autocomplete-plugin-recent-searches 1.0.0-alpha.41 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete.js */
(function (global, factory) {

@@ -90,2 +90,8 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

function createRef(initialValue) {
return {
current: initialValue
};
}
var warnCache = {

@@ -363,2 +369,3 @@ current: {}

return x.isHighlighted ? createElement(tagName, {
key: x.value,
children: x.value

@@ -395,4 +402,7 @@ }) : x.value;

hit: item,
attribute: 'query'
}))), createElement("button", {
attribute: 'query',
createElement: createElement
}))), createElement("div", {
className: "aa-ItemActions"
}, createElement("button", {
className: "aa-ItemActionButton",

@@ -406,4 +416,4 @@ title: "Remove this search",

viewBox: "0 0 24 24",
width: "20",
height: "20",
width: "18",
height: "18",
fill: "none",

@@ -416,3 +426,3 @@ stroke: "currentColor"

strokeWidth: 2
}))));
})))));
}

@@ -424,15 +434,16 @@ };

var storage = _ref.storage,
_ref$getTemplates = _ref.getTemplates,
getTemplates$1 = _ref$getTemplates === void 0 ? getTemplates : _ref$getTemplates;
_ref$transformSource = _ref.transformSource,
transformSource = _ref$transformSource === void 0 ? function (_ref2) {
var source = _ref2.source;
return source;
} : _ref$transformSource;
var store = createStore(storage);
var lastItemsRef = {
current: []
};
var lastItemsRef = createRef([]);
return {
subscribe: function subscribe(_ref2) {
var onSelect = _ref2.onSelect;
onSelect(function (_ref3) {
var item = _ref3.item,
state = _ref3.state,
source = _ref3.source;
subscribe: function subscribe(_ref3) {
var onSelect = _ref3.onSelect;
onSelect(function (_ref4) {
var item = _ref4.item,
state = _ref4.state,
source = _ref4.source;
var inputValue = source.getItemInputValue({

@@ -451,4 +462,4 @@ item: item,

},
onSubmit: function onSubmit(_ref4) {
var state = _ref4.state;
onSubmit: function onSubmit(_ref5) {
var state = _ref5.state;
var query = state.query;

@@ -463,6 +474,15 @@

},
getSources: function getSources(_ref5) {
var query = _ref5.query,
refresh = _ref5.refresh;
getSources: function getSources(_ref6) {
var query = _ref6.query,
refresh = _ref6.refresh;
lastItemsRef.current = store.getAll(query);
function onRemove(id) {
store.remove(id);
refresh();
}
var templates = getTemplates({
onRemove: onRemove
});
return Promise.resolve(lastItemsRef.current).then(function (items) {

@@ -473,17 +493,16 @@ if (items.length === 0) {

return [{
getItemInputValue: function getItemInputValue(_ref6) {
var item = _ref6.item;
return item.query;
return [transformSource({
source: {
sourceId: 'recentSearchesPlugin',
getItemInputValue: function getItemInputValue(_ref7) {
var item = _ref7.item;
return item.query;
},
getItems: function getItems() {
return items;
},
templates: templates
},
getItems: function getItems() {
return items;
},
templates: getTemplates$1({
onRemove: function onRemove(id) {
store.remove(id);
refresh();
}
})
}];
onRemove: onRemove
})];
});

@@ -620,3 +639,3 @@ },

limit = _ref$limit === void 0 ? 5 : _ref$limit,
getTemplates = _ref.getTemplates,
transformSource = _ref.transformSource,
_ref$search = _ref.search,

@@ -630,3 +649,3 @@ search$1 = _ref$search === void 0 ? search : _ref$search;

return createRecentSearchesPlugin({
getTemplates: getTemplates,
transformSource: transformSource,
storage: storage

@@ -633,0 +652,0 @@ });

@@ -1,3 +0,3 @@

/*! @algolia/autocomplete-plugin-recent-searches 1.0.0-alpha.40 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete.js */
!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,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(Object(i),!0).forEach((function(r){t(e,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function i(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(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 o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var u;function a(e,t,r){var n,i,o,u=arguments,a={};for(o in t)"key"==o?n=t[o]:"ref"==o?i=t[o]:a[o]=t[o];if(arguments.length>3)for(r=[r],o=3;o<arguments.length;o++)r.push(u[o]);if(null!=r&&(a.children=r),"function"==typeof e&&null!=e.defaultProps)for(o in e.defaultProps)void 0===a[o]&&(a[o]=e.defaultProps[o]);return c(e,a,n,i,null)}function c(e,t,r,n,i){var o={type:e,props:t,key:r,ref:n,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==i?++u.__v:i};return null!=u.vnode&&u.vnode(o),o}function l(e,t){return t.reduce((function(e,t){return e&&e[t]}),e)}u={__e:function(e,t){for(var r,n,i,o=t.__h;t=t.__;)if((r=t.__c)&&!r.__)try{if((n=r.constructor)&&null!=n.getDerivedStateFromError&&(r.setState(n.getDerivedStateFromError(e)),i=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(e),i=r.__d),i)return t.__h=o,r.__E=r}catch(t){e=t}throw e},__v:0},"function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout;function f(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(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 s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var g={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},h=new RegExp(/\w/i),d=/&(amp|quot|lt|gt|#39);/g,m=RegExp(d.source);function p(e,t){var r,n,i,o=e[t],u=(null===(r=e[t+1])||void 0===r?void 0:r.isHighlighted)||!0,a=(null===(n=e[t-1])||void 0===n?void 0:n.isHighlighted)||!0;return h.test((i=o.value)&&m.test(i)?i.replace(d,(function(e){return g[e]})):i)||a!==u?o.isHighlighted:a}function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){b(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _(e){return n=(r=e).hit,i=r.attribute,o=Array.isArray(i)?i:[i],"string"!=typeof(u=l(n,["_highlightResult"].concat(f(o),["value"])))&&(u=l(n,o)||""),(t=function(e){var t=e.highlightedValue.split("__aa-highlight__"),r=t.shift(),n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{get:function(){return e},add:function(t){var r=e[e.length-1];(null==r?void 0:r.isHighlighted)===t.isHighlighted?e[e.length-1]={value:r.value+t.value,isHighlighted:r.isHighlighted}:e.push(t)}}}(r?[{value:r,isHighlighted:!1}]:[]);return t.forEach((function(e){var t=e.split("__/aa-highlight__");n.add({value:t[0],isHighlighted:!0}),""!==t[1]&&n.add({value:t[1],isHighlighted:!1})})),n.get()}({highlightedValue:u})).some((function(e){return e.isHighlighted}))?t.map((function(e,r){return y(y({},e),{},{isHighlighted:!p(t,r)})})):t.map((function(e){return y(y({},e),{},{isHighlighted:!1})}));var t,r,n,i,o,u}function O(e){var t=e.onRemove;return{item:function(e){var r=e.item,n=e.createElement;return n(e.Fragment,null,n("div",{className:"aa-ItemIcon aa-ItemIcon--no-border"},n("svg",{width:"20",height:"20",viewBox:"0 0 22 22",fill:"currentColor"},n("path",{d:"M0 0h24v24H0z",fill:"none"}),n("path",{d:"M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"}))),n("div",{className:"aa-ItemContent"},n("div",{className:"aa-ItemContentTitle"},function(e){var t=e.hit,r=e.attribute,n=e.tagName,i=void 0===n?"mark":n,o=e.createElement,u=void 0===o?a:o;return _({hit:t,attribute:r}).map((function(e){return e.isHighlighted?u(i,{children:e.value}):e.value}))}({hit:r,attribute:"query"}))),n("button",{className:"aa-ItemActionButton",title:"Remove this search",onClick:function(e){e.stopPropagation(),t(r.id)}},n("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor"},n("path",{d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}))))}}}function j(e){var t=e.storage,r=e.getTemplates,o=void 0===r?O:r,u=function(e){return{add:function(t){e.onRemove(t.id),e.onAdd(t)},remove:function(t){e.onRemove(t)},getAll:function(t){return e.getAll(t)}}}(t),a={current:[]};return{subscribe:function(e){(0,e.onSelect)((function(e){var t=e.item,r=e.state,n=e.source.getItemInputValue({item:t,state:r});n&&u.add({id:n,query:n})}))},onSubmit:function(e){var t=e.state.query;t&&u.add({id:t,query:t})},getSources:function(e){var t=e.query,r=e.refresh;return a.current=u.getAll(t),Promise.resolve(a.current).then((function(e){return 0===e.length?[]:[{getItemInputValue:function(e){return e.item.query},getItems:function(){return e},templates:o({onRemove:function(e){u.remove(e),r()}})}]}))},data:{getAlgoliaSearchParams:function(){var e,t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Array.isArray(a.current)?n(n({},r),{},{facetFilters:[].concat(i(null!==(e=r.facetFilters)&&void 0!==e?e:[]),i(a.current.map((function(e){return["objectID:-".concat(e.query)]})))),hitsPerPage:Math.max(1,(null!==(t=r.hitsPerPage)&&void 0!==t?t:10)-a.current.length)}):r}}}}var P="AUTOCOMPLETE_RECENT_SEARCHES",S="__AUTOCOMPLETE_RECENT_SEARCHES_PLUGIN_TEST_KEY__";function w(e){var t=e.key;return function(){try{return localStorage.setItem(S,""),localStorage.removeItem(S),!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 I(e){var t=e.item,r=e.query;return n(n({},t),{},{_highlightResult:{query:{value:r?t.query.replace(new RegExp(r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),"__aa-highlight__".concat(r,"__/aa-highlight__")):t.query}}})}function A(e){var t=e.query,r=e.items,n=e.limit;return t?r.filter((function(e){return e.query.toLowerCase().includes(t.toLowerCase())})).slice(0,n).map((function(e){return I({item:e,query:t})})):r.slice(0,n).map((function(e){return I({item:e,query:t})}))}e.createLocalStorageRecentSearchesPlugin=function(e){var t=e.key,r=e.limit,n=void 0===r?5:r,o=e.getTemplates,u=e.search,a=void 0===u?A:u;return j({getTemplates:o,storage:function(e){var t=e.key,r=e.limit,n=e.search,o=w({key:t});return{getAll:function(){return n({query:arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",items:o.getItem(),limit:r}).slice(0,r)},onAdd:function(e){o.setItem([e].concat(i(o.getItem())))},onRemove:function(e){o.setItem(o.getItem().filter((function(t){return t.id!==e})))}}}({key:[P,t].join(":"),limit:n,search:a})})},e.createRecentSearchesPlugin=j,e.getTemplates=O,Object.defineProperty(e,"__esModule",{value:!0})}));
/*! @algolia/autocomplete-plugin-recent-searches 1.0.0-alpha.41 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete.js */
!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,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(Object(i),!0).forEach((function(r){t(e,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function i(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(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 o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var u;function a(e,t,r){var n,i,o,u=arguments,a={};for(o in t)"key"==o?n=t[o]:"ref"==o?i=t[o]:a[o]=t[o];if(arguments.length>3)for(r=[r],o=3;o<arguments.length;o++)r.push(u[o]);if(null!=r&&(a.children=r),"function"==typeof e&&null!=e.defaultProps)for(o in e.defaultProps)void 0===a[o]&&(a[o]=e.defaultProps[o]);return c(e,a,n,i,null)}function c(e,t,r,n,i){var o={type:e,props:t,key:r,ref:n,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==i?++u.__v:i};return null!=u.vnode&&u.vnode(o),o}function l(e,t){return t.reduce((function(e,t){return e&&e[t]}),e)}u={__e:function(e,t){for(var r,n,i,o=t.__h;t=t.__;)if((r=t.__c)&&!r.__)try{if((n=r.constructor)&&null!=n.getDerivedStateFromError&&(r.setState(n.getDerivedStateFromError(e)),i=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(e),i=r.__d),i)return t.__h=o,r.__E=r}catch(t){e=t}throw e},__v:0},"function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout;function f(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(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 s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var g={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},h=new RegExp(/\w/i),m=/&(amp|quot|lt|gt|#39);/g,d=RegExp(m.source);function v(e,t){var r,n,i,o=e[t],u=(null===(r=e[t+1])||void 0===r?void 0:r.isHighlighted)||!0,a=(null===(n=e[t-1])||void 0===n?void 0:n.isHighlighted)||!0;return h.test((i=o.value)&&d.test(i)?i.replace(m,(function(e){return g[e]})):i)||a!==u?o.isHighlighted:a}function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){b(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _(e){return n=(r=e).hit,i=r.attribute,o=Array.isArray(i)?i:[i],"string"!=typeof(u=l(n,["_highlightResult"].concat(f(o),["value"])))&&(u=l(n,o)||""),(t=function(e){var t=e.highlightedValue.split("__aa-highlight__"),r=t.shift(),n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{get:function(){return e},add:function(t){var r=e[e.length-1];(null==r?void 0:r.isHighlighted)===t.isHighlighted?e[e.length-1]={value:r.value+t.value,isHighlighted:r.isHighlighted}:e.push(t)}}}(r?[{value:r,isHighlighted:!1}]:[]);return t.forEach((function(e){var t=e.split("__/aa-highlight__");n.add({value:t[0],isHighlighted:!0}),""!==t[1]&&n.add({value:t[1],isHighlighted:!1})})),n.get()}({highlightedValue:u})).some((function(e){return e.isHighlighted}))?t.map((function(e,r){return y(y({},e),{},{isHighlighted:!v(t,r)})})):t.map((function(e){return y(y({},e),{},{isHighlighted:!1})}));var t,r,n,i,o,u}function O(e){var t=e.onRemove;return{item:function(e){var r=e.item,n=e.createElement;return n(e.Fragment,null,n("div",{className:"aa-ItemIcon aa-ItemIcon--no-border"},n("svg",{width:"20",height:"20",viewBox:"0 0 22 22",fill:"currentColor"},n("path",{d:"M0 0h24v24H0z",fill:"none"}),n("path",{d:"M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"}))),n("div",{className:"aa-ItemContent"},n("div",{className:"aa-ItemContentTitle"},function(e){var t=e.hit,r=e.attribute,n=e.tagName,i=void 0===n?"mark":n,o=e.createElement,u=void 0===o?a:o;return _({hit:t,attribute:r}).map((function(e){return e.isHighlighted?u(i,{key:e.value,children:e.value}):e.value}))}({hit:r,attribute:"query",createElement:n}))),n("div",{className:"aa-ItemActions"},n("button",{className:"aa-ItemActionButton",title:"Remove this search",onClick:function(e){e.stopPropagation(),t(r.id)}},n("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor"},n("path",{d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})))))}}}function S(e){var t=e.storage,r=e.transformSource,o=void 0===r?function(e){return e.source}:r,u=function(e){return{add:function(t){e.onRemove(t.id),e.onAdd(t)},remove:function(t){e.onRemove(t)},getAll:function(t){return e.getAll(t)}}}(t),a={current:[]};return{subscribe:function(e){(0,e.onSelect)((function(e){var t=e.item,r=e.state,n=e.source.getItemInputValue({item:t,state:r});n&&u.add({id:n,query:n})}))},onSubmit:function(e){var t=e.state.query;t&&u.add({id:t,query:t})},getSources:function(e){var t=e.query,r=e.refresh;function n(e){u.remove(e),r()}a.current=u.getAll(t);var i=O({onRemove:n});return Promise.resolve(a.current).then((function(e){return 0===e.length?[]:[o({source:{sourceId:"recentSearchesPlugin",getItemInputValue:function(e){return e.item.query},getItems:function(){return e},templates:i},onRemove:n})]}))},data:{getAlgoliaSearchParams:function(){var e,t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Array.isArray(a.current)?n(n({},r),{},{facetFilters:[].concat(i(null!==(e=r.facetFilters)&&void 0!==e?e:[]),i(a.current.map((function(e){return["objectID:-".concat(e.query)]})))),hitsPerPage:Math.max(1,(null!==(t=r.hitsPerPage)&&void 0!==t?t:10)-a.current.length)}):r}}}}var P="AUTOCOMPLETE_RECENT_SEARCHES",j="__AUTOCOMPLETE_RECENT_SEARCHES_PLUGIN_TEST_KEY__";function I(e){var t=e.key;return function(){try{return localStorage.setItem(j,""),localStorage.removeItem(j),!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 w(e){var t=e.item,r=e.query;return n(n({},t),{},{_highlightResult:{query:{value:r?t.query.replace(new RegExp(r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),"__aa-highlight__".concat(r,"__/aa-highlight__")):t.query}}})}function A(e){var t=e.query,r=e.items,n=e.limit;return t?r.filter((function(e){return e.query.toLowerCase().includes(t.toLowerCase())})).slice(0,n).map((function(e){return w({item:e,query:t})})):r.slice(0,n).map((function(e){return w({item:e,query:t})}))}e.createLocalStorageRecentSearchesPlugin=function(e){var t=e.key,r=e.limit,n=void 0===r?5:r,o=e.transformSource,u=e.search,a=void 0===u?A:u;return S({transformSource:o,storage:function(e){var t=e.key,r=e.limit,n=e.search,o=I({key:t});return{getAll:function(){return n({query:arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",items:o.getItem(),limit:r}).slice(0,r)},onAdd:function(e){o.setItem([e].concat(i(o.getItem())))},onRemove:function(e){o.setItem(o.getItem().filter((function(t){return t.id!==e})))}}}({key:[P,t].join(":"),limit:n,search:a})})},e.createRecentSearchesPlugin=S,e.getTemplates=O,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.production.js.map
{
"name": "@algolia/autocomplete-plugin-recent-searches",
"description": "A plugin to add recent searches to Algolia Autocomplete.",
"version": "1.0.0-alpha.40",
"version": "1.0.0-alpha.41",
"license": "MIT",

@@ -34,6 +34,6 @@ "homepage": "https://github.com/algolia/autocomplete.js",

"dependencies": {
"@algolia/autocomplete-core": "1.0.0-alpha.40",
"@algolia/autocomplete-js": "1.0.0-alpha.40",
"@algolia/autocomplete-preset-algolia": "1.0.0-alpha.40",
"@algolia/autocomplete-shared": "1.0.0-alpha.40"
"@algolia/autocomplete-core": "1.0.0-alpha.41",
"@algolia/autocomplete-js": "1.0.0-alpha.41",
"@algolia/autocomplete-preset-algolia": "1.0.0-alpha.41",
"@algolia/autocomplete-shared": "1.0.0-alpha.41"
},

@@ -40,0 +40,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc