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

@algolia/autocomplete-core

Package Overview
Dependencies
Maintainers
68
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/autocomplete-core - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

89

dist/esm/onInput.js

@@ -13,4 +13,5 @@ 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; }

import { preResolve, resolve, postResolve } from './resolve';
import { getActiveItem } from './utils';
import { createConcurrentSafePromise, getActiveItem } from './utils';
var lastStalledId = null;
var runConcurrentSafePromise = createConcurrentSafePromise();
export function onInput(_ref) {

@@ -41,12 +42,19 @@ var event = _ref.event,

setStatus('idle');
setCollections(store.getState().collections.map(function (collection) {
var collections = store.getState().collections.map(function (collection) {
return _objectSpread(_objectSpread({}, collection), {}, {
items: []
});
}));
});
setStatus('idle');
setCollections(collections);
setIsOpen((_nextState$isOpen = nextState.isOpen) !== null && _nextState$isOpen !== void 0 ? _nextState$isOpen : props.shouldPanelOpen({
state: store.getState()
}));
return Promise.resolve();
})); // We make sure to update the latest resolved value of the tracked
// promises to keep late resolving promises from "cancelling" the state
// updates performed in this code path.
// We chain with a void promise to respect `onInput`'s expected return type.
return runConcurrentSafePromise(collections).then(function () {
return Promise.resolve();
});
}

@@ -57,4 +65,10 @@

