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

@algolia/autocomplete-core

Package Overview
Dependencies
Maintainers
69
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.5.0 to 1.5.1

3

dist/esm/createStore.js

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

});
}
},
shouldSkipPendingUpdate: false
};
}

@@ -41,3 +41,11 @@ var _excluded = ["props", "refresh", "store"],

onTouchStart: function onTouchStart(event) {
if (store.getState().isOpen === false || event.target === inputElement) {
// The `onTouchStart` event shouldn't trigger the `blur` handler when
// it's not an interaction with Autocomplete. We detect it with the
// following heuristics:
// - the panel is closed AND there are no running requests
// (no interaction with the autocomplete, no future state updates)
// - OR the touched target is the input element (should open the panel)
var isNotAutocompleteInteraction = store.getState().isOpen === false && !onInput.isRunning();
if (isNotAutocompleteInteraction || event.target === inputElement) {
return;

@@ -51,3 +59,10 @@ }

if (isTargetWithinAutocomplete === false) {
store.dispatch('blur', null);
store.dispatch('blur', null); // If requests are still running when the user closes the panel, they
// could reopen the panel once they resolve.
// We want to prevent any subsequent query from reopening the panel
// because it would result in an unsolicited UI behavior.
if (!props.debug && onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
}
}

@@ -178,3 +193,10 @@ },

if (!isTouchDevice) {
store.dispatch('blur', null);
store.dispatch('blur', null); // If requests are still running when the user closes the panel, they
// could reopen the panel once they resolve.
// We want to prevent any subsequent query from reopening the panel
// because it would result in an unsolicited UI behavior.
if (!props.debug && onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
}
}

@@ -181,0 +203,0 @@ },

@@ -17,2 +17,5 @@ import { AutocompleteScopeApi, AutocompleteState, AutocompleteStore, BaseItem, InternalAutocompleteOptions } from './types';

export declare function onInput<TItem extends BaseItem>({ event, nextState, props, query, refresh, store, ...setters }: OnInputParams<TItem>): Promise<void>;
export declare namespace onInput {
var isRunning: () => boolean;
}
export {};

@@ -97,3 +97,16 @@ var _excluded = ["event", "nextState", "props", "query", "refresh", "store"];

// Parameters passed to `onInput` could be stale when the following code
// executes, because `onInput` calls may not resolve in order.
// If it becomes a problem we'll need to save the last passed parameters.
// See: https://codesandbox.io/s/agitated-cookies-y290z
setStatus('idle');
if (store.shouldSkipPendingUpdate) {
if (!runConcurrentSafePromise.isRunning()) {
store.shouldSkipPendingUpdate = false;
}
return;
}
setCollections(collections);

@@ -126,2 +139,3 @@ var isPanelOpen = props.shouldPanelOpen({

});
}
}
onInput.isRunning = runConcurrentSafePromise.isRunning;

@@ -89,3 +89,10 @@ var _excluded = ["event", "props", "refresh", "store"];

event.preventDefault();
store.dispatch(event.key, null);
store.dispatch(event.key, null); // Hitting the `Escape` key signals the end of a user interaction with the
// autocomplete. At this point, we should ignore any requests that are still
// running and could reopen the panel once they resolve, because that would
// result in an unsolicited UI behavior.
if (onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
}
} else if (event.key === 'Enter') {

@@ -92,0 +99,0 @@ // No active item, so we let the browser handle the native `onSubmit` form

@@ -7,2 +7,3 @@ import { BaseItem } from './AutocompleteApi';

dispatch(action: ActionType, payload: any): void;
shouldSkipPendingUpdate: boolean;
}

@@ -9,0 +10,0 @@ export declare type Reducer = <TItem extends BaseItem>(state: AutocompleteState<TItem>, action: Action<TItem, any>) => AutocompleteState<TItem>;

@@ -8,2 +8,5 @@ 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>;
isRunning(): boolean;
};

