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

@algolia/autocomplete-core

Package Overview
Dependencies
Maintainers
68
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/autocomplete-core - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

dist/esm/reshape.d.ts

2

dist/esm/getAutocompleteSetters.js

@@ -7,3 +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 { flatten } from './utils';
import { flatten } from '@algolia/autocomplete-shared';
export function getAutocompleteSetters(_ref) {

@@ -10,0 +10,0 @@ var store = _ref.store;

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

import { getItemsCount, generateAutocompleteId } from '@algolia/autocomplete-shared';
import { getNormalizedSources, flatten } from './utils';
import { getItemsCount, generateAutocompleteId, flatten } from '@algolia/autocomplete-shared';
import { getNormalizedSources } from './utils';
export function getDefaultProps(props, pluginSubscribers) {

@@ -41,2 +41,6 @@ var _props$id;

return getItemsCount(state) > 0;
},
reshape: function reshape(_ref2) {
var sources = _ref2.sources;
return sources;
}

@@ -119,13 +123,13 @@ }, props), {}, {

navigator: _objectSpread({
navigate: function navigate(_ref2) {
var itemUrl = _ref2.itemUrl;
navigate: function navigate(_ref3) {
var itemUrl = _ref3.itemUrl;
environment.location.assign(itemUrl);
},
navigateNewTab: function navigateNewTab(_ref3) {
var itemUrl = _ref3.itemUrl;
navigateNewTab: function navigateNewTab(_ref4) {
var itemUrl = _ref4.itemUrl;
var windowReference = environment.open(itemUrl, '_blank', 'noopener');
windowReference === null || windowReference === void 0 ? void 0 : windowReference.focus();
},
navigateNewWindow: function navigateNewWindow(_ref4) {
var itemUrl = _ref4.itemUrl;
navigateNewWindow: function navigateNewWindow(_ref5) {
var itemUrl = _ref5.itemUrl;
environment.open(itemUrl, '_blank', 'noopener');

@@ -132,0 +136,0 @@ }

@@ -11,2 +11,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 { reshape } from './reshape';
import { preResolve, resolve, postResolve } from './resolve';

@@ -73,2 +74,8 @@ import { getActiveItem } from './utils';

}).then(function (collections) {
return reshape({
collections: collections,
props: props,
state: store.getState()
});
}).then(function (collections) {
var _nextState$isOpen2;

@@ -75,0 +82,0 @@

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

import { invariant } from '@algolia/autocomplete-shared';
import { flatten, mapToAlgoliaResponse } from './utils';
import { decycle, flatten, invariant } from '@algolia/autocomplete-shared';
import { mapToAlgoliaResponse } from './utils';

@@ -109,3 +109,5 @@ function isDescription(item) {

var items = transform ? transform(mapToAlgoliaResponse(results)) : results;
invariant(Array.isArray(items), "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(items, null, 2), ".\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"));
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");
});
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"));

@@ -112,0 +114,0 @@ return {

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

import { AutocompletePlugin } from './AutocompletePlugin';
import { Reshape } from './AutocompleteReshape';
import { AutocompleteSource, InternalAutocompleteSource } from './AutocompleteSource';

@@ -153,2 +154,12 @@ import { AutocompleteState } from './AutocompleteState';

plugins?: Array<AutocompletePlugin<any, any>>;
/**
* The function called to reshape the sources after they're resolved.
*
* This is useful to transform sources before rendering them. You can group sources by attribute, remove duplicates, create shared limits between sources, etc.
*
* See [**Reshaping sources**](https://www.algolia.com/doc/ui-libraries/autocomplete/guides/reshaping-sources/) for more information.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-reshape
*/
reshape?: Reshape<TItem>;
}

@@ -174,3 +185,4 @@ export interface InternalAutocompleteOptions<TItem extends BaseItem> extends AutocompleteOptions<TItem> {

onReset(params: OnResetParams<TItem>): void;
reshape: Reshape<TItem>;
}
export {};

@@ -9,2 +9,3 @@ export * from './AutocompleteApi';

export * from './AutocompletePlugin';
export * from './AutocompleteReshape';
export * from './AutocompleteSetters';

@@ -11,0 +12,0 @@ export * from './AutocompleteState';

@@ -9,2 +9,3 @@ export * from './AutocompleteApi';

export * from './AutocompletePlugin';
export * from './AutocompleteReshape';
export * from './AutocompleteSetters';

@@ -11,0 +12,0 @@ export * from './AutocompleteState';

@@ -9,3 +9,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 { invariant } from '@algolia/autocomplete-shared';
import { invariant, decycle } from '@algolia/autocomplete-shared';
import { noop } from './noop';

@@ -15,3 +15,5 @@ export function getNormalizedSources(getSources, params) {

return Promise.resolve(getSources(params)).then(function (sources) {
invariant(Array.isArray(sources), "The `getSources` function must return an array of sources but returned type ".concat(JSON.stringify(_typeof(sources)), ":\n\n").concat(JSON.stringify(sources, null, 2)));
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 Promise.all(sources // We allow `undefined` and `false` sources to allow users to use

@@ -18,0 +20,0 @@ // `Boolean(query) && source` (=> `false`).

export * from './createConcurrentSafePromise';
export * from './flatten';
export * from './getNextActiveItemId';

@@ -4,0 +3,0 @@ export * from './getNormalizedSources';

export * from './createConcurrentSafePromise';
export * from './flatten';
export * from './getNextActiveItemId';

@@ -4,0 +3,0 @@ export * from './getNormalizedSources';

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

export declare const version = "1.2.2";
export declare const version = "1.3.0";

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

export var version = '1.2.2';
export var version = '1.3.0';

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

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

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

function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray$1(o, minLen) {
if (!o) return;
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$1(o, minLen);
}
function _arrayLikeToArray$1(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
return arr2;
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _typeof$1(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof$1 = function _typeof(obj) {
return typeof obj;
};
} else {
_typeof$1 = function _typeof(obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof$1(obj);
}
/**
* Decycles objects with circular references.
* This is used to print cyclic structures in development environment only.
*/
function decycle(obj) {
var seen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();
if ( !obj || _typeof$1(obj) !== 'object') {
return obj;
}
if (seen.has(obj)) {
return '[Circular]';
}
var newSeen = seen.add(obj);
if (Array.isArray(obj)) {
return obj.map(function (x) {
return decycle(x, newSeen);
});
}
return Object.fromEntries(Object.entries(obj).map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return [key, decycle(value, newSeen)];
}));
}
function flatten(values) {
return values.reduce(function (a, b) {
return a.concat(b);
}, []);
}
var autocompleteId = 0;

@@ -166,3 +279,3 @@ function generateAutocompleteId() {

if (!condition) {
throw new Error("[Autocomplete] ".concat(message));
throw new Error("[Autocomplete] ".concat(typeof message === 'function' ? message() : message));
}

@@ -221,6 +334,49 @@ }

function flatten(values) {
return values.reduce(function (a, b) {
return a.concat(b);
}, []);
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
};
}

@@ -267,3 +423,5 @@

return Promise.resolve(getSources(params)).then(function (sources) {
invariant(Array.isArray(sources), "The `getSources` function must return an array of sources but returned type ".concat(JSON.stringify(_typeof(sources)), ":\n\n").concat(JSON.stringify(sources, null, 2)));
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 Promise.all(sources // We allow `undefined` and `false` sources to allow users to use

@@ -431,51 +589,2 @@ // `Boolean(query) && source` (=> `false`).

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) {

@@ -500,2 +609,6 @@ var _props$id;

return getItemsCount(state) > 0;
},
reshape: function reshape(_ref2) {
var sources = _ref2.sources;
return sources;
}

@@ -578,13 +691,13 @@ }, props), {}, {

navigator: _objectSpread2({
navigate: function navigate(_ref2) {
var itemUrl = _ref2.itemUrl;
navigate: function navigate(_ref3) {
var itemUrl = _ref3.itemUrl;
environment.location.assign(itemUrl);
},
navigateNewTab: function navigateNewTab(_ref3) {
var itemUrl = _ref3.itemUrl;
navigateNewTab: function navigateNewTab(_ref4) {
var itemUrl = _ref4.itemUrl;
var windowReference = environment.open(itemUrl, '_blank', 'noopener');
windowReference === null || windowReference === void 0 ? void 0 : windowReference.focus();
},
navigateNewWindow: function navigateNewWindow(_ref4) {
var itemUrl = _ref4.itemUrl;
navigateNewWindow: function navigateNewWindow(_ref5) {
var itemUrl = _ref5.itemUrl;
environment.open(itemUrl, '_blank', 'noopener');

@@ -596,2 +709,30 @@ }

function reshape(_ref) {
var collections = _ref.collections,
props = _ref.props,
state = _ref.state;
// Sources are grouped by `sourceId` to conveniently pick them via destructuring.
// Example: `const { recentSearchesPlugin } = sourcesBySourceId`
var sourcesBySourceId = collections.reduce(function (acc, collection) {
return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, collection.source.sourceId, _objectSpread2(_objectSpread2({}, collection.source), {}, {
getItems: function getItems() {
// We provide the resolved items from the collection to the `reshape` prop.
return flatten(collection.items);
}
})));
}, {});
var reshapeSources = props.reshape({
sources: Object.values(sourcesBySourceId),
sourcesBySourceId: sourcesBySourceId,
state: state
}); // We reconstruct the collections with the items modified by the `reshape` prop.
return flatten(reshapeSources).filter(Boolean).map(function (source) {
return {
source: source,
items: source.getItems()
};
});
}
function isDescription(item) {

@@ -681,3 +822,5 @@ return Boolean(item.execute);

var items = transform ? transform(mapToAlgoliaResponse(results)) : results;
invariant(Array.isArray(items), "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(items, null, 2), ".\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"));
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");
});
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"));

@@ -750,2 +893,8 @@ return {

}).then(function (collections) {
return reshape({
collections: collections,
props: props,
state: store.getState()
});
}).then(function (collections) {
var _nextState$isOpen2;

@@ -1472,3 +1621,3 @@

var version = '1.2.2';
var version = '1.3.0';

@@ -1475,0 +1624,0 @@ exports.createAutocomplete = createAutocomplete;

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

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

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

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