setStatus('stalled');
}, props.stallThreshold);
return props.getSources(_objectSpread({
}, props.stallThreshold); // We track the entire promise chain triggered by `onInput` before mutating
// the Autocomplete state to make sure that any state manipulation is based on
// fresh data regardless of when promises individually resolve.
// We don't track nested promises and only rely on the full chain resolution,
// meaning we should only ever manipulate the state once this concurrent-safe
// promise is resolved.
return runConcurrentSafePromise(props.getSources(_objectSpread({
query: query,

@@ -64,3 +78,2 @@ refresh: refresh,

}, setters)).then(function (sources) {
setStatus('loading');
return Promise.all(sources.map(function (source) {

@@ -82,34 +95,34 @@ return Promise.resolve(source.getItems(_objectSpread({

});
}).then(function (collections) {
var _nextState$isOpen2;
});
})).then(function (collections) {
var _nextState$isOpen2;
setStatus('idle');
setCollections(collections);
var isPanelOpen = props.shouldPanelOpen({
setStatus('idle');
setCollections(collections);
var isPanelOpen = props.shouldPanelOpen({
state: store.getState()
});
setIsOpen((_nextState$isOpen2 = nextState.isOpen) !== null && _nextState$isOpen2 !== void 0 ? _nextState$isOpen2 : props.openOnFocus && !query && isPanelOpen || isPanelOpen);
var highlightedItem = getActiveItem(store.getState());
if (store.getState().activeItemId !== null && highlightedItem) {
var item = highlightedItem.item,
itemInputValue = highlightedItem.itemInputValue,
itemUrl = highlightedItem.itemUrl,
source = highlightedItem.source;
source.onActive(_objectSpread({
event: event,
item: item,
itemInputValue: itemInputValue,
itemUrl: itemUrl,
refresh: refresh,
source: source,
state: store.getState()
});
setIsOpen((_nextState$isOpen2 = nextState.isOpen) !== null && _nextState$isOpen2 !== void 0 ? _nextState$isOpen2 : props.openOnFocus && !query && isPanelOpen || isPanelOpen);
var highlightedItem = getActiveItem(store.getState());
if (store.getState().activeItemId !== null && highlightedItem) {
var item = highlightedItem.item,
itemInputValue = highlightedItem.itemInputValue,
itemUrl = highlightedItem.itemUrl,
source = highlightedItem.source;
source.onActive(_objectSpread({
event: event,
item: item,
itemInputValue: itemInputValue,
itemUrl: itemUrl,
refresh: refresh,
source: source,
state: store.getState()
}, setters));
}
}).finally(function () {
if (lastStalledId) {
props.environment.clearTimeout(lastStalledId);
}
});
}, setters));
}
}).finally(function () {
if (lastStalledId) {
props.environment.clearTimeout(lastStalledId);
}
});
}

@@ -8,2 +8,2 @@ import { MaybePromise } from '@algolia/autocomplete-shared';

*/
export declare function createConcurrentSafePromise<TValue>(): (promise: MaybePromise<TValue>) => Promise<TValue>;
export declare function createConcurrentSafePromise(): <TValue>(promise: MaybePromise<TValue>) => Promise<TValue>;

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

export declare const version = "1.4.0";
export declare const version = "1.4.1";

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

export var version = '1.4.0';
export var version = '1.4.1';

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

/*! @algolia/autocomplete-core 1.4.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
/*! @algolia/autocomplete-core 1.4.1 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
(function (global, factory) {

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

/**
* Creates a runner that executes promises in a concurrent-safe way.
*
* This is useful to prevent older promises to resolve after a newer promise,
* otherwise resulting in stale resolved values.
*/
function createConcurrentSafePromise() {
var basePromiseId = -1;
var latestResolvedId = -1;
var latestResolvedValue = undefined;
return function runConcurrentSafePromise(promise) {
basePromiseId++;
var currentPromiseId = basePromiseId;
return Promise.resolve(promise).then(function (x) {
// The promise might take too long to resolve and get outdated. This would
// result in resolving stale values.
// When this happens, we ignore the promise value and return the one
// coming from the latest resolved value.
//
// +----------------------------------+
// | 100ms |
// | run(1) +---> R1 |
// | 300ms |
// | run(2) +-------------> R2 (SKIP) |
// | 200ms |
// | run(3) +--------> R3 |
// +----------------------------------+
if (latestResolvedValue && currentPromiseId < latestResolvedId) {
return latestResolvedValue;
}
latestResolvedId = currentPromiseId;
latestResolvedValue = x;
return x;
});
};
}
/**
* Returns the next active item ID from the current state.

@@ -827,2 +865,3 @@ *

var lastStalledId = null;
var runConcurrentSafePromise = createConcurrentSafePromise();
function onInput(_ref) {

@@ -853,12 +892,19 @@ var event = _ref.event,

setStatus('idle');
setCollections(store.getState().collections.map(function (collection) {
var collections = store.getState().collections.map(function (collection) {
return _objectSpread2(_objectSpread2({}, collection), {}, {
items: []
});
}));
});
setStatus('idle');
setCollections(collections);
setIsOpen((_nextState$isOpen = nextState.isOpen) !== null && _nextState$isOpen !== void 0 ? _nextState$isOpen : props.shouldPanelOpen({
state: store.getState()
}));
return Promise.resolve();
})); // We make sure to update the latest resolved value of the tracked
// promises to keep late resolving promises from "cancelling" the state
// updates performed in this code path.
// We chain with a void promise to respect `onInput`'s expected return type.
return runConcurrentSafePromise(collections).then(function () {
return Promise.resolve();
});
}

@@ -869,4 +915,10 @@

setStatus('stalled');
}, props.stallThreshold);
return props.getSources(_objectSpread2({
}, props.stallThreshold); // We track the entire promise chain triggered by `onInput` before mutating
// the Autocomplete state to make sure that any state manipulation is based on
// fresh data regardless of when promises individually resolve.
// We don't track nested promises and only rely on the full chain resolution,
// meaning we should only ever manipulate the state once this concurrent-safe
// promise is resolved.
return runConcurrentSafePromise(props.getSources(_objectSpread2({
query: query,

@@ -876,3 +928,2 @@ refresh: refresh,

}, setters)).then(function (sources) {
setStatus('loading');
return Promise.all(sources.map(function (source) {

@@ -894,33 +945,33 @@ return Promise.resolve(source.getItems(_objectSpread2({

});
}).then(function (collections) {
var _nextState$isOpen2;
});
})).then(function (collections) {
var _nextState$isOpen2;
setStatus('idle');
setCollections(collections);
var isPanelOpen = props.shouldPanelOpen({
setStatus('idle');
setCollections(collections);
var isPanelOpen = props.shouldPanelOpen({
state: store.getState()
});
setIsOpen((_nextState$isOpen2 = nextState.isOpen) !== null && _nextState$isOpen2 !== void 0 ? _nextState$isOpen2 : props.openOnFocus && !query && isPanelOpen || isPanelOpen);
var highlightedItem = getActiveItem(store.getState());
if (store.getState().activeItemId !== null && highlightedItem) {
var item = highlightedItem.item,
itemInputValue = highlightedItem.itemInputValue,
itemUrl = highlightedItem.itemUrl,
source = highlightedItem.source;
source.onActive(_objectSpread2({
event: event,
item: item,
itemInputValue: itemInputValue,
itemUrl: itemUrl,
refresh: refresh,
source: source,
state: store.getState()
});
setIsOpen((_nextState$isOpen2 = nextState.isOpen) !== null && _nextState$isOpen2 !== void 0 ? _nextState$isOpen2 : props.openOnFocus && !query && isPanelOpen || isPanelOpen);
var highlightedItem = getActiveItem(store.getState());
if (store.getState().activeItemId !== null && highlightedItem) {
var item = highlightedItem.item,
itemInputValue = highlightedItem.itemInputValue,
itemUrl = highlightedItem.itemUrl,
source = highlightedItem.source;
source.onActive(_objectSpread2({
event: event,
item: item,
itemInputValue: itemInputValue,
itemUrl: itemUrl,
refresh: refresh,
source: source,
state: store.getState()
}, setters));
}
}).finally(function () {
if (lastStalledId) {
props.environment.clearTimeout(lastStalledId);
}
});
}, setters));
}
}).finally(function () {
if (lastStalledId) {
props.environment.clearTimeout(lastStalledId);
}
});

@@ -1617,3 +1668,3 @@ }

var version = '1.4.0';
var version = '1.4.1';

@@ -1620,0 +1671,0 @@ exports.createAutocomplete = createAutocomplete;

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

/*! @algolia/autocomplete-core 1.4.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
!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-core"]={})}(this,(function(e){"use strict";function t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(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 r(e){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(Object(o),!0).forEach((function(n){t(e,n,o[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function o(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function i(e){return function(e){if(Array.isArray(e))return u(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 u(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 u(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 u(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 a(e){return e.reduce((function(e,t){return e.concat(t)}),[])}var c=0;function l(e){return 0===e.collections.length?0:e.collections.reduce((function(e,t){return e+t.items.length}),0)}var s=function(){};function p(e,t,n,r){if(!n)return null;if(e<0&&(null===t||null!==r&&0===t))return n+e;var o=(null===t?-1:t)+e;return o<=-1||o>=n?null===r?null:0:o}function f(e){var t=function(e){var t=e.collections.map((function(e){return e.items.length})).reduce((function(e,t,n){var r=(e[n-1]||0)+t;return e.push(r),e}),[]).reduce((function(t,n){return n<=e.activeItemId?t+1:t}),0);return e.collections[t]}(e);if(!t)return null;var n=t.items[function(e){for(var t=e.state,n=e.collection,r=!1,o=0,i=0;!1===r;){var u=t.collections[o];if(u===n){r=!0;break}i+=u.items.length,o++}return t.activeItemId-i}({state:e,collection:t})],r=t.source;return{item:n,itemInputValue:r.getItemInputValue({item:n,state:e}),itemUrl:r.getItemUrl({item:n,state:e}),source:r}}function m(e,t){return e===t||e.contains(t)}function v(e,t){var n,o="undefined"!=typeof window?window:{},u=e.plugins||[];return r(r({debug:!1,openOnFocus:!1,placeholder:"",autoFocus:!1,defaultActiveItemId:null,stallThreshold:300,environment:o,shouldPanelOpen:function(e){return l(e.state)>0},reshape:function(e){return e.sources}},e),{},{id:null!==(n=e.id)&&void 0!==n?n:"autocomplete-".concat(c++),plugins:u,initialState:r({activeItemId:null,query:"",completion:null,collections:[],isOpen:!1,status:"idle",context:{}},e.initialState),onStateChange:function(t){var n;null===(n=e.onStateChange)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onStateChange)||void 0===n?void 0:n.call(e,t)}))},onSubmit:function(t){var n;null===(n=e.onSubmit)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onSubmit)||void 0===n?void 0:n.call(e,t)}))},onReset:function(t){var n;null===(n=e.onReset)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onReset)||void 0===n?void 0:n.call(e,t)}))},getSources:function(n){return Promise.all([].concat(i(u.map((function(e){return e.getSources}))),[e.getSources]).filter(Boolean).map((function(e){return function(e,t){var n=[];return Promise.resolve(e(t)).then((function(e){return Promise.all(e.filter((function(e){return Boolean(e)})).map((function(e){if(e.sourceId,n.includes(e.sourceId))throw new Error("[Autocomplete] The `sourceId` ".concat(JSON.stringify(e.sourceId)," is not unique."));n.push(e.sourceId);var t=r({getItemInputValue:function(e){return e.state.query},getItemUrl:function(){},onSelect:function(e){(0,e.setIsOpen)(!1)},onActive:s},e);return Promise.resolve(t)})))}))}(e,n)}))).then((function(e){return a(e)})).then((function(e){return e.map((function(e){return r(r({},e),{},{onSelect:function(n){e.onSelect(n),t.forEach((function(e){var t;return null===(t=e.onSelect)||void 0===t?void 0:t.call(e,n)}))},onActive:function(n){e.onActive(n),t.forEach((function(e){var t;return null===(t=e.onActive)||void 0===t?void 0:t.call(e,n)}))}})}))}))},navigator:r({navigate:function(e){var t=e.itemUrl;o.location.assign(t)},navigateNewTab:function(e){var t=e.itemUrl,n=o.open(t,"_blank","noopener");null==n||n.focus()},navigateNewWindow:function(e){var t=e.itemUrl;o.open(t,"_blank","noopener")}},e.navigator)})}function d(e){return Boolean(e.execute)}function g(e,t){return n=e,Boolean(null==n?void 0:n.execute)?r(r({},e),{},{requests:e.queries.map((function(n){return{query:n,sourceId:t,transformResponse:e.transformResponse}}))}):{items:e,sourceId:t};var n}function h(e){var t=e.reduce((function(e,t){if(!d(t))return e.push(t),e;var n=t.searchClient,r=t.execute,o=t.requests,u=e.find((function(e){return d(t)&&d(e)&&e.searchClient===n&&e.execute===r}));if(u){var a;(a=u.items).push.apply(a,i(o))}else{var c={execute:r,items:o,searchClient:n};e.push(c)}return e}),[]).map((function(e){if(!d(e))return Promise.resolve(e);var t=e,n=t.execute,r=t.items;return n({searchClient:t.searchClient,requests:r})}));return Promise.all(t).then((function(e){return a(e)}))}function I(e,t){return t.map((function(t){var n=e.filter((function(e){return e.sourceId===t.sourceId})),o=n.map((function(e){return e.items})),i=n[0].transformResponse,u=i?i(function(e){var t=e.map((function(e){var t;return r(r({},e),{},{hits:null===(t=e.hits)||void 0===t?void 0:t.map((function(t){return r(r({},t),{},{__autocomplete_indexName:e.index,__autocomplete_queryID:e.queryID})}))})}));return{results:t,hits:t.map((function(e){return e.hits})).filter(Boolean),facetHits:t.map((function(e){var t;return null===(t=e.facetHits)||void 0===t?void 0:t.map((function(e){return{label:e.value,count:e.count,_highlightResult:{label:{value:e.highlighted}}}}))})).filter(Boolean)}}(o)):o;return u.every(Boolean),'The `getItems` function from source "'.concat(t.sourceId,'" must return an array of items but returned ').concat(JSON.stringify(void 0),".\n\nDid you forget to return items?\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"),{source:t,items:u}}))}var y=null;function S(e){var n=e.event,i=e.nextState,u=void 0===i?{}:i,c=e.props,l=e.query,s=e.refresh,p=e.store,m=o(e,["event","nextState","props","query","refresh","store"]);y&&c.environment.clearTimeout(y);var v,d=m.setCollections,S=m.setIsOpen,b=m.setQuery,O=m.setActiveItemId,w=m.setStatus;return b(l),O(c.defaultActiveItemId),l||!1!==c.openOnFocus?(w("loading"),y=c.environment.setTimeout((function(){w("stalled")}),c.stallThreshold),c.getSources(r({query:l,refresh:s,state:p.getState()},m)).then((function(e){return w("loading"),Promise.all(e.map((function(e){return Promise.resolve(e.getItems(r({query:l,refresh:s,state:p.getState()},m))).then((function(t){return g(t,e.sourceId)}))}))).then(h).then((function(t){return I(t,e)})).then((function(e){return function(e){var n=e.collections,o=e.props,i=e.state,u=n.reduce((function(e,n){return r(r({},e),{},t({},n.source.sourceId,r(r({},n.source),{},{getItems:function(){return a(n.items)}})))}),{});return a(o.reshape({sources:Object.values(u),sourcesBySourceId:u,state:i})).filter(Boolean).map((function(e){return{source:e,items:e.getItems()}}))}({collections:e,props:c,state:p.getState()})})).then((function(e){var t;w("idle"),d(e);var o=c.shouldPanelOpen({state:p.getState()});S(null!==(t=u.isOpen)&&void 0!==t?t:c.openOnFocus&&!l&&o||o);var i=f(p.getState());if(null!==p.getState().activeItemId&&i){var a=i.item,v=i.itemInputValue,g=i.itemUrl,h=i.source;h.onActive(r({event:n,item:a,itemInputValue:v,itemUrl:g,refresh:s,source:h,state:p.getState()},m))}})).finally((function(){y&&c.environment.clearTimeout(y)}))}))):(w("idle"),d(p.getState().collections.map((function(e){return r(r({},e),{},{items:[]})}))),S(null!==(v=u.isOpen)&&void 0!==v?v:c.shouldPanelOpen({state:p.getState()})),Promise.resolve())}function b(e){var t=e.props,n=e.refresh,i=e.store,u=o(e,["props","refresh","store"]);return{getEnvironmentProps:function(e){var n=e.inputElement,u=e.formElement,a=e.panelElement;return r({onTouchStart:function(e){!1!==i.getState().isOpen&&e.target!==n&&(!1===[u,a].some((function(n){return m(n,e.target)||m(n,t.environment.document.activeElement)}))&&i.dispatch("blur",null))},onTouchMove:function(e){!1!==i.getState().isOpen&&n===t.environment.document.activeElement&&e.target!==n&&n.blur()}},o(e,["inputElement","formElement","panelElement"]))},getRootProps:function(e){return r({role:"combobox","aria-expanded":i.getState().isOpen,"aria-haspopup":"listbox","aria-owns":i.getState().isOpen?"".concat(t.id,"-list"):void 0,"aria-labelledby":"".concat(t.id,"-label")},e)},getFormProps:function(e){e.inputElement;return r({action:"",noValidate:!0,role:"search",onSubmit:function(o){var a;o.preventDefault(),t.onSubmit(r({event:o,refresh:n,state:i.getState()},u)),i.dispatch("submit",null),null===(a=e.inputElement)||void 0===a||a.blur()},onReset:function(o){var a;o.preventDefault(),t.onReset(r({event:o,refresh:n,state:i.getState()},u)),i.dispatch("reset",null),null===(a=e.inputElement)||void 0===a||a.focus()}},o(e,["inputElement"]))},getLabelProps:function(e){return r({htmlFor:"".concat(t.id,"-input"),id:"".concat(t.id,"-label")},e)},getInputProps:function(e){function a(e){(t.openOnFocus||Boolean(i.getState().query))&&S(r({event:e,props:t,query:i.getState().completion||i.getState().query,refresh:n,store:i},u)),i.dispatch("focus",null)}var c="ontouchstart"in t.environment,l=e||{},s=(l.inputElement,l.maxLength),p=void 0===s?512:s,m=o(l,["inputElement","maxLength"]),v=f(i.getState());return r({"aria-autocomplete":"both","aria-activedescendant":i.getState().isOpen&&null!==i.getState().activeItemId?"".concat(t.id,"-item-").concat(i.getState().activeItemId):void 0,"aria-controls":i.getState().isOpen?"".concat(t.id,"-list"):void 0,"aria-labelledby":"".concat(t.id,"-label"),value:i.getState().completion||i.getState().query,id:"".concat(t.id,"-input"),autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",enterKeyHint:null!=v&&v.itemUrl?"go":"search",spellCheck:"false",autoFocus:t.autoFocus,placeholder:t.placeholder,maxLength:p,type:"search",onChange:function(e){S(r({event:e,props:t,query:e.currentTarget.value.slice(0,p),refresh:n,store:i},u))},onKeyDown:function(e){!function(e){var t=e.event,n=e.props,i=e.refresh,u=e.store,a=o(e,["event","props","refresh","store"]);if("ArrowUp"===t.key||"ArrowDown"===t.key){var c=function(){var e=n.environment.document.getElementById("".concat(n.id,"-item-").concat(u.getState().activeItemId));e&&(e.scrollIntoViewIfNeeded?e.scrollIntoViewIfNeeded(!1):e.scrollIntoView(!1))},l=function(){var e=f(u.getState());if(null!==u.getState().activeItemId&&e){var n=e.item,o=e.itemInputValue,c=e.itemUrl,l=e.source;l.onActive(r({event:t,item:n,itemInputValue:o,itemUrl:c,refresh:i,source:l,state:u.getState()},a))}};t.preventDefault(),!1===u.getState().isOpen&&(n.openOnFocus||Boolean(u.getState().query))?S(r({event:t,props:n,query:u.getState().query,refresh:i,store:u},a)).then((function(){u.dispatch(t.key,{nextActiveItemId:n.defaultActiveItemId}),l(),setTimeout(c,0)})):(u.dispatch(t.key,{}),l(),c())}else if("Escape"===t.key)t.preventDefault(),u.dispatch(t.key,null);else if("Enter"===t.key){if(null===u.getState().activeItemId||u.getState().collections.every((function(e){return 0===e.items.length})))return;t.preventDefault();var s=f(u.getState()),p=s.item,m=s.itemInputValue,v=s.itemUrl,d=s.source;if(t.metaKey||t.ctrlKey)void 0!==v&&(d.onSelect(r({event:t,item:p,itemInputValue:m,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),n.navigator.navigateNewTab({itemUrl:v,item:p,state:u.getState()}));else if(t.shiftKey)void 0!==v&&(d.onSelect(r({event:t,item:p,itemInputValue:m,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),n.navigator.navigateNewWindow({itemUrl:v,item:p,state:u.getState()}));else if(t.altKey);else{if(void 0!==v)return d.onSelect(r({event:t,item:p,itemInputValue:m,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),void n.navigator.navigate({itemUrl:v,item:p,state:u.getState()});S(r({event:t,nextState:{isOpen:!1},props:n,query:m,refresh:i,store:u},a)).then((function(){d.onSelect(r({event:t,item:p,itemInputValue:m,itemUrl:v,refresh:i,source:d,state:u.getState()},a))}))}}}(r({event:e,props:t,refresh:n,store:i},u))},onFocus:a,onBlur:function(){c||i.dispatch("blur",null)},onClick:function(n){e.inputElement!==t.environment.document.activeElement||i.getState().isOpen||a(n)}},m)},getPanelProps:function(e){return r({onMouseDown:function(e){e.preventDefault()},onMouseLeave:function(){i.dispatch("mouseleave",null)}},e)},getListProps:function(e){return r({role:"listbox","aria-labelledby":"".concat(t.id,"-label"),id:"".concat(t.id,"-list")},e)},getItemProps:function(e){var a=e.item,c=e.source,l=o(e,["item","source"]);return r({id:"".concat(t.id,"-item-").concat(a.__autocomplete_id),role:"option","aria-selected":i.getState().activeItemId===a.__autocomplete_id,onMouseMove:function(e){if(a.__autocomplete_id!==i.getState().activeItemId){i.dispatch("mousemove",a.__autocomplete_id);var t=f(i.getState());if(null!==i.getState().activeItemId&&t){var o=t.item,c=t.itemInputValue,l=t.itemUrl,s=t.source;s.onActive(r({event:e,item:o,itemInputValue:c,itemUrl:l,refresh:n,source:s,state:i.getState()},u))}}},onMouseDown:function(e){e.preventDefault()},onClick:function(e){var o=c.getItemInputValue({item:a,state:i.getState()}),l=c.getItemUrl({item:a,state:i.getState()});(l?Promise.resolve():S(r({event:e,nextState:{isOpen:!1},props:t,query:o,refresh:n,store:i},u))).then((function(){c.onSelect(r({event:e,item:a,itemInputValue:o,itemUrl:l,refresh:n,source:c,state:i.getState()},u))}))}},l)}}}function O(e){var t,n=e.state;return!1===n.isOpen||null===n.activeItemId?null:(null===(t=f(n))||void 0===t?void 0:t.itemInputValue)||null}var w=function(e,t){switch(t.type){case"setActiveItemId":return r(r({},e),{},{activeItemId:t.payload});case"setQuery":return r(r({},e),{},{query:t.payload,completion:null});case"setCollections":return r(r({},e),{},{collections:t.payload});case"setIsOpen":return r(r({},e),{},{isOpen:t.payload});case"setStatus":return r(r({},e),{},{status:t.payload});case"setContext":return r(r({},e),{},{context:r(r({},e.context),t.payload)});case"ArrowDown":var n=r(r({},e),{},{activeItemId:t.payload.hasOwnProperty("nextActiveItemId")?t.payload.nextActiveItemId:p(1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return r(r({},n),{},{completion:O({state:n})});case"ArrowUp":var o=r(r({},e),{},{activeItemId:p(-1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return r(r({},o),{},{completion:O({state:o})});case"Escape":return e.isOpen?r(r({},e),{},{activeItemId:null,isOpen:!1,completion:null}):r(r({},e),{},{activeItemId:null,query:"",status:"idle",collections:[]});case"submit":return r(r({},e),{},{activeItemId:null,isOpen:!1,status:"idle"});case"reset":return r(r({},e),{},{activeItemId:!0===t.props.openOnFocus?t.props.defaultActiveItemId:null,status:"idle",query:""});case"focus":return r(r({},e),{},{activeItemId:t.props.defaultActiveItemId,isOpen:(t.props.openOnFocus||Boolean(e.query))&&t.props.shouldPanelOpen({state:e})});case"blur":return t.props.debug?e:r(r({},e),{},{isOpen:!1,activeItemId:null});case"mousemove":return r(r({},e),{},{activeItemId:t.payload});case"mouseleave":return r(r({},e),{},{activeItemId:t.props.defaultActiveItemId});default:return"The reducer action ".concat(JSON.stringify(t.type)," is not supported."),e}};e.createAutocomplete=function(e){var t=[],n=v(e,t),o=function(e,t,n){var o=t.initialState;return{getState:function(){return o},dispatch:function(i,u){var a=r({},o);o=e(o,{type:i,props:t,payload:u}),n({state:o,prevState:a})}}}(w,n,(function(e){var t=e.prevState,o=e.state;n.onStateChange(r({prevState:t,state:o,refresh:c},i))})),i=function(e){var t=e.store;return{setActiveItemId:function(e){t.dispatch("setActiveItemId",e)},setQuery:function(e){t.dispatch("setQuery",e)},setCollections:function(e){var n=0,o=e.map((function(e){return r(r({},e),{},{items:a(e.items).map((function(e){return r(r({},e),{},{__autocomplete_id:n++})}))})}));t.dispatch("setCollections",o)},setIsOpen:function(e){t.dispatch("setIsOpen",e)},setStatus:function(e){t.dispatch("setStatus",e)},setContext:function(e){t.dispatch("setContext",e)}}}({store:o}),u=b(r({props:n,refresh:c,store:o},i));function c(){return S(r({event:new Event("input"),nextState:{isOpen:o.getState().isOpen},props:n,query:o.getState().query,refresh:c,store:o},i))}return n.plugins.forEach((function(e){var n;return null===(n=e.subscribe)||void 0===n?void 0:n.call(e,r(r({},i),{},{refresh:c,onSelect:function(e){t.push({onSelect:e})},onActive:function(e){t.push({onActive:e})}}))})),r(r({refresh:c},u),i)},e.getDefaultProps=v,e.version="1.4.0",Object.defineProperty(e,"__esModule",{value:!0})}));
/*! @algolia/autocomplete-core 1.4.1 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
!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-core"]={})}(this,(function(e){"use strict";function t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(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 r(e){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(Object(o),!0).forEach((function(n){t(e,n,o[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function o(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function i(e){return function(e){if(Array.isArray(e))return u(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 u(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 u(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 u(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 a(e){return e.reduce((function(e,t){return e.concat(t)}),[])}var c=0;function l(e){return 0===e.collections.length?0:e.collections.reduce((function(e,t){return e+t.items.length}),0)}var s=function(){};function f(e,t,n,r){if(!n)return null;if(e<0&&(null===t||null!==r&&0===t))return n+e;var o=(null===t?-1:t)+e;return o<=-1||o>=n?null===r?null:0:o}function p(e){var t=function(e){var t=e.collections.map((function(e){return e.items.length})).reduce((function(e,t,n){var r=(e[n-1]||0)+t;return e.push(r),e}),[]).reduce((function(t,n){return n<=e.activeItemId?t+1:t}),0);return e.collections[t]}(e);if(!t)return null;var n=t.items[function(e){for(var t=e.state,n=e.collection,r=!1,o=0,i=0;!1===r;){var u=t.collections[o];if(u===n){r=!0;break}i+=u.items.length,o++}return t.activeItemId-i}({state:e,collection:t})],r=t.source;return{item:n,itemInputValue:r.getItemInputValue({item:n,state:e}),itemUrl:r.getItemUrl({item:n,state:e}),source:r}}function m(e,t){return e===t||e.contains(t)}function v(e,t){var n,o="undefined"!=typeof window?window:{},u=e.plugins||[];return r(r({debug:!1,openOnFocus:!1,placeholder:"",autoFocus:!1,defaultActiveItemId:null,stallThreshold:300,environment:o,shouldPanelOpen:function(e){return l(e.state)>0},reshape:function(e){return e.sources}},e),{},{id:null!==(n=e.id)&&void 0!==n?n:"autocomplete-".concat(c++),plugins:u,initialState:r({activeItemId:null,query:"",completion:null,collections:[],isOpen:!1,status:"idle",context:{}},e.initialState),onStateChange:function(t){var n;null===(n=e.onStateChange)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onStateChange)||void 0===n?void 0:n.call(e,t)}))},onSubmit:function(t){var n;null===(n=e.onSubmit)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onSubmit)||void 0===n?void 0:n.call(e,t)}))},onReset:function(t){var n;null===(n=e.onReset)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onReset)||void 0===n?void 0:n.call(e,t)}))},getSources:function(n){return Promise.all([].concat(i(u.map((function(e){return e.getSources}))),[e.getSources]).filter(Boolean).map((function(e){return function(e,t){var n=[];return Promise.resolve(e(t)).then((function(e){return Promise.all(e.filter((function(e){return Boolean(e)})).map((function(e){if(e.sourceId,n.includes(e.sourceId))throw new Error("[Autocomplete] The `sourceId` ".concat(JSON.stringify(e.sourceId)," is not unique."));n.push(e.sourceId);var t=r({getItemInputValue:function(e){return e.state.query},getItemUrl:function(){},onSelect:function(e){(0,e.setIsOpen)(!1)},onActive:s},e);return Promise.resolve(t)})))}))}(e,n)}))).then((function(e){return a(e)})).then((function(e){return e.map((function(e){return r(r({},e),{},{onSelect:function(n){e.onSelect(n),t.forEach((function(e){var t;return null===(t=e.onSelect)||void 0===t?void 0:t.call(e,n)}))},onActive:function(n){e.onActive(n),t.forEach((function(e){var t;return null===(t=e.onActive)||void 0===t?void 0:t.call(e,n)}))}})}))}))},navigator:r({navigate:function(e){var t=e.itemUrl;o.location.assign(t)},navigateNewTab:function(e){var t=e.itemUrl,n=o.open(t,"_blank","noopener");null==n||n.focus()},navigateNewWindow:function(e){var t=e.itemUrl;o.open(t,"_blank","noopener")}},e.navigator)})}function d(e){return Boolean(e.execute)}function h(e,t){return n=e,Boolean(null==n?void 0:n.execute)?r(r({},e),{},{requests:e.queries.map((function(n){return{query:n,sourceId:t,transformResponse:e.transformResponse}}))}):{items:e,sourceId:t};var n}function g(e){var t=e.reduce((function(e,t){if(!d(t))return e.push(t),e;var n=t.searchClient,r=t.execute,o=t.requests,u=e.find((function(e){return d(t)&&d(e)&&e.searchClient===n&&e.execute===r}));if(u){var a;(a=u.items).push.apply(a,i(o))}else{var c={execute:r,items:o,searchClient:n};e.push(c)}return e}),[]).map((function(e){if(!d(e))return Promise.resolve(e);var t=e,n=t.execute,r=t.items;return n({searchClient:t.searchClient,requests:r})}));return Promise.all(t).then((function(e){return a(e)}))}function I(e,t){return t.map((function(t){var n=e.filter((function(e){return e.sourceId===t.sourceId})),o=n.map((function(e){return e.items})),i=n[0].transformResponse,u=i?i(function(e){var t=e.map((function(e){var t;return r(r({},e),{},{hits:null===(t=e.hits)||void 0===t?void 0:t.map((function(t){return r(r({},t),{},{__autocomplete_indexName:e.index,__autocomplete_queryID:e.queryID})}))})}));return{results:t,hits:t.map((function(e){return e.hits})).filter(Boolean),facetHits:t.map((function(e){var t;return null===(t=e.facetHits)||void 0===t?void 0:t.map((function(e){return{label:e.value,count:e.count,_highlightResult:{label:{value:e.highlighted}}}}))})).filter(Boolean)}}(o)):o;return u.every(Boolean),'The `getItems` function from source "'.concat(t.sourceId,'" must return an array of items but returned ').concat(JSON.stringify(void 0),".\n\nDid you forget to return items?\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"),{source:t,items:u}}))}var y,S,b,O=null,w=(y=-1,S=-1,b=void 0,function(e){var t=++y;return Promise.resolve(e).then((function(e){return b&&t<S?b:(S=t,b=e,e)}))});function P(e){var n=e.event,i=e.nextState,u=void 0===i?{}:i,c=e.props,l=e.query,s=e.refresh,f=e.store,m=o(e,["event","nextState","props","query","refresh","store"]);O&&c.environment.clearTimeout(O);var v=m.setCollections,d=m.setIsOpen,y=m.setQuery,S=m.setActiveItemId,b=m.setStatus;if(y(l),S(c.defaultActiveItemId),!l&&!1===c.openOnFocus){var P,A=f.getState().collections.map((function(e){return r(r({},e),{},{items:[]})}));return b("idle"),v(A),d(null!==(P=u.isOpen)&&void 0!==P?P:c.shouldPanelOpen({state:f.getState()})),w(A).then((function(){return Promise.resolve()}))}return b("loading"),O=c.environment.setTimeout((function(){b("stalled")}),c.stallThreshold),w(c.getSources(r({query:l,refresh:s,state:f.getState()},m)).then((function(e){return Promise.all(e.map((function(e){return Promise.resolve(e.getItems(r({query:l,refresh:s,state:f.getState()},m))).then((function(t){return h(t,e.sourceId)}))}))).then(g).then((function(t){return I(t,e)})).then((function(e){return function(e){var n=e.collections,o=e.props,i=e.state,u=n.reduce((function(e,n){return r(r({},e),{},t({},n.source.sourceId,r(r({},n.source),{},{getItems:function(){return a(n.items)}})))}),{});return a(o.reshape({sources:Object.values(u),sourcesBySourceId:u,state:i})).filter(Boolean).map((function(e){return{source:e,items:e.getItems()}}))}({collections:e,props:c,state:f.getState()})}))}))).then((function(e){var t;b("idle"),v(e);var o=c.shouldPanelOpen({state:f.getState()});d(null!==(t=u.isOpen)&&void 0!==t?t:c.openOnFocus&&!l&&o||o);var i=p(f.getState());if(null!==f.getState().activeItemId&&i){var a=i.item,h=i.itemInputValue,g=i.itemUrl,I=i.source;I.onActive(r({event:n,item:a,itemInputValue:h,itemUrl:g,refresh:s,source:I,state:f.getState()},m))}})).finally((function(){O&&c.environment.clearTimeout(O)}))}function A(e){var t=e.props,n=e.refresh,i=e.store,u=o(e,["props","refresh","store"]);return{getEnvironmentProps:function(e){var n=e.inputElement,u=e.formElement,a=e.panelElement;return r({onTouchStart:function(e){!1!==i.getState().isOpen&&e.target!==n&&(!1===[u,a].some((function(n){return m(n,e.target)||m(n,t.environment.document.activeElement)}))&&i.dispatch("blur",null))},onTouchMove:function(e){!1!==i.getState().isOpen&&n===t.environment.document.activeElement&&e.target!==n&&n.blur()}},o(e,["inputElement","formElement","panelElement"]))},getRootProps:function(e){return r({role:"combobox","aria-expanded":i.getState().isOpen,"aria-haspopup":"listbox","aria-owns":i.getState().isOpen?"".concat(t.id,"-list"):void 0,"aria-labelledby":"".concat(t.id,"-label")},e)},getFormProps:function(e){e.inputElement;return r({action:"",noValidate:!0,role:"search",onSubmit:function(o){var a;o.preventDefault(),t.onSubmit(r({event:o,refresh:n,state:i.getState()},u)),i.dispatch("submit",null),null===(a=e.inputElement)||void 0===a||a.blur()},onReset:function(o){var a;o.preventDefault(),t.onReset(r({event:o,refresh:n,state:i.getState()},u)),i.dispatch("reset",null),null===(a=e.inputElement)||void 0===a||a.focus()}},o(e,["inputElement"]))},getLabelProps:function(e){return r({htmlFor:"".concat(t.id,"-input"),id:"".concat(t.id,"-label")},e)},getInputProps:function(e){function a(e){(t.openOnFocus||Boolean(i.getState().query))&&P(r({event:e,props:t,query:i.getState().completion||i.getState().query,refresh:n,store:i},u)),i.dispatch("focus",null)}var c="ontouchstart"in t.environment,l=e||{},s=(l.inputElement,l.maxLength),f=void 0===s?512:s,m=o(l,["inputElement","maxLength"]),v=p(i.getState());return r({"aria-autocomplete":"both","aria-activedescendant":i.getState().isOpen&&null!==i.getState().activeItemId?"".concat(t.id,"-item-").concat(i.getState().activeItemId):void 0,"aria-controls":i.getState().isOpen?"".concat(t.id,"-list"):void 0,"aria-labelledby":"".concat(t.id,"-label"),value:i.getState().completion||i.getState().query,id:"".concat(t.id,"-input"),autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",enterKeyHint:null!=v&&v.itemUrl?"go":"search",spellCheck:"false",autoFocus:t.autoFocus,placeholder:t.placeholder,maxLength:f,type:"search",onChange:function(e){P(r({event:e,props:t,query:e.currentTarget.value.slice(0,f),refresh:n,store:i},u))},onKeyDown:function(e){!function(e){var t=e.event,n=e.props,i=e.refresh,u=e.store,a=o(e,["event","props","refresh","store"]);if("ArrowUp"===t.key||"ArrowDown"===t.key){var c=function(){var e=n.environment.document.getElementById("".concat(n.id,"-item-").concat(u.getState().activeItemId));e&&(e.scrollIntoViewIfNeeded?e.scrollIntoViewIfNeeded(!1):e.scrollIntoView(!1))},l=function(){var e=p(u.getState());if(null!==u.getState().activeItemId&&e){var n=e.item,o=e.itemInputValue,c=e.itemUrl,l=e.source;l.onActive(r({event:t,item:n,itemInputValue:o,itemUrl:c,refresh:i,source:l,state:u.getState()},a))}};t.preventDefault(),!1===u.getState().isOpen&&(n.openOnFocus||Boolean(u.getState().query))?P(r({event:t,props:n,query:u.getState().query,refresh:i,store:u},a)).then((function(){u.dispatch(t.key,{nextActiveItemId:n.defaultActiveItemId}),l(),setTimeout(c,0)})):(u.dispatch(t.key,{}),l(),c())}else if("Escape"===t.key)t.preventDefault(),u.dispatch(t.key,null);else if("Enter"===t.key){if(null===u.getState().activeItemId||u.getState().collections.every((function(e){return 0===e.items.length})))return;t.preventDefault();var s=p(u.getState()),f=s.item,m=s.itemInputValue,v=s.itemUrl,d=s.source;if(t.metaKey||t.ctrlKey)void 0!==v&&(d.onSelect(r({event:t,item:f,itemInputValue:m,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),n.navigator.navigateNewTab({itemUrl:v,item:f,state:u.getState()}));else if(t.shiftKey)void 0!==v&&(d.onSelect(r({event:t,item:f,itemInputValue:m,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),n.navigator.navigateNewWindow({itemUrl:v,item:f,state:u.getState()}));else if(t.altKey);else{if(void 0!==v)return d.onSelect(r({event:t,item:f,itemInputValue:m,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),void n.navigator.navigate({itemUrl:v,item:f,state:u.getState()});P(r({event:t,nextState:{isOpen:!1},props:n,query:m,refresh:i,store:u},a)).then((function(){d.onSelect(r({event:t,item:f,itemInputValue:m,itemUrl:v,refresh:i,source:d,state:u.getState()},a))}))}}}(r({event:e,props:t,refresh:n,store:i},u))},onFocus:a,onBlur:function(){c||i.dispatch("blur",null)},onClick:function(n){e.inputElement!==t.environment.document.activeElement||i.getState().isOpen||a(n)}},m)},getPanelProps:function(e){return r({onMouseDown:function(e){e.preventDefault()},onMouseLeave:function(){i.dispatch("mouseleave",null)}},e)},getListProps:function(e){return r({role:"listbox","aria-labelledby":"".concat(t.id,"-label"),id:"".concat(t.id,"-list")},e)},getItemProps:function(e){var a=e.item,c=e.source,l=o(e,["item","source"]);return r({id:"".concat(t.id,"-item-").concat(a.__autocomplete_id),role:"option","aria-selected":i.getState().activeItemId===a.__autocomplete_id,onMouseMove:function(e){if(a.__autocomplete_id!==i.getState().activeItemId){i.dispatch("mousemove",a.__autocomplete_id);var t=p(i.getState());if(null!==i.getState().activeItemId&&t){var o=t.item,c=t.itemInputValue,l=t.itemUrl,s=t.source;s.onActive(r({event:e,item:o,itemInputValue:c,itemUrl:l,refresh:n,source:s,state:i.getState()},u))}}},onMouseDown:function(e){e.preventDefault()},onClick:function(e){var o=c.getItemInputValue({item:a,state:i.getState()}),l=c.getItemUrl({item:a,state:i.getState()});(l?Promise.resolve():P(r({event:e,nextState:{isOpen:!1},props:t,query:o,refresh:n,store:i},u))).then((function(){c.onSelect(r({event:e,item:a,itemInputValue:o,itemUrl:l,refresh:n,source:c,state:i.getState()},u))}))}},l)}}}function x(e){var t,n=e.state;return!1===n.isOpen||null===n.activeItemId?null:(null===(t=p(n))||void 0===t?void 0:t.itemInputValue)||null}var E=function(e,t){switch(t.type){case"setActiveItemId":return r(r({},e),{},{activeItemId:t.payload});case"setQuery":return r(r({},e),{},{query:t.payload,completion:null});case"setCollections":return r(r({},e),{},{collections:t.payload});case"setIsOpen":return r(r({},e),{},{isOpen:t.payload});case"setStatus":return r(r({},e),{},{status:t.payload});case"setContext":return r(r({},e),{},{context:r(r({},e.context),t.payload)});case"ArrowDown":var n=r(r({},e),{},{activeItemId:t.payload.hasOwnProperty("nextActiveItemId")?t.payload.nextActiveItemId:f(1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return r(r({},n),{},{completion:x({state:n})});case"ArrowUp":var o=r(r({},e),{},{activeItemId:f(-1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return r(r({},o),{},{completion:x({state:o})});case"Escape":return e.isOpen?r(r({},e),{},{activeItemId:null,isOpen:!1,completion:null}):r(r({},e),{},{activeItemId:null,query:"",status:"idle",collections:[]});case"submit":return r(r({},e),{},{activeItemId:null,isOpen:!1,status:"idle"});case"reset":return r(r({},e),{},{activeItemId:!0===t.props.openOnFocus?t.props.defaultActiveItemId:null,status:"idle",query:""});case"focus":return r(r({},e),{},{activeItemId:t.props.defaultActiveItemId,isOpen:(t.props.openOnFocus||Boolean(e.query))&&t.props.shouldPanelOpen({state:e})});case"blur":return t.props.debug?e:r(r({},e),{},{isOpen:!1,activeItemId:null});case"mousemove":return r(r({},e),{},{activeItemId:t.payload});case"mouseleave":return r(r({},e),{},{activeItemId:t.props.defaultActiveItemId});default:return"The reducer action ".concat(JSON.stringify(t.type)," is not supported."),e}};e.createAutocomplete=function(e){var t=[],n=v(e,t),o=function(e,t,n){var o=t.initialState;return{getState:function(){return o},dispatch:function(i,u){var a=r({},o);o=e(o,{type:i,props:t,payload:u}),n({state:o,prevState:a})}}}(E,n,(function(e){var t=e.prevState,o=e.state;n.onStateChange(r({prevState:t,state:o,refresh:c},i))})),i=function(e){var t=e.store;return{setActiveItemId:function(e){t.dispatch("setActiveItemId",e)},setQuery:function(e){t.dispatch("setQuery",e)},setCollections:function(e){var n=0,o=e.map((function(e){return r(r({},e),{},{items:a(e.items).map((function(e){return r(r({},e),{},{__autocomplete_id:n++})}))})}));t.dispatch("setCollections",o)},setIsOpen:function(e){t.dispatch("setIsOpen",e)},setStatus:function(e){t.dispatch("setStatus",e)},setContext:function(e){t.dispatch("setContext",e)}}}({store:o}),u=A(r({props:n,refresh:c,store:o},i));function c(){return P(r({event:new Event("input"),nextState:{isOpen:o.getState().isOpen},props:n,query:o.getState().query,refresh:c,store:o},i))}return n.plugins.forEach((function(e){var n;return null===(n=e.subscribe)||void 0===n?void 0:n.call(e,r(r({},i),{},{refresh:c,onSelect:function(e){t.push({onSelect:e})},onActive:function(e){t.push({onActive:e})}}))})),r(r({refresh:c},u),i)},e.getDefaultProps=v,e.version="1.4.1",Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.production.js.map
{
"name": "@algolia/autocomplete-core",
"description": "Core primitives for building autocomplete experiences.",
"version": "1.4.0",
"version": "1.4.1",
"license": "MIT",

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

"dependencies": {
"@algolia/autocomplete-shared": "1.4.0"
"@algolia/autocomplete-shared": "1.4.1"
},
"devDependencies": {
"@algolia/autocomplete-preset-algolia": "1.4.0",
"@algolia/autocomplete-preset-algolia": "1.4.1",
"@algolia/client-search": "4.9.1",

@@ -40,0 +40,0 @@ "algoliasearch": "4.9.1"

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