@@ -11,4 +11,7 @@ /**

var latestResolvedValue = undefined;
return function runConcurrentSafePromise(promise) {
var runningPromisesCount = 0;
function runConcurrentSafePromise(promise) {
basePromiseId++;
runningPromisesCount++;
var currentPromiseId = basePromiseId;

@@ -36,4 +39,12 @@ return Promise.resolve(promise).then(function (x) {

return x;
}).finally(function () {
return runningPromisesCount--;
});
}
runConcurrentSafePromise.isRunning = function () {
return runningPromisesCount > 0;
};
return runConcurrentSafePromise;
}

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

/*! @algolia/autocomplete-core 1.5.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
/*! @algolia/autocomplete-core 1.5.1 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@algolia/autocomplete-core'] = {}));
}(this, (function (exports) { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@algolia/autocomplete-core"] = {}));
})(this, (function (exports) { 'use strict';

@@ -46,11 +46,11 @@ function ownKeys(object, enumerableOnly) {

function _typeof(obj) {
function _typeof$1(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
_typeof$1 = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
_typeof$1 = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;

@@ -60,3 +60,3 @@ };

return _typeof(obj);
return _typeof$1(obj);
}

@@ -116,7 +116,7 @@

function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
}

@@ -128,12 +128,12 @@

function _unsupportedIterableToArray(o, minLen) {
function _unsupportedIterableToArray$1(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
if (typeof o === "string") return _arrayLikeToArray$1(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);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
}
function _arrayLikeToArray(arr, len) {
function _arrayLikeToArray$1(arr, len) {
if (len == null || len > arr.length) len = arr.length;

@@ -151,3 +151,3 @@

function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}

@@ -159,12 +159,12 @@

function _unsupportedIterableToArray$1(o, minLen) {
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
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$1(o, minLen);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray$1(arr, len) {
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;

@@ -213,11 +213,11 @@

function _typeof$1(obj) {
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof$1 = function _typeof(obj) {
_typeof = function _typeof(obj) {
return typeof obj;
};
} else {
_typeof$1 = function _typeof(obj) {
_typeof = function _typeof(obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;

@@ -227,3 +227,3 @@ };

return _typeof$1(obj);
return _typeof(obj);
}

@@ -239,3 +239,3 @@ /**

if ( !obj || _typeof$1(obj) !== 'object') {
if (!obj || _typeof(obj) !== 'object') {
return obj;

@@ -300,3 +300,3 @@ }

var version = '1.5.0';
var version = '1.5.1';

@@ -354,3 +354,4 @@ var userAgents = [{

});
}
},
shouldSkipPendingUpdate: false
};

@@ -418,4 +419,7 @@ }

var latestResolvedValue = undefined;
return function runConcurrentSafePromise(promise) {
var runningPromisesCount = 0;
function runConcurrentSafePromise(promise) {
basePromiseId++;
runningPromisesCount++;
var currentPromiseId = basePromiseId;

@@ -443,4 +447,12 @@ return Promise.resolve(promise).then(function (x) {

return x;
}).finally(function () {
return runningPromisesCount--;
});
}
runConcurrentSafePromise.isRunning = function () {
return runningPromisesCount > 0;
};
return runConcurrentSafePromise;
}

@@ -486,3 +498,3 @@

invariant(Array.isArray(sources), function () {
return "The `getSources` function must return an array of sources but returned type ".concat(JSON.stringify(_typeof(sources)), ":\n\n").concat(JSON.stringify(decycle(sources), null, 2));
return "The `getSources` function must return an array of sources but returned type ".concat(JSON.stringify(_typeof$1(sources)), ":\n\n").concat(JSON.stringify(decycle(sources), null, 2));
});

@@ -881,3 +893,3 @@ return Promise.all(sources // We allow `undefined` and `false` sources to allow users to use

invariant(Array.isArray(items), function () {
return "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned type ").concat(JSON.stringify(_typeof(items)), ":\n\n").concat(JSON.stringify(decycle(items), null, 2), ".\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems");
return "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned type ").concat(JSON.stringify(_typeof$1(items)), ":\n\n").concat(JSON.stringify(decycle(items), null, 2), ".\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems");
});

@@ -892,3 +904,3 @@ invariant(items.every(Boolean), "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned ").concat(JSON.stringify(undefined), ".\n\nDid you forget to return items?\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"));

var _excluded = ["event", "nextState", "props", "query", "refresh", "store"];
var _excluded$2 = ["event", "nextState", "props", "query", "refresh", "store"];
var lastStalledId = null;

@@ -904,3 +916,3 @@ var runConcurrentSafePromise = createConcurrentSafePromise();

store = _ref.store,
setters = _objectWithoutProperties(_ref, _excluded);
setters = _objectWithoutProperties(_ref, _excluded$2);

@@ -976,3 +988,16 @@ if (lastStalledId) {

// Parameters passed to `onInput` could be stale when the following code
// executes, because `onInput` calls may not resolve in order.
// If it becomes a problem we'll need to save the last passed parameters.
// See: https://codesandbox.io/s/agitated-cookies-y290z
setStatus('idle');
if (store.shouldSkipPendingUpdate) {
if (!runConcurrentSafePromise.isRunning()) {
store.shouldSkipPendingUpdate = false;
}
return;
}
setCollections(collections);

@@ -1006,2 +1031,3 @@ var isPanelOpen = props.shouldPanelOpen({

}
onInput.isRunning = runConcurrentSafePromise.isRunning;

@@ -1083,3 +1109,10 @@ var _excluded$1 = ["event", "props", "refresh", "store"];

event.preventDefault();
store.dispatch(event.key, null);
store.dispatch(event.key, null); // Hitting the `Escape` key signals the end of a user interaction with the
// autocomplete. At this point, we should ignore any requests that are still
// running and could reopen the panel once they resolve, because that would
// result in an unsolicited UI behavior.
if (onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
}
} else if (event.key === 'Enter') {

@@ -1181,3 +1214,3 @@ // No active item, so we let the browser handle the native `onSubmit` form

var _excluded$2 = ["props", "refresh", "store"],
var _excluded = ["props", "refresh", "store"],
_excluded2 = ["inputElement", "formElement", "panelElement"],

@@ -1191,3 +1224,3 @@ _excluded3 = ["inputElement"],

store = _ref.store,
setters = _objectWithoutProperties(_ref, _excluded$2);
setters = _objectWithoutProperties(_ref, _excluded);

@@ -1209,3 +1242,11 @@ var getEnvironmentProps = function getEnvironmentProps(providedProps) {

onTouchStart: function onTouchStart(event) {
if (store.getState().isOpen === false || event.target === inputElement) {
// The `onTouchStart` event shouldn't trigger the `blur` handler when
// it's not an interaction with Autocomplete. We detect it with the
// following heuristics:
// - the panel is closed AND there are no running requests
// (no interaction with the autocomplete, no future state updates)
// - OR the touched target is the input element (should open the panel)
var isNotAutocompleteInteraction = store.getState().isOpen === false && !onInput.isRunning();
if (isNotAutocompleteInteraction || event.target === inputElement) {
return;

@@ -1219,3 +1260,10 @@ }

if (isTargetWithinAutocomplete === false) {
store.dispatch('blur', null);
store.dispatch('blur', null); // If requests are still running when the user closes the panel, they
// could reopen the panel once they resolve.
// We want to prevent any subsequent query from reopening the panel
// because it would result in an unsolicited UI behavior.
if (!props.debug && onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
}
}

@@ -1248,4 +1296,4 @@ },

var getFormProps = function getFormProps(providedProps) {
var inputElement = providedProps.inputElement,
rest = _objectWithoutProperties(providedProps, _excluded3);
providedProps.inputElement;
var rest = _objectWithoutProperties(providedProps, _excluded3);

@@ -1302,5 +1350,5 @@ return _objectSpread2({

var _ref2 = providedProps || {},
inputElement = _ref2.inputElement,
_ref2$maxLength = _ref2.maxLength,
var _ref2 = providedProps || {};
_ref2.inputElement;
var _ref2$maxLength = _ref2.maxLength,
maxLength = _ref2$maxLength === void 0 ? 512 : _ref2$maxLength,

@@ -1348,3 +1396,10 @@ rest = _objectWithoutProperties(_ref2, _excluded4);

if (!isTouchDevice) {
store.dispatch('blur', null);
store.dispatch('blur', null); // If requests are still running when the user closes the panel, they
// could reopen the panel once they resolve.
// We want to prevent any subsequent query from reopening the panel
// because it would result in an unsolicited UI behavior.
if (!props.debug && onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
}
}

@@ -1760,3 +1815,3 @@ },

})));
}));
//# sourceMappingURL=index.development.js.map

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

/*! @algolia/autocomplete-core 1.5.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){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,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&&null!=e[Symbol.iterator]||null!=e["@@iterator"])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(){},p=[{segment:"autocomplete-core",version:"1.5.0"}];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 m(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 v(e,t){var r,o="undefined"!=typeof window?window:{},u=e.plugins||[];return n(n({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!==(r=e.id)&&void 0!==r?r:"autocomplete-".concat(c++),plugins:u,initialState:n({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(r){return Promise.all([].concat(i(u.map((function(e){return e.getSources}))),[e.getSources]).filter(Boolean).map((function(e){return function(e,t){var r=[];return Promise.resolve(e(t)).then((function(e){return Promise.all(e.filter((function(e){return Boolean(e)})).map((function(e){if(e.sourceId,r.includes(e.sourceId))throw new Error("[Autocomplete] The `sourceId` ".concat(JSON.stringify(e.sourceId)," is not unique."));r.push(e.sourceId);var t=n({getItemInputValue:function(e){return e.state.query},getItemUrl:function(){},onSelect:function(e){(0,e.setIsOpen)(!1)},onActive:s},e);return Promise.resolve(t)})))}))}(e,r)}))).then((function(e){return a(e)})).then((function(e){return e.map((function(e){return n(n({},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:n({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 r=e,Boolean(null==r?void 0:r.execute)?n(n({},e),{},{requests:e.queries.map((function(n){return{query:n,sourceId:t,transformResponse:e.transformResponse}}))}):{items:e,sourceId:t};var r}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 r=e.filter((function(e){return e.sourceId===t.sourceId})),o=r.map((function(e){return e.items})),i=r[0].transformResponse,u=i?i(function(e){var t=e.map((function(e){var t;return n(n({},e),{},{hits:null===(t=e.hits)||void 0===t?void 0:t.map((function(t){return n(n({},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=["event","nextState","props","query","refresh","store"],w=null,A=(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 t=e.event,i=e.nextState,u=void 0===i?{}:i,c=e.props,l=e.query,s=e.refresh,p=e.store,f=o(e,O);w&&c.environment.clearTimeout(w);var v=f.setCollections,d=f.setIsOpen,y=f.setQuery,S=f.setActiveItemId,b=f.setStatus;if(y(l),S(c.defaultActiveItemId),!l&&!1===c.openOnFocus){var P,_=p.getState().collections.map((function(e){return n(n({},e),{},{items:[]})}));return b("idle"),v(_),d(null!==(P=u.isOpen)&&void 0!==P?P:c.shouldPanelOpen({state:p.getState()})),A(_).then((function(){return Promise.resolve()}))}return b("loading"),w=c.environment.setTimeout((function(){b("stalled")}),c.stallThreshold),A(c.getSources(n({query:l,refresh:s,state:p.getState()},f)).then((function(e){return Promise.all(e.map((function(e){return Promise.resolve(e.getItems(n({query:l,refresh:s,state:p.getState()},f))).then((function(t){return g(t,e.sourceId)}))}))).then(h).then((function(t){return I(t,e)})).then((function(e){return function(e){var t=e.collections,o=e.props,i=e.state,u=t.reduce((function(e,t){return n(n({},e),{},r({},t.source.sourceId,n(n({},t.source),{},{getItems:function(){return a(t.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 r;b("idle"),v(e);var o=c.shouldPanelOpen({state:p.getState()});d(null!==(r=u.isOpen)&&void 0!==r?r:c.openOnFocus&&!l&&o||o);var i=m(p.getState());if(null!==p.getState().activeItemId&&i){var a=i.item,g=i.itemInputValue,h=i.itemUrl,I=i.source;I.onActive(n({event:t,item:a,itemInputValue:g,itemUrl:h,refresh:s,source:I,state:p.getState()},f))}})).finally((function(){w&&c.environment.clearTimeout(w)}))}var _=["event","props","refresh","store"];var x=["props","refresh","store"],E=["inputElement","formElement","panelElement"],q=["inputElement"],C=["inputElement","maxLength"],U=["item","source"];function j(e){var t=e.props,r=e.refresh,i=e.store,u=o(e,x);return{getEnvironmentProps:function(e){var r=e.inputElement,u=e.formElement,a=e.panelElement;return n({onTouchStart:function(e){!1!==i.getState().isOpen&&e.target!==r&&(!1===[u,a].some((function(t){return n=t,r=e.target,n===r||n.contains(r);var n,r}))&&i.dispatch("blur",null))},onTouchMove:function(e){!1!==i.getState().isOpen&&r===t.environment.document.activeElement&&e.target!==r&&r.blur()}},o(e,E))},getRootProps:function(e){return n({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 n({action:"",noValidate:!0,role:"search",onSubmit:function(o){var a;o.preventDefault(),t.onSubmit(n({event:o,refresh:r,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(n({event:o,refresh:r,state:i.getState()},u)),i.dispatch("reset",null),null===(a=e.inputElement)||void 0===a||a.focus()}},o(e,q))},getLabelProps:function(e){return n({htmlFor:"".concat(t.id,"-input"),id:"".concat(t.id,"-label")},e)},getInputProps:function(e){function a(e){(t.openOnFocus||Boolean(i.getState().query))&&P(n({event:e,props:t,query:i.getState().completion||i.getState().query,refresh:r,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,f=o(l,C),v=m(i.getState());return n({"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){P(n({event:e,props:t,query:e.currentTarget.value.slice(0,p),refresh:r,store:i},u))},onKeyDown:function(e){!function(e){var t=e.event,r=e.props,i=e.refresh,u=e.store,a=o(e,_);if("ArrowUp"===t.key||"ArrowDown"===t.key){var c=function(){var e=r.environment.document.getElementById("".concat(r.id,"-item-").concat(u.getState().activeItemId));e&&(e.scrollIntoViewIfNeeded?e.scrollIntoViewIfNeeded(!1):e.scrollIntoView(!1))},l=function(){var e=m(u.getState());if(null!==u.getState().activeItemId&&e){var r=e.item,o=e.itemInputValue,c=e.itemUrl,l=e.source;l.onActive(n({event:t,item:r,itemInputValue:o,itemUrl:c,refresh:i,source:l,state:u.getState()},a))}};t.preventDefault(),!1===u.getState().isOpen&&(r.openOnFocus||Boolean(u.getState().query))?P(n({event:t,props:r,query:u.getState().query,refresh:i,store:u},a)).then((function(){u.dispatch(t.key,{nextActiveItemId:r.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=m(u.getState()),p=s.item,f=s.itemInputValue,v=s.itemUrl,d=s.source;if(t.metaKey||t.ctrlKey)void 0!==v&&(d.onSelect(n({event:t,item:p,itemInputValue:f,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),r.navigator.navigateNewTab({itemUrl:v,item:p,state:u.getState()}));else if(t.shiftKey)void 0!==v&&(d.onSelect(n({event:t,item:p,itemInputValue:f,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),r.navigator.navigateNewWindow({itemUrl:v,item:p,state:u.getState()}));else if(t.altKey);else{if(void 0!==v)return d.onSelect(n({event:t,item:p,itemInputValue:f,itemUrl:v,refresh:i,source:d,state:u.getState()},a)),void r.navigator.navigate({itemUrl:v,item:p,state:u.getState()});P(n({event:t,nextState:{isOpen:!1},props:r,query:f,refresh:i,store:u},a)).then((function(){d.onSelect(n({event:t,item:p,itemInputValue:f,itemUrl:v,refresh:i,source:d,state:u.getState()},a))}))}}}(n({event:e,props:t,refresh:r,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)}},f)},getPanelProps:function(e){return n({onMouseDown:function(e){e.preventDefault()},onMouseLeave:function(){i.dispatch("mouseleave",null)}},e)},getListProps:function(e){return n({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,U);return n({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=m(i.getState());if(null!==i.getState().activeItemId&&t){var o=t.item,c=t.itemInputValue,l=t.itemUrl,s=t.source;s.onActive(n({event:e,item:o,itemInputValue:c,itemUrl:l,refresh:r,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(n({event:e,nextState:{isOpen:!1},props:t,query:o,refresh:r,store:i},u))).then((function(){c.onSelect(n({event:e,item:a,itemInputValue:o,itemUrl:l,refresh:r,source:c,state:i.getState()},u))}))}},l)}}}function V(e){var t,o,i,u,a=e.plugins,c=e.options,l=null===(t=((null===(o=c.__autocomplete_metadata)||void 0===o?void 0:o.userAgents)||[])[0])||void 0===t?void 0:t.segment,s=l?r({},l,Object.keys((null===(i=c.__autocomplete_metadata)||void 0===i?void 0:i.options)||{})):{};return{plugins:a.map((function(e){return{name:e.name,options:Object.keys(e.__autocomplete_pluginOptions||[])}})),options:n({"autocomplete-core":Object.keys(c)},s),ua:p.concat((null===(u=c.__autocomplete_metadata)||void 0===u?void 0:u.userAgents)||[])}}function D(e){var t,n=e.state;return!1===n.isOpen||null===n.activeItemId?null:(null===(t=m(n))||void 0===t?void 0:t.itemInputValue)||null}var k=function(e,t){switch(t.type){case"setActiveItemId":case"mousemove":return n(n({},e),{},{activeItemId:t.payload});case"setQuery":return n(n({},e),{},{query:t.payload,completion:null});case"setCollections":return n(n({},e),{},{collections:t.payload});case"setIsOpen":return n(n({},e),{},{isOpen:t.payload});case"setStatus":return n(n({},e),{},{status:t.payload});case"setContext":return n(n({},e),{},{context:n(n({},e.context),t.payload)});case"ArrowDown":var r=n(n({},e),{},{activeItemId:t.payload.hasOwnProperty("nextActiveItemId")?t.payload.nextActiveItemId:f(1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},r),{},{completion:D({state:r})});case"ArrowUp":var o=n(n({},e),{},{activeItemId:f(-1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},o),{},{completion:D({state:o})});case"Escape":return e.isOpen?n(n({},e),{},{activeItemId:null,isOpen:!1,completion:null}):n(n({},e),{},{activeItemId:null,query:"",status:"idle",collections:[]});case"submit":return n(n({},e),{},{activeItemId:null,isOpen:!1,status:"idle"});case"reset":return n(n({},e),{},{activeItemId:!0===t.props.openOnFocus?t.props.defaultActiveItemId:null,status:"idle",query:""});case"focus":return n(n({},e),{},{activeItemId:t.props.defaultActiveItemId,isOpen:(t.props.openOnFocus||Boolean(e.query))&&t.props.shouldPanelOpen({state:e})});case"blur":return t.props.debug?e:n(n({},e),{},{isOpen:!1,activeItemId:null});case"mouseleave":return n(n({},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=[],r=v(e,t),o=function(e,t,r){var o=t.initialState;return{getState:function(){return o},dispatch:function(i,u){var a=n({},o);o=e(o,{type:i,props:t,payload:u}),r({state:o,prevState:a})}}}(k,r,(function(e){var t=e.prevState,o=e.state;r.onStateChange(n({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 r=0,o=e.map((function(e){return n(n({},e),{},{items:a(e.items).map((function(e){return n(n({},e),{},{__autocomplete_id:r++})}))})}));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=j(n({props:r,refresh:c,store:o},i));function c(){return P(n({event:new Event("input"),nextState:{isOpen:o.getState().isOpen},props:r,query:o.getState().query,refresh:c,store:o},i))}return r.plugins.forEach((function(e){var r;return null===(r=e.subscribe)||void 0===r?void 0:r.call(e,n(n({},i),{},{refresh:c,onSelect:function(e){t.push({onSelect:e})},onActive:function(e){t.push({onActive:e})}}))})),function(e){var t,n=e.metadata,r=e.environment;if(null===(t=r.navigator)||void 0===t?void 0:t.userAgent.includes("Algolia Crawler")){var o=r.document.createElement("meta"),i=r.document.querySelector("head");o.name="algolia:metadata",setTimeout((function(){o.content=JSON.stringify(n),i.appendChild(o)}),0)}}({metadata:V({plugins:r.plugins,options:e}),environment:r.environment}),n(n({refresh:c},u),i)},e.getDefaultProps=v,Object.defineProperty(e,"__esModule",{value:!0})}));
/*! @algolia/autocomplete-core 1.5.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){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,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&&null!=e[Symbol.iterator]||null!=e["@@iterator"])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(){},p=[{segment:"autocomplete-core",version:"1.5.1"}];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 m(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 d(e,t){var r,o="undefined"!=typeof window?window:{},u=e.plugins||[];return n(n({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!==(r=e.id)&&void 0!==r?r:"autocomplete-".concat(c++),plugins:u,initialState:n({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(r){return Promise.all([].concat(i(u.map((function(e){return e.getSources}))),[e.getSources]).filter(Boolean).map((function(e){return function(e,t){var r=[];return Promise.resolve(e(t)).then((function(e){return Promise.all(e.filter((function(e){return Boolean(e)})).map((function(e){if(e.sourceId,r.includes(e.sourceId))throw new Error("[Autocomplete] The `sourceId` ".concat(JSON.stringify(e.sourceId)," is not unique."));r.push(e.sourceId);var t=n({getItemInputValue:function(e){return e.state.query},getItemUrl:function(){},onSelect:function(e){(0,e.setIsOpen)(!1)},onActive:s},e);return Promise.resolve(t)})))}))}(e,r)}))).then((function(e){return a(e)})).then((function(e){return e.map((function(e){return n(n({},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:n({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 v(e){return Boolean(e.execute)}function g(e,t){return r=e,Boolean(null==r?void 0:r.execute)?n(n({},e),{},{requests:e.queries.map((function(n){return{query:n,sourceId:t,transformResponse:e.transformResponse}}))}):{items:e,sourceId:t};var r}function h(e){var t=e.reduce((function(e,t){if(!v(t))return e.push(t),e;var n=t.searchClient,r=t.execute,o=t.requests,u=e.find((function(e){return v(t)&&v(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(!v(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 r=e.filter((function(e){return e.sourceId===t.sourceId})),o=r.map((function(e){return e.items})),i=r[0].transformResponse,u=i?i(function(e){var t=e.map((function(e){var t;return n(n({},e),{},{hits:null===(t=e.hits)||void 0===t?void 0:t.map((function(t){return n(n({},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 S=["event","nextState","props","query","refresh","store"],y=null,b=function(){var e=-1,t=-1,n=void 0,r=0;function o(o){e++,r++;var i=e;return Promise.resolve(o).then((function(e){return n&&i<t?n:(t=i,n=e,e)})).finally((function(){return r--}))}return o.isRunning=function(){return r>0},o}();function O(e){var t=e.event,i=e.nextState,u=void 0===i?{}:i,c=e.props,l=e.query,s=e.refresh,p=e.store,f=o(e,S);y&&c.environment.clearTimeout(y);var d=f.setCollections,v=f.setIsOpen,O=f.setQuery,w=f.setActiveItemId,P=f.setStatus;if(O(l),w(c.defaultActiveItemId),!l&&!1===c.openOnFocus){var A,_=p.getState().collections.map((function(e){return n(n({},e),{},{items:[]})}));return P("idle"),d(_),v(null!==(A=u.isOpen)&&void 0!==A?A:c.shouldPanelOpen({state:p.getState()})),b(_).then((function(){return Promise.resolve()}))}return P("loading"),y=c.environment.setTimeout((function(){P("stalled")}),c.stallThreshold),b(c.getSources(n({query:l,refresh:s,state:p.getState()},f)).then((function(e){return Promise.all(e.map((function(e){return Promise.resolve(e.getItems(n({query:l,refresh:s,state:p.getState()},f))).then((function(t){return g(t,e.sourceId)}))}))).then(h).then((function(t){return I(t,e)})).then((function(e){return function(e){var t=e.collections,o=e.props,i=e.state,u=t.reduce((function(e,t){return n(n({},e),{},r({},t.source.sourceId,n(n({},t.source),{},{getItems:function(){return a(t.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 r;if(P("idle"),p.shouldSkipPendingUpdate)b.isRunning()||(p.shouldSkipPendingUpdate=!1);else{d(e);var o=c.shouldPanelOpen({state:p.getState()});v(null!==(r=u.isOpen)&&void 0!==r?r:c.openOnFocus&&!l&&o||o);var i=m(p.getState());if(null!==p.getState().activeItemId&&i){var a=i.item,g=i.itemInputValue,h=i.itemUrl,I=i.source;I.onActive(n({event:t,item:a,itemInputValue:g,itemUrl:h,refresh:s,source:I,state:p.getState()},f))}}})).finally((function(){y&&c.environment.clearTimeout(y)}))}O.isRunning=b.isRunning;var w=["event","props","refresh","store"];var P=["props","refresh","store"],A=["inputElement","formElement","panelElement"],_=["inputElement"],x=["inputElement","maxLength"],E=["item","source"];function U(e){var t=e.props,r=e.refresh,i=e.store,u=o(e,P);return{getEnvironmentProps:function(e){var r=e.inputElement,u=e.formElement,a=e.panelElement;return n({onTouchStart:function(e){!1===i.getState().isOpen&&!O.isRunning()||e.target===r||!1===[u,a].some((function(t){return n=t,r=e.target,n===r||n.contains(r);var n,r}))&&(i.dispatch("blur",null),!t.debug&&O.isRunning()&&(i.shouldSkipPendingUpdate=!0))},onTouchMove:function(e){!1!==i.getState().isOpen&&r===t.environment.document.activeElement&&e.target!==r&&r.blur()}},o(e,A))},getRootProps:function(e){return n({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){return e.inputElement,n({action:"",noValidate:!0,role:"search",onSubmit:function(o){var a;o.preventDefault(),t.onSubmit(n({event:o,refresh:r,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(n({event:o,refresh:r,state:i.getState()},u)),i.dispatch("reset",null),null===(a=e.inputElement)||void 0===a||a.focus()}},o(e,_))},getLabelProps:function(e){return n({htmlFor:"".concat(t.id,"-input"),id:"".concat(t.id,"-label")},e)},getInputProps:function(e){function a(e){(t.openOnFocus||Boolean(i.getState().query))&&O(n({event:e,props:t,query:i.getState().completion||i.getState().query,refresh:r,store:i},u)),i.dispatch("focus",null)}var c="ontouchstart"in t.environment,l=e||{};l.inputElement;var s=l.maxLength,p=void 0===s?512:s,f=o(l,x),d=m(i.getState());return n({"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!=d&&d.itemUrl?"go":"search",spellCheck:"false",autoFocus:t.autoFocus,placeholder:t.placeholder,maxLength:p,type:"search",onChange:function(e){O(n({event:e,props:t,query:e.currentTarget.value.slice(0,p),refresh:r,store:i},u))},onKeyDown:function(e){!function(e){var t=e.event,r=e.props,i=e.refresh,u=e.store,a=o(e,w);if("ArrowUp"===t.key||"ArrowDown"===t.key){var c=function(){var e=r.environment.document.getElementById("".concat(r.id,"-item-").concat(u.getState().activeItemId));e&&(e.scrollIntoViewIfNeeded?e.scrollIntoViewIfNeeded(!1):e.scrollIntoView(!1))},l=function(){var e=m(u.getState());if(null!==u.getState().activeItemId&&e){var r=e.item,o=e.itemInputValue,c=e.itemUrl,l=e.source;l.onActive(n({event:t,item:r,itemInputValue:o,itemUrl:c,refresh:i,source:l,state:u.getState()},a))}};t.preventDefault(),!1===u.getState().isOpen&&(r.openOnFocus||Boolean(u.getState().query))?O(n({event:t,props:r,query:u.getState().query,refresh:i,store:u},a)).then((function(){u.dispatch(t.key,{nextActiveItemId:r.defaultActiveItemId}),l(),setTimeout(c,0)})):(u.dispatch(t.key,{}),l(),c())}else if("Escape"===t.key)t.preventDefault(),u.dispatch(t.key,null),O.isRunning()&&(u.shouldSkipPendingUpdate=!0);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=m(u.getState()),p=s.item,f=s.itemInputValue,d=s.itemUrl,v=s.source;if(t.metaKey||t.ctrlKey)void 0!==d&&(v.onSelect(n({event:t,item:p,itemInputValue:f,itemUrl:d,refresh:i,source:v,state:u.getState()},a)),r.navigator.navigateNewTab({itemUrl:d,item:p,state:u.getState()}));else if(t.shiftKey)void 0!==d&&(v.onSelect(n({event:t,item:p,itemInputValue:f,itemUrl:d,refresh:i,source:v,state:u.getState()},a)),r.navigator.navigateNewWindow({itemUrl:d,item:p,state:u.getState()}));else if(t.altKey);else{if(void 0!==d)return v.onSelect(n({event:t,item:p,itemInputValue:f,itemUrl:d,refresh:i,source:v,state:u.getState()},a)),void r.navigator.navigate({itemUrl:d,item:p,state:u.getState()});O(n({event:t,nextState:{isOpen:!1},props:r,query:f,refresh:i,store:u},a)).then((function(){v.onSelect(n({event:t,item:p,itemInputValue:f,itemUrl:d,refresh:i,source:v,state:u.getState()},a))}))}}}(n({event:e,props:t,refresh:r,store:i},u))},onFocus:a,onBlur:function(){c||(i.dispatch("blur",null),!t.debug&&O.isRunning()&&(i.shouldSkipPendingUpdate=!0))},onClick:function(n){e.inputElement!==t.environment.document.activeElement||i.getState().isOpen||a(n)}},f)},getPanelProps:function(e){return n({onMouseDown:function(e){e.preventDefault()},onMouseLeave:function(){i.dispatch("mouseleave",null)}},e)},getListProps:function(e){return n({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,E);return n({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=m(i.getState());if(null!==i.getState().activeItemId&&t){var o=t.item,c=t.itemInputValue,l=t.itemUrl,s=t.source;s.onActive(n({event:e,item:o,itemInputValue:c,itemUrl:l,refresh:r,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():O(n({event:e,nextState:{isOpen:!1},props:t,query:o,refresh:r,store:i},u))).then((function(){c.onSelect(n({event:e,item:a,itemInputValue:o,itemUrl:l,refresh:r,source:c,state:i.getState()},u))}))}},l)}}}function q(e){var t,o,i,u,a=e.plugins,c=e.options,l=null===(t=((null===(o=c.__autocomplete_metadata)||void 0===o?void 0:o.userAgents)||[])[0])||void 0===t?void 0:t.segment,s=l?r({},l,Object.keys((null===(i=c.__autocomplete_metadata)||void 0===i?void 0:i.options)||{})):{};return{plugins:a.map((function(e){return{name:e.name,options:Object.keys(e.__autocomplete_pluginOptions||[])}})),options:n({"autocomplete-core":Object.keys(c)},s),ua:p.concat((null===(u=c.__autocomplete_metadata)||void 0===u?void 0:u.userAgents)||[])}}function C(e){var t,n=e.state;return!1===n.isOpen||null===n.activeItemId?null:(null===(t=m(n))||void 0===t?void 0:t.itemInputValue)||null}var j=function(e,t){switch(t.type){case"setActiveItemId":case"mousemove":return n(n({},e),{},{activeItemId:t.payload});case"setQuery":return n(n({},e),{},{query:t.payload,completion:null});case"setCollections":return n(n({},e),{},{collections:t.payload});case"setIsOpen":return n(n({},e),{},{isOpen:t.payload});case"setStatus":return n(n({},e),{},{status:t.payload});case"setContext":return n(n({},e),{},{context:n(n({},e.context),t.payload)});case"ArrowDown":var r=n(n({},e),{},{activeItemId:t.payload.hasOwnProperty("nextActiveItemId")?t.payload.nextActiveItemId:f(1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},r),{},{completion:C({state:r})});case"ArrowUp":var o=n(n({},e),{},{activeItemId:f(-1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},o),{},{completion:C({state:o})});case"Escape":return e.isOpen?n(n({},e),{},{activeItemId:null,isOpen:!1,completion:null}):n(n({},e),{},{activeItemId:null,query:"",status:"idle",collections:[]});case"submit":return n(n({},e),{},{activeItemId:null,isOpen:!1,status:"idle"});case"reset":return n(n({},e),{},{activeItemId:!0===t.props.openOnFocus?t.props.defaultActiveItemId:null,status:"idle",query:""});case"focus":return n(n({},e),{},{activeItemId:t.props.defaultActiveItemId,isOpen:(t.props.openOnFocus||Boolean(e.query))&&t.props.shouldPanelOpen({state:e})});case"blur":return t.props.debug?e:n(n({},e),{},{isOpen:!1,activeItemId:null});case"mouseleave":return n(n({},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=[],r=d(e,t),o=function(e,t,r){var o=t.initialState;return{getState:function(){return o},dispatch:function(i,u){var a=n({},o);o=e(o,{type:i,props:t,payload:u}),r({state:o,prevState:a})},shouldSkipPendingUpdate:!1}}(j,r,(function(e){var t=e.prevState,o=e.state;r.onStateChange(n({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 r=0,o=e.map((function(e){return n(n({},e),{},{items:a(e.items).map((function(e){return n(n({},e),{},{__autocomplete_id:r++})}))})}));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=U(n({props:r,refresh:c,store:o},i));function c(){return O(n({event:new Event("input"),nextState:{isOpen:o.getState().isOpen},props:r,query:o.getState().query,refresh:c,store:o},i))}return r.plugins.forEach((function(e){var r;return null===(r=e.subscribe)||void 0===r?void 0:r.call(e,n(n({},i),{},{refresh:c,onSelect:function(e){t.push({onSelect:e})},onActive:function(e){t.push({onActive:e})}}))})),function(e){var t,n=e.metadata,r=e.environment;if(null===(t=r.navigator)||void 0===t?void 0:t.userAgent.includes("Algolia Crawler")){var o=r.document.createElement("meta"),i=r.document.querySelector("head");o.name="algolia:metadata",setTimeout((function(){o.content=JSON.stringify(n),i.appendChild(o)}),0)}}({metadata:q({plugins:r.plugins,options:e}),environment:r.environment}),n(n({refresh:c},u),i)},e.getDefaultProps=d,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.production.js.map
{
"name": "@algolia/autocomplete-core",
"description": "Core primitives for building autocomplete experiences.",
"version": "1.5.0",
"version": "1.5.1",
"license": "MIT",

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

"dependencies": {
"@algolia/autocomplete-shared": "1.5.0"
"@algolia/autocomplete-shared": "1.5.1"
},
"devDependencies": {
"@algolia/autocomplete-preset-algolia": "1.5.0",
"@algolia/autocomplete-preset-algolia": "1.5.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