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

@algolia/autocomplete-core

Package Overview
Dependencies
Maintainers
66
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.1 to 1.5.2

dist/esm/utils/createCancelablePromise.d.ts

3

dist/esm/createStore.js

@@ -7,2 +7,3 @@ 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 { createCancelablePromiseList } from './utils';
export function createStore(reducer, props, onStoreStateChange) {

@@ -27,4 +28,4 @@ var state = props.initialState;

},
shouldSkipPendingUpdate: false
pendingRequests: createCancelablePromiseList()
};
}

@@ -44,8 +44,8 @@ var _excluded = ["props", "refresh", "store"],

// following heuristics:
// - the panel is closed AND there are no running requests
// - the panel is closed AND there are no pending 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();
var isAutocompleteInteraction = store.getState().isOpen || !store.pendingRequests.isEmpty();
if (isNotAutocompleteInteraction || event.target === inputElement) {
if (!isAutocompleteInteraction || event.target === inputElement) {
return;

@@ -59,3 +59,3 @@ }

if (isTargetWithinAutocomplete === false) {
store.dispatch('blur', null); // If requests are still running when the user closes the panel, they
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they
// could reopen the panel once they resolve.

@@ -65,4 +65,4 @@ // We want to prevent any subsequent query from reopening the panel

if (!props.debug && onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
if (!props.debug) {
store.pendingRequests.cancelAll();
}

@@ -194,3 +194,3 @@ }

if (!isTouchDevice) {
store.dispatch('blur', null); // If requests are still running when the user closes the panel, they
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they
// could reopen the panel once they resolve.

@@ -200,4 +200,4 @@ // We want to prevent any subsequent query from reopening the panel

if (!props.debug && onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
if (!props.debug) {
store.pendingRequests.cancelAll();
}

@@ -204,0 +204,0 @@ }

import { AutocompleteScopeApi, AutocompleteState, AutocompleteStore, BaseItem, InternalAutocompleteOptions } from './types';
import { CancelablePromise } from './utils';
interface OnInputParams<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> {

@@ -16,6 +17,3 @@ event: any;

}
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 declare function onInput<TItem extends BaseItem>({ event, nextState, props, query, refresh, store, ...setters }: OnInputParams<TItem>): CancelablePromise<void>;
export {};

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

import { preResolve, resolve, postResolve } from './resolve';
import { createConcurrentSafePromise, getActiveItem } from './utils';
import { cancelable, createConcurrentSafePromise, getActiveItem } from './utils';
var lastStalledId = null;

@@ -58,5 +58,7 @@ var runConcurrentSafePromise = createConcurrentSafePromise();

return runConcurrentSafePromise(collections).then(function () {
var _request = cancelable(runConcurrentSafePromise(collections).then(function () {
return Promise.resolve();
});
}));
return store.pendingRequests.add(_request);
}

@@ -74,3 +76,3 @@

return runConcurrentSafePromise(props.getSources(_objectSpread({
var request = cancelable(runConcurrentSafePromise(props.getSources(_objectSpread({
query: query,

@@ -97,3 +99,3 @@ refresh: refresh,

});
})).then(function (collections) {
}))).then(function (collections) {
var _nextState$isOpen2;

@@ -106,11 +108,2 @@

setStatus('idle');
if (store.shouldSkipPendingUpdate) {
if (!runConcurrentSafePromise.isRunning()) {
store.shouldSkipPendingUpdate = false;
}
return;
}
setCollections(collections);

@@ -139,2 +132,4 @@ var isPanelOpen = props.shouldPanelOpen({

}).finally(function () {
setStatus('idle');
if (lastStalledId) {

@@ -144,3 +139,3 @@ props.environment.clearTimeout(lastStalledId);

});
}
onInput.isRunning = runConcurrentSafePromise.isRunning;
return store.pendingRequests.add(request);
}

@@ -91,8 +91,6 @@ var _excluded = ["event", "props", "refresh", "store"];

// autocomplete. At this point, we should ignore any requests that are still
// running and could reopen the panel once they resolve, because that would
// pending and could reopen the panel once they resolve, because that would
// result in an unsolicited UI behavior.
if (onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
}
store.pendingRequests.cancelAll();
} else if (event.key === 'Enter') {

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

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

import { CancelablePromiseList } from '../utils';
import { BaseItem } from './AutocompleteApi';

@@ -7,3 +8,3 @@ import { InternalAutocompleteOptions } from './AutocompleteOptions';

dispatch(action: ActionType, payload: any): void;
shouldSkipPendingUpdate: boolean;
pendingRequests: CancelablePromiseList<void>;
}

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

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

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

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

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

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

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

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

export * from './createCancelablePromise';
export * from './createCancelablePromiseList';
export * from './createConcurrentSafePromise';

@@ -2,0 +4,0 @@ export * from './getNextActiveItemId';

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

export * from './createCancelablePromise';
export * from './createCancelablePromiseList';
export * from './createConcurrentSafePromise';

@@ -2,0 +4,0 @@ export * from './getNextActiveItemId';

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

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

@@ -291,3 +291,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

var version = '1.5.1';
var version = '1.5.2';

@@ -327,71 +327,75 @@ var userAgents = [{

function createStore(reducer, props, onStoreStateChange) {
var state = props.initialState;
function createInternalCancelablePromise(promise, initialState) {
var state = initialState;
return {
getState: function getState() {
return state;
then: function then(onfulfilled, onrejected) {
return createInternalCancelablePromise(promise.then(createCallback(onfulfilled, state, promise), createCallback(onrejected, state, promise)), state);
},
dispatch: function dispatch(action, payload) {
var prevState = _objectSpread2({}, state);
catch: function _catch(onrejected) {
return createInternalCancelablePromise(promise.catch(createCallback(onrejected, state, promise)), state);
},
finally: function _finally(onfinally) {
if (onfinally) {
state.onCancelList.push(onfinally);
}
state = reducer(state, {
type: action,
props: props,
payload: payload
return createInternalCancelablePromise(promise.finally(createCallback(onfinally && function () {
state.onCancelList = [];
return onfinally();
}, state, promise)), state);
},
cancel: function cancel() {
state.isCanceled = true;
var callbacks = state.onCancelList;
state.onCancelList = [];
callbacks.forEach(function (callback) {
callback();
});
onStoreStateChange({
state: state,
prevState: prevState
});
},
shouldSkipPendingUpdate: false
isCanceled: function isCanceled() {
return state.isCanceled === true;
}
};
}
function getAutocompleteSetters(_ref) {
var store = _ref.store;
function cancelable(promise) {
return createInternalCancelablePromise(promise, {
isCanceled: false,
onCancelList: []
});
}
var setActiveItemId = function setActiveItemId(value) {
store.dispatch('setActiveItemId', value);
};
function createCallback(onResult, state, fallback) {
if (!onResult) {
return fallback;
}
var setQuery = function setQuery(value) {
store.dispatch('setQuery', value);
};
return function callback(arg) {
if (state.isCanceled) {
return arg;
}
var setCollections = function setCollections(rawValue) {
var baseItemId = 0;
var value = rawValue.map(function (collection) {
return _objectSpread2(_objectSpread2({}, collection), {}, {
// We flatten the stored items to support calling `getAlgoliaResults`
// from the source itself.
items: flatten(collection.items).map(function (item) {
return _objectSpread2(_objectSpread2({}, item), {}, {
__autocomplete_id: baseItemId++
});
})
});
});
store.dispatch('setCollections', value);
return onResult(arg);
};
}
var setIsOpen = function setIsOpen(value) {
store.dispatch('setIsOpen', value);
};
var setStatus = function setStatus(value) {
store.dispatch('setStatus', value);
};
var setContext = function setContext(value) {
store.dispatch('setContext', value);
};
function createCancelablePromiseList() {
var list = [];
return {
setActiveItemId: setActiveItemId,
setQuery: setQuery,
setCollections: setCollections,
setIsOpen: setIsOpen,
setStatus: setStatus,
setContext: setContext
add: function add(cancelablePromise) {
list.push(cancelablePromise);
return cancelablePromise.finally(function () {
list = list.filter(function (item) {
return item !== cancelablePromise;
});
});
},
cancelAll: function cancelAll() {
list.forEach(function (promise) {
return promise.cancel();
});
},
isEmpty: function isEmpty() {
return list.length === 0;
}
};

@@ -410,7 +414,4 @@ }

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

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

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

@@ -653,2 +646,74 @@

function createStore(reducer, props, onStoreStateChange) {
var state = props.initialState;
return {
getState: function getState() {
return state;
},
dispatch: function dispatch(action, payload) {
var prevState = _objectSpread2({}, state);
state = reducer(state, {
type: action,
props: props,
payload: payload
});
onStoreStateChange({
state: state,
prevState: prevState
});
},
pendingRequests: createCancelablePromiseList()
};
}
function getAutocompleteSetters(_ref) {
var store = _ref.store;
var setActiveItemId = function setActiveItemId(value) {
store.dispatch('setActiveItemId', value);
};
var setQuery = function setQuery(value) {
store.dispatch('setQuery', value);
};
var setCollections = function setCollections(rawValue) {
var baseItemId = 0;
var value = rawValue.map(function (collection) {
return _objectSpread2(_objectSpread2({}, collection), {}, {
// We flatten the stored items to support calling `getAlgoliaResults`
// from the source itself.
items: flatten(collection.items).map(function (item) {
return _objectSpread2(_objectSpread2({}, item), {}, {
__autocomplete_id: baseItemId++
});
})
});
});
store.dispatch('setCollections', value);
};
var setIsOpen = function setIsOpen(value) {
store.dispatch('setIsOpen', value);
};
var setStatus = function setStatus(value) {
store.dispatch('setStatus', value);
};
var setContext = function setContext(value) {
store.dispatch('setContext', value);
};
return {
setActiveItemId: setActiveItemId,
setQuery: setQuery,
setCollections: setCollections,
setIsOpen: setIsOpen,
setStatus: setStatus,
setContext: setContext
};
}
function getDefaultProps(props, pluginSubscribers) {

@@ -936,5 +1001,7 @@ var _props$id;

return runConcurrentSafePromise(collections).then(function () {
var _request = cancelable(runConcurrentSafePromise(collections).then(function () {
return Promise.resolve();
});
}));
return store.pendingRequests.add(_request);
}

@@ -952,3 +1019,3 @@

return runConcurrentSafePromise(props.getSources(_objectSpread2({
var request = cancelable(runConcurrentSafePromise(props.getSources(_objectSpread2({
query: query,

@@ -975,3 +1042,3 @@ refresh: refresh,

});
})).then(function (collections) {
}))).then(function (collections) {
var _nextState$isOpen2;

@@ -984,11 +1051,2 @@

setStatus('idle');
if (store.shouldSkipPendingUpdate) {
if (!runConcurrentSafePromise.isRunning()) {
store.shouldSkipPendingUpdate = false;
}
return;
}
setCollections(collections);

@@ -1017,2 +1075,4 @@ var isPanelOpen = props.shouldPanelOpen({

}).finally(function () {
setStatus('idle');
if (lastStalledId) {

@@ -1022,4 +1082,4 @@ props.environment.clearTimeout(lastStalledId);

});
return store.pendingRequests.add(request);
}
onInput.isRunning = runConcurrentSafePromise.isRunning;

@@ -1103,8 +1163,6 @@ var _excluded$1 = ["event", "props", "refresh", "store"];

// autocomplete. At this point, we should ignore any requests that are still
// running and could reopen the panel once they resolve, because that would
// pending and could reopen the panel once they resolve, because that would
// result in an unsolicited UI behavior.
if (onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
}
store.pendingRequests.cancelAll();
} else if (event.key === 'Enter') {

@@ -1235,8 +1293,8 @@ // No active item, so we let the browser handle the native `onSubmit` form

// following heuristics:
// - the panel is closed AND there are no running requests
// - the panel is closed AND there are no pending 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();
var isAutocompleteInteraction = store.getState().isOpen || !store.pendingRequests.isEmpty();
if (isNotAutocompleteInteraction || event.target === inputElement) {
if (!isAutocompleteInteraction || event.target === inputElement) {
return;

@@ -1250,3 +1308,3 @@ }

if (isTargetWithinAutocomplete === false) {
store.dispatch('blur', null); // If requests are still running when the user closes the panel, they
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they
// could reopen the panel once they resolve.

@@ -1256,4 +1314,4 @@ // We want to prevent any subsequent query from reopening the panel

if (!props.debug && onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
if (!props.debug) {
store.pendingRequests.cancelAll();
}

@@ -1385,3 +1443,3 @@ }

if (!isTouchDevice) {
store.dispatch('blur', null); // If requests are still running when the user closes the panel, they
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they
// could reopen the panel once they resolve.

@@ -1391,4 +1449,4 @@ // We want to prevent any subsequent query from reopening the panel

if (!props.debug && onInput.isRunning()) {
store.shouldSkipPendingUpdate = true;
if (!props.debug) {
store.pendingRequests.cancelAll();
}

@@ -1395,0 +1453,0 @@ }

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

/*! @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})}));
/*! @algolia/autocomplete-core 1.5.2 | 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(){},f=[{segment:"autocomplete-core",version:"1.5.2"}];function p(e,t){var n=t;return{then:function(t,r){return p(e.then(d(t,n,e),d(r,n,e)),n)},catch:function(t){return p(e.catch(d(t,n,e)),n)},finally:function(t){return t&&n.onCancelList.push(t),p(e.finally(d(t&&function(){return n.onCancelList=[],t()},n,e)),n)},cancel:function(){n.isCanceled=!0;var e=n.onCancelList;n.onCancelList=[],e.forEach((function(e){e()}))},isCanceled:function(){return!0===n.isCanceled}}}function m(e){return p(e,{isCanceled:!1,onCancelList:[]})}function d(e,t,n){return e?function(n){return t.isCanceled?n:e(n)}:n}function v(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 g(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 h(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 I(e){return Boolean(e.execute)}function y(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 S(e){var t=e.reduce((function(e,t){if(!I(t))return e.push(t),e;var n=t.searchClient,r=t.execute,o=t.requests,u=e.find((function(e){return I(t)&&I(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(!I(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 b(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 O,A,w,q=["event","nextState","props","query","refresh","store"],P=null,_=(O=-1,A=-1,w=void 0,function(e){var t=++O;return Promise.resolve(e).then((function(e){return w&&t<A?w:(A=t,w=e,e)}))});function E(e){var t=e.event,i=e.nextState,u=void 0===i?{}:i,c=e.props,l=e.query,s=e.refresh,f=e.store,p=o(e,q);P&&c.environment.clearTimeout(P);var d=p.setCollections,v=p.setIsOpen,h=p.setQuery,I=p.setActiveItemId,O=p.setStatus;if(h(l),I(c.defaultActiveItemId),!l&&!1===c.openOnFocus){var A,w=f.getState().collections.map((function(e){return n(n({},e),{},{items:[]})}));O("idle"),d(w),v(null!==(A=u.isOpen)&&void 0!==A?A:c.shouldPanelOpen({state:f.getState()}));var E=m(_(w).then((function(){return Promise.resolve()})));return f.pendingRequests.add(E)}O("loading"),P=c.environment.setTimeout((function(){O("stalled")}),c.stallThreshold);var C=m(_(c.getSources(n({query:l,refresh:s,state:f.getState()},p)).then((function(e){return Promise.all(e.map((function(e){return Promise.resolve(e.getItems(n({query:l,refresh:s,state:f.getState()},p))).then((function(t){return y(t,e.sourceId)}))}))).then(S).then((function(t){return b(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:f.getState()})}))})))).then((function(e){var r;O("idle"),d(e);var o=c.shouldPanelOpen({state:f.getState()});v(null!==(r=u.isOpen)&&void 0!==r?r:c.openOnFocus&&!l&&o||o);var i=g(f.getState());if(null!==f.getState().activeItemId&&i){var a=i.item,m=i.itemInputValue,h=i.itemUrl,I=i.source;I.onActive(n({event:t,item:a,itemInputValue:m,itemUrl:h,refresh:s,source:I,state:f.getState()},p))}})).finally((function(){O("idle"),P&&c.environment.clearTimeout(P)}));return f.pendingRequests.add(C)}var C=["event","props","refresh","store"];var x=["props","refresh","store"],U=["inputElement","formElement","panelElement"],j=["inputElement"],V=["inputElement","maxLength"],D=["item","source"];function k(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){!i.getState().isOpen&&i.pendingRequests.isEmpty()||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||i.pendingRequests.cancelAll())},onTouchMove:function(e){!1!==i.getState().isOpen&&r===t.environment.document.activeElement&&e.target!==r&&r.blur()}},o(e,U))},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,j))},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))&&E(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,f=void 0===s?512:s,p=o(l,V),m=g(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!=m&&m.itemUrl?"go":"search",spellCheck:"false",autoFocus:t.autoFocus,placeholder:t.placeholder,maxLength:f,type:"search",onChange:function(e){E(n({event:e,props:t,query:e.currentTarget.value.slice(0,f),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,C);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=g(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))?E(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),u.pendingRequests.cancelAll();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=g(u.getState()),f=s.item,p=s.itemInputValue,m=s.itemUrl,d=s.source;if(t.metaKey||t.ctrlKey)void 0!==m&&(d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),r.navigator.navigateNewTab({itemUrl:m,item:f,state:u.getState()}));else if(t.shiftKey)void 0!==m&&(d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),r.navigator.navigateNewWindow({itemUrl:m,item:f,state:u.getState()}));else if(t.altKey);else{if(void 0!==m)return d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),void r.navigator.navigate({itemUrl:m,item:f,state:u.getState()});E(n({event:t,nextState:{isOpen:!1},props:r,query:p,refresh:i,store:u},a)).then((function(){d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,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),t.debug||i.pendingRequests.cancelAll())},onClick:function(n){e.inputElement!==t.environment.document.activeElement||i.getState().isOpen||a(n)}},p)},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,D);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=g(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():E(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 T(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:f.concat((null===(u=c.__autocomplete_metadata)||void 0===u?void 0:u.userAgents)||[])}}function R(e){var t,n=e.state;return!1===n.isOpen||null===n.activeItemId?null:(null===(t=g(n))||void 0===t?void 0:t.itemInputValue)||null}var B=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:v(1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},r),{},{completion:R({state:r})});case"ArrowUp":var o=n(n({},e),{},{activeItemId:v(-1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},o),{},{completion:R({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=h(e,t),o=function(e,t,r){var o,i=t.initialState;return{getState:function(){return i},dispatch:function(o,u){var a=n({},i);i=e(i,{type:o,props:t,payload:u}),r({state:i,prevState:a})},pendingRequests:(o=[],{add:function(e){return o.push(e),e.finally((function(){o=o.filter((function(t){return t!==e}))}))},cancelAll:function(){o.forEach((function(e){return e.cancel()}))},isEmpty:function(){return 0===o.length}})}}(B,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=k(n({props:r,refresh:c,store:o},i));function c(){return E(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:T({plugins:r.plugins,options:e}),environment:r.environment}),n(n({refresh:c},u),i)},e.getDefaultProps=h,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.1",
"version": "1.5.2",
"license": "MIT",

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

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