@algolia/autocomplete-core
Advanced tools
Comparing version 1.0.0-alpha.44 to 1.0.0-alpha.45
@@ -19,4 +19,4 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
import { getItemsCount } from '@algolia/autocomplete-shared'; | ||
import { generateAutocompleteId, getNormalizedSources, flatten } from './utils'; | ||
import { getItemsCount, generateAutocompleteId } from '@algolia/autocomplete-shared'; | ||
import { getNormalizedSources, flatten } from './utils'; | ||
export function getDefaultProps(props, pluginSubscribers) { | ||
@@ -41,3 +41,3 @@ var _props$id; | ||
// Since `generateAutocompleteId` triggers a side effect (it increments | ||
// and internal counter), we don't want to execute it if unnecessary. | ||
// an internal counter), we don't want to execute it if unnecessary. | ||
id: (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generateAutocompleteId(), | ||
@@ -44,0 +44,0 @@ plugins: plugins, |
@@ -21,3 +21,9 @@ import { MaybePromise } from '@algolia/autocomplete-shared'; | ||
interface OnStateChangeProps<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> { | ||
/** | ||
* The current Autocomplete state. | ||
*/ | ||
state: AutocompleteState<TItem>; | ||
/** | ||
* The previous Autocomplete state. | ||
*/ | ||
prevState: AutocompleteState<TItem>; | ||
@@ -27,12 +33,14 @@ } | ||
/** | ||
* Whether to consider the experience in debug mode. | ||
* A flag to activate the debug mode. | ||
* | ||
* The debug mode is useful when developing because it doesn't close | ||
* the panel when the blur event occurs. | ||
* This is useful while developing because it keeps the panel open even when the blur event occurs. **Make sure to disable it in production.** | ||
* | ||
* See [**Debugging**](https://autocomplete.algolia.com/docs/debugging) for more information. | ||
* | ||
* @default false | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#debug | ||
*/ | ||
debug?: boolean; | ||
/** | ||
* The unique Autocomplete ID to create accessible attributes. | ||
* An ID for the autocomplete to create accessible attributes. | ||
* | ||
@@ -42,16 +50,22 @@ * It is incremented by default when creating a new Autocomplete instance. | ||
* @default "autocomplete-0" | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#id | ||
*/ | ||
id?: string; | ||
/** | ||
* Function called when the internal state changes. | ||
* The function called when the internal state changes. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#onstatechange | ||
*/ | ||
onStateChange?(props: OnStateChangeProps<TItem>): void; | ||
/** | ||
* The text that appears in the search box input when there is no query. | ||
* The placeholder text to show in the search input when there's no query. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#placeholder | ||
*/ | ||
placeholder?: string; | ||
/** | ||
* Whether to focus the search box when the page is loaded. | ||
* Whether to focus the search input or not when the page is loaded. | ||
* | ||
* @default false | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#autofocus | ||
*/ | ||
@@ -62,3 +76,6 @@ autoFocus?: boolean; | ||
* | ||
* We recommend using `0` when the autocomplete is used to open links, instead of triggering a search in an application. | ||
* | ||
* @default null | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#defaultactiveitemid | ||
*/ | ||
@@ -70,9 +87,10 @@ defaultActiveItemId?: number | null; | ||
* @default false | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#openonfocus | ||
*/ | ||
openOnFocus?: boolean; | ||
/** | ||
* The number of milliseconds that must elapse before the autocomplete | ||
* experience is stalled. | ||
* How many milliseconds must elapse before considering the autocomplete experience [stalled](https://autocomplete.algolia.com/docs/state#status). | ||
* | ||
* @default 300 | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#stallthreshold | ||
*/ | ||
@@ -82,22 +100,35 @@ stallThreshold?: number; | ||
* The initial state to apply when autocomplete is created. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#initialstate | ||
*/ | ||
initialState?: Partial<AutocompleteState<TItem>>; | ||
/** | ||
* The sources to get the suggestions from. | ||
* The [sources](https://autocomplete.algolia.com/docs/sources) to get the suggestions from. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#getsources | ||
*/ | ||
getSources?: GetSources<TItem>; | ||
/** | ||
* The environment from where your JavaScript is running. | ||
* Useful if you're using autocomplete in a different context than | ||
* `window`. | ||
* The environment in which your application is running. | ||
* | ||
* This is useful if you're using autocomplete in a different context than `window`. | ||
* | ||
* @default window | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#environment | ||
*/ | ||
environment?: AutocompleteEnvironment; | ||
/** | ||
* Navigator API to redirect the user when a link should be opened. | ||
* An implementation of Autocomplete's Navigator API to redirect the user when opening a link. | ||
* | ||
* Learn more on the [**Navigator API**](https://autocomplete.algolia.com/docs/keyboard-navigation) documentation. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#navigator | ||
*/ | ||
navigator?: Partial<AutocompleteNavigator<TItem>>; | ||
/** | ||
* The function called to determine whether the panel should open. | ||
* The function called to determine whether the panel should open or not. | ||
* | ||
* By default, the panel opens when there are items in the state. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#shouldpanelopen | ||
*/ | ||
@@ -108,11 +139,19 @@ shouldPanelOpen?(params: { | ||
/** | ||
* The function called when the Autocomplete form is submitted. | ||
* The function called when submitting the Autocomplete form. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#onsubmit | ||
*/ | ||
onSubmit?(params: OnSubmitParams<TItem>): void; | ||
/** | ||
* The function called when the Autocomplete form is reset. | ||
* The function called when resetting the Autocomplete form. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#onreset | ||
*/ | ||
onReset?(params: OnResetParams<TItem>): void; | ||
/** | ||
* The array of plugins. | ||
* The plugins that encapsulate and distribute custom Autocomplete behaviors. | ||
* | ||
* See [**Plugins**](https://autocomplete.algolia.com/docs/plugins) for more information. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/autocomplete-js#plugins | ||
*/ | ||
@@ -140,4 +179,3 @@ plugins?: Array<AutocompletePlugin<TItem, unknown>>; | ||
onReset(params: OnResetParams<TItem>): void; | ||
onInput?(params: OnInputParams<TItem>): void | Promise<any>; | ||
} | ||
export {}; |
@@ -5,3 +5,3 @@ import { AutocompleteScopeApi, BaseItem } from './AutocompleteApi'; | ||
declare type PluginSubscriber<TParams> = (params: TParams) => void; | ||
interface PluginSubscribeParams<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> { | ||
export interface PluginSubscribeParams<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> { | ||
onSelect(fn: PluginSubscriber<OnSelectParams<TItem>>): void; | ||
@@ -12,10 +12,9 @@ onActive(fn: PluginSubscriber<OnActiveParams<TItem>>): void; | ||
/** | ||
* Function called when Autocomplete starts. | ||
* The function called when Autocomplete starts. | ||
* | ||
* It can be used to subscribe to lifecycle hooks or to interact with the | ||
* Autocomplete state and context. | ||
* It lets you subscribe to lifecycle hooks and interact with the instance's state and context. | ||
*/ | ||
subscribe?(params: PluginSubscribeParams<TItem>): void; | ||
/** | ||
* Extra plugin object to expose properties and functions as APIs. | ||
* An extra plugin object to expose properties and functions as APIs. | ||
*/ | ||
@@ -22,0 +21,0 @@ data?: TData; |
@@ -6,8 +6,42 @@ import { BaseItem } from './AutocompleteApi'; | ||
export interface AutocompleteSetters<TItem extends BaseItem> { | ||
/** | ||
* Sets the highlighted item index. | ||
* | ||
* Pass `null` to unselect items. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/state#setactiveitemid | ||
*/ | ||
setActiveItemId: StateUpdater<AutocompleteState<TItem>['activeItemId']>; | ||
/** | ||
* Sets the query. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/state#setquery | ||
*/ | ||
setQuery: StateUpdater<AutocompleteState<TItem>['query']>; | ||
/** | ||
* Sets the collections. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/state#setcollections | ||
*/ | ||
setCollections: StateUpdater<Array<AutocompleteCollection<TItem> | AutocompleteCollectionItemsArray<TItem>>>; | ||
/** | ||
* Sets whether the panel is open or not. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/state#setisopen | ||
*/ | ||
setIsOpen: StateUpdater<AutocompleteState<TItem>['isOpen']>; | ||
/** | ||
* Sets the status of the autocomplete. | ||
* | ||
* @link https://autocomplete.algolia.com/docs/state#setisopen | ||
*/ | ||
setStatus: StateUpdater<AutocompleteState<TItem>['status']>; | ||
/** | ||
* Sets the context passed to lifecycle hooks. | ||
* | ||
* See more in [**Context**](https://autocomplete.algolia.com/docs/context). | ||
* | ||
* @link https://autocomplete.algolia.com/docs/state#setcontext | ||
*/ | ||
setContext: StateUpdater<AutocompleteState<TItem>['context']>; | ||
} |
@@ -16,7 +16,9 @@ import { MaybePromise } from '@algolia/autocomplete-shared'; | ||
/** | ||
* Identifier for the source. | ||
* Unique identifier for the source. | ||
*/ | ||
sourceId: string; | ||
/** | ||
* Get the string value of the item. The value is used to fill the search box. | ||
* The function called to get the value of an item. | ||
* | ||
* The value is used to fill the search box. | ||
*/ | ||
@@ -28,4 +30,5 @@ getItemInputValue?({ item, state, }: { | ||
/** | ||
* Get the URL of a item. The value is used to create default navigation features for | ||
* `onClick` and `onKeyDown`. | ||
* The function called to get the URL of the item. | ||
* | ||
* The value is used to add [keyboard accessibility](https://autocomplete.algolia.com/docs/keyboard-navigation) features to let users open items in the current tab, a new tab, or a new window. | ||
*/ | ||
@@ -37,14 +40,15 @@ getItemUrl?({ item, state, }: { | ||
/** | ||
* Function called when the input changes. You can use this function to filter/search the items based on the query. | ||
* The function called when the input changes. | ||
* | ||
* You can use this function to filter the items based on the query. | ||
*/ | ||
getItems(params: GetSourcesParams<TItem>): MaybePromise<TItem[] | TItem[][]>; | ||
/** | ||
* Function called when an item is selected. | ||
* The function called whenever an item is selected. | ||
*/ | ||
onSelect?(params: OnSelectParams<TItem>): void; | ||
/** | ||
* Function called when an item is highlighted. | ||
* The function called whenever an item is active. | ||
* | ||
* An item is highlighted either via keyboard navigation or via mouse over. | ||
* You can trigger different behaviors based on the event `type`. | ||
* You can trigger different behaviors if the item is active depending on the triggering event using the `event` parameter. | ||
*/ | ||
@@ -51,0 +55,0 @@ onActive?(params: OnActiveParams<TItem>): void; |
export * from './createConcurrentSafePromise'; | ||
export * from './flatten'; | ||
export * from './generateAutocompleteId'; | ||
export * from './getNextActiveItemId'; | ||
@@ -5,0 +4,0 @@ export * from './getNormalizedSources'; |
export * from './createConcurrentSafePromise'; | ||
export * from './flatten'; | ||
export * from './generateAutocompleteId'; | ||
export * from './getNextActiveItemId'; | ||
@@ -5,0 +4,0 @@ export * from './getNormalizedSources'; |
@@ -1,1 +0,1 @@ | ||
export declare const version = "1.0.0-alpha.44"; | ||
export declare const version = "1.0.0-alpha.45"; |
@@ -1,1 +0,1 @@ | ||
export var version = '1.0.0-alpha.44'; | ||
export var version = '1.0.0-alpha.45'; |
@@ -1,2 +0,2 @@ | ||
/*! @algolia/autocomplete-core 1.0.0-alpha.44 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */ | ||
/*! @algolia/autocomplete-core 1.0.0-alpha.45 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */ | ||
(function (global, factory) { | ||
@@ -142,2 +142,7 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
var autocompleteId = 0; | ||
function generateAutocompleteId() { | ||
return "autocomplete-".concat(autocompleteId++); | ||
} | ||
function getItemsCount(state) { | ||
@@ -221,7 +226,2 @@ if (state.collections.length === 0) { | ||
var autocompleteId = 0; | ||
function generateAutocompleteId() { | ||
return "autocomplete-".concat(autocompleteId++); | ||
} | ||
/** | ||
@@ -448,3 +448,3 @@ * Returns the next active item ID from the current state. | ||
// Since `generateAutocompleteId` triggers a side effect (it increments | ||
// and internal counter), we don't want to execute it if unnecessary. | ||
// an internal counter), we don't want to execute it if unnecessary. | ||
id: (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generateAutocompleteId(), | ||
@@ -1295,3 +1295,3 @@ plugins: plugins, | ||
var version = '1.0.0-alpha.44'; | ||
var version = '1.0.0-alpha.45'; | ||
@@ -1298,0 +1298,0 @@ exports.createAutocomplete = createAutocomplete; |
@@ -1,3 +0,3 @@ | ||
/*! @algolia/autocomplete-core 1.0.0-alpha.44 | 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 a(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 c(e){return 0===e.collections.length?0:e.collections.reduce((function(e,t){return e+t.items.length}),0)}function l(e){return e.reduce((function(e,t){return e.concat(t)}),[])}var s=0;function p(e,t,n,r){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 f=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 a=t.collections[o];if(a===n){r=!0;break}i+=a.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:{},u=e.plugins||[];return o(o({debug:!1,openOnFocus:!1,placeholder:"",autoFocus:!1,defaultActiveItemId:null,stallThreshold:300,environment:i,shouldPanelOpen:function(e){return c(e.state)>0}},e),{},{id:null!==(r=e.id)&&void 0!==r?r:"autocomplete-".concat(s++),plugins:u,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),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(a(u.map((function(e){return e.getSources}))),[e.getSources]).filter(Boolean).map((function(e){return function(e,n){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){e.sourceId;var t=o({getItemInputValue:function(e){return e.state.query},getItemUrl:function(){},onSelect:function(e){(0,e.setIsOpen)(!1)},onActive:f},e);return Promise.resolve(t)})))}))}(e,r)}))).then((function(e){return l(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)})}var g=null;function y(e){var n=e.event,r=e.nextState,a=void 0===r?{}:r,u=e.props,c=e.query,l=e.refresh,s=e.store,p=i(e,["event","nextState","props","query","refresh","store"]);g&&u.environment.clearTimeout(g);var f,v=p.setCollections,d=p.setIsOpen,y=p.setQuery,h=p.setActiveItemId,I=p.setStatus;return y(c),h(u.defaultActiveItemId),c||!1!==u.openOnFocus?(I("loading"),g=u.environment.setTimeout((function(){I("stalled")}),u.stallThreshold),u.getSources(o({query:c,refresh:l,state:s.getState()},p)).then((function(e){return I("loading"),Promise.all(e.map((function(e){return Promise.resolve(e.getItems(o({query:c,refresh:l,state:s.getState()},p))).then((function(n){return Array.isArray(n),"The `getItems` function must return an array of items but returned type ".concat(JSON.stringify(t(n)),":\n\n").concat(JSON.stringify(n,null,2)),{source:e,items:n}}))}))).then((function(e){var t;I("idle"),v(e);var r=u.shouldPanelOpen({state:s.getState()});d(null!==(t=a.isOpen)&&void 0!==t?t:u.openOnFocus&&!c&&r||r);var i=m(s.getState());if(null!==s.getState().activeItemId&&i){var f=i.item,g=i.itemInputValue,y=i.itemUrl,h=i.source;h.onActive(o({event:n,item:f,itemInputValue:g,itemUrl:y,refresh:l,source:h,state:s.getState()},p))}})).finally((function(){g&&u.environment.clearTimeout(g)}))}))):(I("idle"),v(s.getState().collections.map((function(e){return o(o({},e),{},{items:[]})}))),d(null!==(f=a.isOpen)&&void 0!==f?f:u.shouldPanelOpen({state:s.getState()})),Promise.resolve())}function h(e){var t=e.props,n=e.refresh,r=e.store,a=i(e,["props","refresh","store"]);return{getEnvironmentProps:function(e){var n=e.inputElement,a=e.formElement,u=e.panelElement;return o({onTouchStart:function(e){!1!==r.getState().isOpen&&e.target!==n&&(!1===[a,u].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 u;i.preventDefault(),t.onSubmit(o({event:i,refresh:n,state:r.getState()},a)),r.dispatch("submit",null),null===(u=e.inputElement)||void 0===u||u.blur()},onReset:function(i){var u;i.preventDefault(),t.onReset(o({event:i,refresh:n,state:r.getState()},a)),r.dispatch("reset",null),null===(u=e.inputElement)||void 0===u||u.focus()}},i(e,["inputElement"]))},getLabelProps:function(e){return o({htmlFor:"".concat(t.id,"-input"),id:"".concat(t.id,"-label")},e)},getInputProps:function(e){function u(e){(t.openOnFocus||Boolean(r.getState().query))&&y(o({event:e,props:t,query:r.getState().completion||r.getState().query,refresh:n,store:r},a)),r.dispatch("focus",null)}var c="ontouchstart"in t.environment,l=e||{},s=(l.inputElement,l.maxLength),p=void 0===s?512:s,f=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:p,type:"search",onChange:function(e){y(o({event:e,props:t,query:e.currentTarget.value.slice(0,p),refresh:n,store:r},a))},onKeyDown:function(e){!function(e){var t=e.event,n=e.props,r=e.refresh,a=e.store,u=i(e,["event","props","refresh","store"]);if("ArrowUp"===t.key||"ArrowDown"===t.key){t.preventDefault(),a.dispatch(t.key,null);var c=n.environment.document.getElementById("".concat(n.id,"-item-").concat(a.getState().activeItemId));c&&(c.scrollIntoViewIfNeeded?c.scrollIntoViewIfNeeded(!1):c.scrollIntoView(!1));var l=m(a.getState());if(null!==a.getState().activeItemId&&l){var s=l.item,p=l.itemInputValue,f=l.itemUrl,v=l.source;v.onActive(o({event:t,item:s,itemInputValue:p,itemUrl:f,refresh:r,source:v,state:a.getState()},u))}}else if("Escape"===t.key)t.preventDefault(),a.dispatch(t.key,null);else if("Enter"===t.key){if(null===a.getState().activeItemId||a.getState().collections.every((function(e){return 0===e.items.length})))return;t.preventDefault();var d=m(a.getState()),g=d.item,h=d.itemInputValue,I=d.itemUrl,S=d.source;if(t.metaKey||t.ctrlKey)void 0!==I&&(S.onSelect(o({event:t,item:g,itemInputValue:h,itemUrl:I,refresh:r,source:S,state:a.getState()},u)),n.navigator.navigateNewTab({itemUrl:I,item:g,state:a.getState()}));else if(t.shiftKey)void 0!==I&&(S.onSelect(o({event:t,item:g,itemInputValue:h,itemUrl:I,refresh:r,source:S,state:a.getState()},u)),n.navigator.navigateNewWindow({itemUrl:I,item:g,state:a.getState()}));else if(t.altKey);else{if(void 0!==I)return S.onSelect(o({event:t,item:g,itemInputValue:h,itemUrl:I,refresh:r,source:S,state:a.getState()},u)),void n.navigator.navigate({itemUrl:I,item:g,state:a.getState()});y(o({event:t,nextState:{isOpen:!1},props:n,query:h,refresh:r,store:a},u)).then((function(){S.onSelect(o({event:t,item:g,itemInputValue:h,itemUrl:I,refresh:r,source:S,state:a.getState()},u))}))}}}(o({event:e,props:t,refresh:n,store:r},a))},onFocus:u,onBlur:function(){c||r.dispatch("blur",null)},onClick:function(n){e.inputElement!==t.environment.document.activeElement||r.getState().isOpen||u(n)}},f)},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 u=e.item,c=e.source,l=i(e,["item","source"]);return o({id:"".concat(t.id,"-item-").concat(u.__autocomplete_id),role:"option","aria-selected":r.getState().activeItemId===u.__autocomplete_id,onMouseMove:function(e){if(u.__autocomplete_id!==r.getState().activeItemId){r.dispatch("mousemove",u.__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()},a))}}},onMouseDown:function(e){e.preventDefault()},onClick:function(e){var i=c.getItemInputValue({item:u,state:r.getState()}),l=c.getItemUrl({item:u,state:r.getState()});(l?Promise.resolve():y(o({event:e,nextState:{isOpen:!1},props:t,query:i,refresh:n,store:r},a))).then((function(){c.onSelect(o({event:e,item:u,itemInputValue:i,itemUrl:l,refresh:n,source:c,state:r.getState()},a))}))}},l)}}}function I(e){var t=e.state;return!1===t.isOpen||null===t.activeItemId?null:m(t).itemInputValue||null}var S=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:p(1,e.activeItemId,c(e),t.props.defaultActiveItemId)});return o(o({},n),{},{completion:I({state:n})});case"ArrowUp":var r=o(o({},e),{},{activeItemId:p(-1,e.activeItemId,c(e),t.props.defaultActiveItemId)});return o(o({},r),{},{completion:I({state:r})});case"Escape":return e.isOpen?o(o({},e),{},{isOpen:!1,completion:null}):o(o({},e),{},{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,a){var u=o({},r);r=e(r,{type:i,props:t,payload:a}),n({state:r,prevState:u})}}}(S,n,(function(e){var t=e.prevState,r=e.state;n.onStateChange(o({prevState:t,state:r,refresh:u},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:l(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}),a=h(o({props:n,refresh:u,store:r},i));function u(){return y(o({event:new Event("input"),nextState:{isOpen:r.getState().isOpen},props:n,query:r.getState().query,refresh:u,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:u,onSelect:function(e){t.push({onSelect:e})},onActive:function(e){t.push({onActive:e})}}))})),o(o({refresh:u},a),i)},e.getDefaultProps=d,e.version="1.0.0-alpha.44",Object.defineProperty(e,"__esModule",{value:!0})})); | ||
/*! @algolia/autocomplete-core 1.0.0-alpha.45 | 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 a(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}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 p(e,t,n,r){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 f=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 a=t.collections[o];if(a===n){r=!0;break}i+=a.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:{},u=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:u,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),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(a(u.map((function(e){return e.getSources}))),[e.getSources]).filter(Boolean).map((function(e){return function(e,n){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){e.sourceId;var t=o({getItemInputValue:function(e){return e.state.query},getItemUrl:function(){},onSelect:function(e){(0,e.setIsOpen)(!1)},onActive:f},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)})}var g=null;function y(e){var n=e.event,r=e.nextState,a=void 0===r?{}:r,u=e.props,c=e.query,l=e.refresh,s=e.store,p=i(e,["event","nextState","props","query","refresh","store"]);g&&u.environment.clearTimeout(g);var f,v=p.setCollections,d=p.setIsOpen,y=p.setQuery,h=p.setActiveItemId,I=p.setStatus;return y(c),h(u.defaultActiveItemId),c||!1!==u.openOnFocus?(I("loading"),g=u.environment.setTimeout((function(){I("stalled")}),u.stallThreshold),u.getSources(o({query:c,refresh:l,state:s.getState()},p)).then((function(e){return I("loading"),Promise.all(e.map((function(e){return Promise.resolve(e.getItems(o({query:c,refresh:l,state:s.getState()},p))).then((function(n){return Array.isArray(n),"The `getItems` function must return an array of items but returned type ".concat(JSON.stringify(t(n)),":\n\n").concat(JSON.stringify(n,null,2)),{source:e,items:n}}))}))).then((function(e){var t;I("idle"),v(e);var r=u.shouldPanelOpen({state:s.getState()});d(null!==(t=a.isOpen)&&void 0!==t?t:u.openOnFocus&&!c&&r||r);var i=m(s.getState());if(null!==s.getState().activeItemId&&i){var f=i.item,g=i.itemInputValue,y=i.itemUrl,h=i.source;h.onActive(o({event:n,item:f,itemInputValue:g,itemUrl:y,refresh:l,source:h,state:s.getState()},p))}})).finally((function(){g&&u.environment.clearTimeout(g)}))}))):(I("idle"),v(s.getState().collections.map((function(e){return o(o({},e),{},{items:[]})}))),d(null!==(f=a.isOpen)&&void 0!==f?f:u.shouldPanelOpen({state:s.getState()})),Promise.resolve())}function h(e){var t=e.props,n=e.refresh,r=e.store,a=i(e,["props","refresh","store"]);return{getEnvironmentProps:function(e){var n=e.inputElement,a=e.formElement,u=e.panelElement;return o({onTouchStart:function(e){!1!==r.getState().isOpen&&e.target!==n&&(!1===[a,u].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 u;i.preventDefault(),t.onSubmit(o({event:i,refresh:n,state:r.getState()},a)),r.dispatch("submit",null),null===(u=e.inputElement)||void 0===u||u.blur()},onReset:function(i){var u;i.preventDefault(),t.onReset(o({event:i,refresh:n,state:r.getState()},a)),r.dispatch("reset",null),null===(u=e.inputElement)||void 0===u||u.focus()}},i(e,["inputElement"]))},getLabelProps:function(e){return o({htmlFor:"".concat(t.id,"-input"),id:"".concat(t.id,"-label")},e)},getInputProps:function(e){function u(e){(t.openOnFocus||Boolean(r.getState().query))&&y(o({event:e,props:t,query:r.getState().completion||r.getState().query,refresh:n,store:r},a)),r.dispatch("focus",null)}var c="ontouchstart"in t.environment,l=e||{},s=(l.inputElement,l.maxLength),p=void 0===s?512:s,f=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:p,type:"search",onChange:function(e){y(o({event:e,props:t,query:e.currentTarget.value.slice(0,p),refresh:n,store:r},a))},onKeyDown:function(e){!function(e){var t=e.event,n=e.props,r=e.refresh,a=e.store,u=i(e,["event","props","refresh","store"]);if("ArrowUp"===t.key||"ArrowDown"===t.key){t.preventDefault(),a.dispatch(t.key,null);var c=n.environment.document.getElementById("".concat(n.id,"-item-").concat(a.getState().activeItemId));c&&(c.scrollIntoViewIfNeeded?c.scrollIntoViewIfNeeded(!1):c.scrollIntoView(!1));var l=m(a.getState());if(null!==a.getState().activeItemId&&l){var s=l.item,p=l.itemInputValue,f=l.itemUrl,v=l.source;v.onActive(o({event:t,item:s,itemInputValue:p,itemUrl:f,refresh:r,source:v,state:a.getState()},u))}}else if("Escape"===t.key)t.preventDefault(),a.dispatch(t.key,null);else if("Enter"===t.key){if(null===a.getState().activeItemId||a.getState().collections.every((function(e){return 0===e.items.length})))return;t.preventDefault();var d=m(a.getState()),g=d.item,h=d.itemInputValue,I=d.itemUrl,S=d.source;if(t.metaKey||t.ctrlKey)void 0!==I&&(S.onSelect(o({event:t,item:g,itemInputValue:h,itemUrl:I,refresh:r,source:S,state:a.getState()},u)),n.navigator.navigateNewTab({itemUrl:I,item:g,state:a.getState()}));else if(t.shiftKey)void 0!==I&&(S.onSelect(o({event:t,item:g,itemInputValue:h,itemUrl:I,refresh:r,source:S,state:a.getState()},u)),n.navigator.navigateNewWindow({itemUrl:I,item:g,state:a.getState()}));else if(t.altKey);else{if(void 0!==I)return S.onSelect(o({event:t,item:g,itemInputValue:h,itemUrl:I,refresh:r,source:S,state:a.getState()},u)),void n.navigator.navigate({itemUrl:I,item:g,state:a.getState()});y(o({event:t,nextState:{isOpen:!1},props:n,query:h,refresh:r,store:a},u)).then((function(){S.onSelect(o({event:t,item:g,itemInputValue:h,itemUrl:I,refresh:r,source:S,state:a.getState()},u))}))}}}(o({event:e,props:t,refresh:n,store:r},a))},onFocus:u,onBlur:function(){c||r.dispatch("blur",null)},onClick:function(n){e.inputElement!==t.environment.document.activeElement||r.getState().isOpen||u(n)}},f)},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 u=e.item,c=e.source,l=i(e,["item","source"]);return o({id:"".concat(t.id,"-item-").concat(u.__autocomplete_id),role:"option","aria-selected":r.getState().activeItemId===u.__autocomplete_id,onMouseMove:function(e){if(u.__autocomplete_id!==r.getState().activeItemId){r.dispatch("mousemove",u.__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()},a))}}},onMouseDown:function(e){e.preventDefault()},onClick:function(e){var i=c.getItemInputValue({item:u,state:r.getState()}),l=c.getItemUrl({item:u,state:r.getState()});(l?Promise.resolve():y(o({event:e,nextState:{isOpen:!1},props:t,query:i,refresh:n,store:r},a))).then((function(){c.onSelect(o({event:e,item:u,itemInputValue:i,itemUrl:l,refresh:n,source:c,state:r.getState()},a))}))}},l)}}}function I(e){var t=e.state;return!1===t.isOpen||null===t.activeItemId?null:m(t).itemInputValue||null}var S=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:p(1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return o(o({},n),{},{completion:I({state:n})});case"ArrowUp":var r=o(o({},e),{},{activeItemId:p(-1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return o(o({},r),{},{completion:I({state:r})});case"Escape":return e.isOpen?o(o({},e),{},{isOpen:!1,completion:null}):o(o({},e),{},{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,a){var u=o({},r);r=e(r,{type:i,props:t,payload:a}),n({state:r,prevState:u})}}}(S,n,(function(e){var t=e.prevState,r=e.state;n.onStateChange(o({prevState:t,state:r,refresh:u},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}),a=h(o({props:n,refresh:u,store:r},i));function u(){return y(o({event:new Event("input"),nextState:{isOpen:r.getState().isOpen},props:n,query:r.getState().query,refresh:u,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:u,onSelect:function(e){t.push({onSelect:e})},onActive:function(e){t.push({onActive:e})}}))})),o(o({refresh:u},a),i)},e.getDefaultProps=d,e.version="1.0.0-alpha.45",Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@algolia/autocomplete-core", | ||
"description": "Core primitives for building autocomplete experiences.", | ||
"version": "1.0.0-alpha.44", | ||
"version": "1.0.0-alpha.45", | ||
"license": "MIT", | ||
@@ -34,4 +34,4 @@ "homepage": "https://github.com/algolia/autocomplete", | ||
"dependencies": { | ||
"@algolia/autocomplete-shared": "1.0.0-alpha.44" | ||
"@algolia/autocomplete-shared": "1.0.0-alpha.45" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
261654
2935
74
+ Added@algolia/autocomplete-shared@1.0.0-alpha.45(transitive)
- Removed@algolia/autocomplete-shared@1.0.0-alpha.44(transitive)