@algolia/autocomplete-core
Advanced tools
Comparing version 1.6.3 to 1.7.0
@@ -17,2 +17,3 @@ var _excluded = ["props", "refresh", "store"], | ||
import { noop } from '@algolia/autocomplete-shared'; | ||
import { onInput } from './onInput'; | ||
@@ -33,38 +34,45 @@ import { onKeyDown as _onKeyDown } from './onKeyDown'; | ||
return _objectSpread({ | ||
// On touch devices, we do not rely on the native `blur` event of the | ||
// input to close the panel, but rather on a custom `touchstart` event | ||
// outside of the autocomplete elements. | ||
// This ensures a working experience on mobile because we blur the input | ||
// on touch devices when the user starts scrolling (`touchmove`). | ||
// @TODO: support cases where there are multiple Autocomplete instances. | ||
function onMouseDownOrTouchStart(event) { | ||
// The `onTouchStart`/`onMouseDown` events shouldn't trigger the `blur` | ||
// handler when it's not an interaction with Autocomplete. | ||
// We detect it with the following heuristics: | ||
// - the panel is closed AND there are no pending requests | ||
// (no interaction with the autocomplete, no future state updates) | ||
// - OR the touched target is the input element (should open the panel) | ||
var isAutocompleteInteraction = store.getState().isOpen || !store.pendingRequests.isEmpty(); | ||
if (!isAutocompleteInteraction || event.target === inputElement) { | ||
return; | ||
} // @TODO: support cases where there are multiple Autocomplete instances. | ||
// Right now, a second instance makes this computation return false. | ||
onTouchStart: function onTouchStart(event) { | ||
// The `onTouchStart` event shouldn't trigger the `blur` handler when | ||
// it's not an interaction with Autocomplete. We detect it with the | ||
// following heuristics: | ||
// - the panel is closed AND there are no pending requests | ||
// (no interaction with the autocomplete, no future state updates) | ||
// - OR the touched target is the input element (should open the panel) | ||
var isAutocompleteInteraction = store.getState().isOpen || !store.pendingRequests.isEmpty(); | ||
if (!isAutocompleteInteraction || event.target === inputElement) { | ||
return; | ||
} | ||
var isTargetWithinAutocomplete = [formElement, panelElement].some(function (contextNode) { | ||
return isOrContainsNode(contextNode, event.target); | ||
}); | ||
var isTargetWithinAutocomplete = [formElement, panelElement].some(function (contextNode) { | ||
return isOrContainsNode(contextNode, event.target); | ||
}); | ||
if (isTargetWithinAutocomplete === false) { | ||
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they | ||
// could reopen the panel once they resolve. | ||
// We want to prevent any subsequent query from reopening the panel | ||
// because it would result in an unsolicited UI behavior. | ||
if (isTargetWithinAutocomplete === false) { | ||
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they | ||
// could reopen the panel once they resolve. | ||
// We want to prevent any subsequent query from reopening the panel | ||
// because it would result in an unsolicited UI behavior. | ||
if (!props.debug) { | ||
store.pendingRequests.cancelAll(); | ||
} | ||
if (!props.debug) { | ||
store.pendingRequests.cancelAll(); | ||
} | ||
}, | ||
} | ||
} | ||
return _objectSpread({ | ||
// We do not rely on the native `blur` event of the input to close the | ||
// panel, but rather on a custom `touchstart`/`mousedown` event outside | ||
// of the autocomplete elements. | ||
// This ensures we don't mistakenly interpret interactions within the | ||
// autocomplete (but outside of the input) as a signal to close the panel. | ||
// For example, clicking reset button causes an input blur, but if | ||
// `openOnFocus=true`, it shouldn't close the panel. | ||
// On touch devices, scrolling results (`touchmove`) causes an input blur | ||
// but shouldn't close the panel. | ||
onTouchStart: onMouseDownOrTouchStart, | ||
onMouseDown: onMouseDownOrTouchStart, | ||
// When scrolling on touch devices (mobiles, tablets, etc.), we want to | ||
@@ -148,4 +156,2 @@ // mimic the native platform behavior where the input is blurred to | ||
var isTouchDevice = ('ontouchstart' in props.environment); | ||
var _ref2 = providedProps || {}, | ||
@@ -195,16 +201,6 @@ inputElement = _ref2.inputElement, | ||
onFocus: onFocus, | ||
onBlur: function onBlur() { | ||
// We do rely on the `blur` event on touch devices. | ||
// See explanation in `onTouchStart`. | ||
if (!isTouchDevice) { | ||
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they | ||
// could reopen the panel once they resolve. | ||
// We want to prevent any subsequent query from reopening the panel | ||
// because it would result in an unsolicited UI behavior. | ||
if (!props.debug) { | ||
store.pendingRequests.cancelAll(); | ||
} | ||
} | ||
}, | ||
// We don't rely on the `blur` event. | ||
// See explanation in `onTouchStart`/`onMouseDown`. | ||
// @MAJOR See if we need to keep this handler. | ||
onBlur: noop, | ||
onClick: function onClick(event) { | ||
@@ -211,0 +207,0 @@ // When the panel is closed and you click on the input while |
@@ -95,2 +95,9 @@ var _excluded = ["event", "props", "refresh", "store"]; | ||
store.pendingRequests.cancelAll(); | ||
} else if (event.key === 'Tab') { | ||
store.dispatch('blur', null); // Hitting the `Escape` key signals the end of a user interaction with the | ||
// autocomplete. At this point, we should ignore any requests that are still | ||
// pending and could reopen the panel once they resolve, because that would | ||
// result in an unsolicited UI behavior. | ||
store.pendingRequests.cancelAll(); | ||
} else if (event.key === 'Enter') { | ||
@@ -102,2 +109,10 @@ // No active item, so we let the browser handle the native `onSubmit` form | ||
})) { | ||
// If requests are still pending when the panel closes, they could reopen | ||
// the panel once they resolve. | ||
// We want to prevent any subsequent query from reopening the panel | ||
// because it would result in an unsolicited UI behavior. | ||
if (!props.debug) { | ||
store.pendingRequests.cancelAll(); | ||
} | ||
return; | ||
@@ -104,0 +119,0 @@ } // This prevents the `onSubmit` event to be sent because an item is |
@@ -21,2 +21,3 @@ import { BaseItem } from './AutocompleteApi'; | ||
onTouchMove(event: TouchEvent): void; | ||
onMouseDown(event: MouseEvent): void; | ||
}; | ||
@@ -23,0 +24,0 @@ export declare type GetRootProps = (props?: { |
import { CancelablePromise } from '.'; | ||
export declare type CancelablePromiseList<TValue> = { | ||
/** | ||
* Add a cancelable promise to the list. | ||
* | ||
* @param cancelablePromise The cancelable promise to add. | ||
*/ | ||
add(cancelablePromise: CancelablePromise<TValue>): CancelablePromise<TValue>; | ||
/** | ||
* Cancel all pending promises. | ||
* | ||
* Requests aren't actually stopped. All pending promises will settle, but | ||
* attached handlers won't run. | ||
*/ | ||
cancelAll(): void; | ||
/** | ||
* Whether there are pending promises in the list. | ||
*/ | ||
isEmpty(): boolean; | ||
}; | ||
export declare function createCancelablePromiseList<TValue>(): CancelablePromiseList<TValue>; |
@@ -1,2 +0,2 @@ | ||
/*! @algolia/autocomplete-core 1.6.3 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */ | ||
/*! @algolia/autocomplete-core 1.7.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */ | ||
(function (global, factory) { | ||
@@ -267,3 +267,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
var version = '1.6.3'; | ||
var version = '1.7.0'; | ||
@@ -1140,2 +1140,9 @@ var userAgents = [{ | ||
store.pendingRequests.cancelAll(); | ||
} else if (event.key === 'Tab') { | ||
store.dispatch('blur', null); // Hitting the `Escape` key signals the end of a user interaction with the | ||
// autocomplete. At this point, we should ignore any requests that are still | ||
// pending and could reopen the panel once they resolve, because that would | ||
// result in an unsolicited UI behavior. | ||
store.pendingRequests.cancelAll(); | ||
} else if (event.key === 'Enter') { | ||
@@ -1147,2 +1154,10 @@ // No active item, so we let the browser handle the native `onSubmit` form | ||
})) { | ||
// If requests are still pending when the panel closes, they could reopen | ||
// the panel once they resolve. | ||
// We want to prevent any subsequent query from reopening the panel | ||
// because it would result in an unsolicited UI behavior. | ||
if (!props.debug) { | ||
store.pendingRequests.cancelAll(); | ||
} | ||
return; | ||
@@ -1255,38 +1270,45 @@ } // This prevents the `onSubmit` event to be sent because an item is | ||
return _objectSpread2({ | ||
// On touch devices, we do not rely on the native `blur` event of the | ||
// input to close the panel, but rather on a custom `touchstart` event | ||
// outside of the autocomplete elements. | ||
// This ensures a working experience on mobile because we blur the input | ||
// on touch devices when the user starts scrolling (`touchmove`). | ||
// @TODO: support cases where there are multiple Autocomplete instances. | ||
function onMouseDownOrTouchStart(event) { | ||
// The `onTouchStart`/`onMouseDown` events shouldn't trigger the `blur` | ||
// handler when it's not an interaction with Autocomplete. | ||
// We detect it with the following heuristics: | ||
// - the panel is closed AND there are no pending requests | ||
// (no interaction with the autocomplete, no future state updates) | ||
// - OR the touched target is the input element (should open the panel) | ||
var isAutocompleteInteraction = store.getState().isOpen || !store.pendingRequests.isEmpty(); | ||
if (!isAutocompleteInteraction || event.target === inputElement) { | ||
return; | ||
} // @TODO: support cases where there are multiple Autocomplete instances. | ||
// Right now, a second instance makes this computation return false. | ||
onTouchStart: function onTouchStart(event) { | ||
// The `onTouchStart` event shouldn't trigger the `blur` handler when | ||
// it's not an interaction with Autocomplete. We detect it with the | ||
// following heuristics: | ||
// - the panel is closed AND there are no pending requests | ||
// (no interaction with the autocomplete, no future state updates) | ||
// - OR the touched target is the input element (should open the panel) | ||
var isAutocompleteInteraction = store.getState().isOpen || !store.pendingRequests.isEmpty(); | ||
if (!isAutocompleteInteraction || event.target === inputElement) { | ||
return; | ||
} | ||
var isTargetWithinAutocomplete = [formElement, panelElement].some(function (contextNode) { | ||
return isOrContainsNode(contextNode, event.target); | ||
}); | ||
var isTargetWithinAutocomplete = [formElement, panelElement].some(function (contextNode) { | ||
return isOrContainsNode(contextNode, event.target); | ||
}); | ||
if (isTargetWithinAutocomplete === false) { | ||
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they | ||
// could reopen the panel once they resolve. | ||
// We want to prevent any subsequent query from reopening the panel | ||
// because it would result in an unsolicited UI behavior. | ||
if (isTargetWithinAutocomplete === false) { | ||
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they | ||
// could reopen the panel once they resolve. | ||
// We want to prevent any subsequent query from reopening the panel | ||
// because it would result in an unsolicited UI behavior. | ||
if (!props.debug) { | ||
store.pendingRequests.cancelAll(); | ||
} | ||
if (!props.debug) { | ||
store.pendingRequests.cancelAll(); | ||
} | ||
}, | ||
} | ||
} | ||
return _objectSpread2({ | ||
// We do not rely on the native `blur` event of the input to close the | ||
// panel, but rather on a custom `touchstart`/`mousedown` event outside | ||
// of the autocomplete elements. | ||
// This ensures we don't mistakenly interpret interactions within the | ||
// autocomplete (but outside of the input) as a signal to close the panel. | ||
// For example, clicking reset button causes an input blur, but if | ||
// `openOnFocus=true`, it shouldn't close the panel. | ||
// On touch devices, scrolling results (`touchmove`) causes an input blur | ||
// but shouldn't close the panel. | ||
onTouchStart: onMouseDownOrTouchStart, | ||
onMouseDown: onMouseDownOrTouchStart, | ||
// When scrolling on touch devices (mobiles, tablets, etc.), we want to | ||
@@ -1370,4 +1392,2 @@ // mimic the native platform behavior where the input is blurred to | ||
var isTouchDevice = ('ontouchstart' in props.environment); | ||
var _ref2 = providedProps || {}; | ||
@@ -1417,16 +1437,6 @@ _ref2.inputElement; | ||
onFocus: onFocus, | ||
onBlur: function onBlur() { | ||
// We do rely on the `blur` event on touch devices. | ||
// See explanation in `onTouchStart`. | ||
if (!isTouchDevice) { | ||
store.dispatch('blur', null); // If requests are still pending when the user closes the panel, they | ||
// could reopen the panel once they resolve. | ||
// We want to prevent any subsequent query from reopening the panel | ||
// because it would result in an unsolicited UI behavior. | ||
if (!props.debug) { | ||
store.pendingRequests.cancelAll(); | ||
} | ||
} | ||
}, | ||
// We don't rely on the `blur` event. | ||
// See explanation in `onTouchStart`/`onMouseDown`. | ||
// @MAJOR See if we need to keep this handler. | ||
onBlur: noop, | ||
onClick: function onClick(event) { | ||
@@ -1433,0 +1443,0 @@ // When the panel is closed and you click on the input while |
@@ -1,3 +0,3 @@ | ||
/*! @algolia/autocomplete-core 1.6.3 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/autocomplete-core"]={})}(this,(function(e){"use strict";function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function n(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function i(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(e){return e.reduce((function(e,t){return e.concat(t)}),[])}var c=0;function l(e){return 0===e.collections.length?0:e.collections.reduce((function(e,t){return e+t.items.length}),0)}var s=function(){},f=[{segment:"autocomplete-core",version:"1.6.3"}];function p(e,t){var n=t;return{then:function(t,r){return p(e.then(d(t,n,e),d(r,n,e)),n)},catch:function(t){return p(e.catch(d(t,n,e)),n)},finally:function(t){return t&&n.onCancelList.push(t),p(e.finally(d(t&&function(){return n.onCancelList=[],t()},n,e)),n)},cancel:function(){n.isCanceled=!0;var e=n.onCancelList;n.onCancelList=[],e.forEach((function(e){e()}))},isCanceled:function(){return!0===n.isCanceled}}}function m(e){return p(e,{isCanceled:!1,onCancelList:[]})}function d(e,t,n){return e?function(n){return t.isCanceled?n:e(n)}:n}function v(e,t,n,r){if(!n)return null;if(e<0&&(null===t||null!==r&&0===t))return n+e;var o=(null===t?-1:t)+e;return o<=-1||o>=n?null===r?null:0:o}function g(e){var t=function(e){var t=e.collections.map((function(e){return e.items.length})).reduce((function(e,t,n){var r=(e[n-1]||0)+t;return e.push(r),e}),[]).reduce((function(t,n){return n<=e.activeItemId?t+1:t}),0);return e.collections[t]}(e);if(!t)return null;var n=t.items[function(e){for(var t=e.state,n=e.collection,r=!1,o=0,i=0;!1===r;){var u=t.collections[o];if(u===n){r=!0;break}i+=u.items.length,o++}return t.activeItemId-i}({state:e,collection:t})],r=t.source;return{item:n,itemInputValue:r.getItemInputValue({item:n,state:e}),itemUrl:r.getItemUrl({item:n,state:e}),source:r}}var h=/((gt|sm)-|galaxy nexus)|samsung[- ]/i;function I(e,t){var r,o="undefined"!=typeof window?window:{},u=e.plugins||[];return n(n({debug:!1,openOnFocus:!1,placeholder:"",autoFocus:!1,defaultActiveItemId:null,stallThreshold:300,environment:o,shouldPanelOpen:function(e){return l(e.state)>0},reshape:function(e){return e.sources}},e),{},{id:null!==(r=e.id)&&void 0!==r?r:"autocomplete-".concat(c++),plugins:u,initialState:n({activeItemId:null,query:"",completion:null,collections:[],isOpen:!1,status:"idle",context:{}},e.initialState),onStateChange:function(t){var n;null===(n=e.onStateChange)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onStateChange)||void 0===n?void 0:n.call(e,t)}))},onSubmit:function(t){var n;null===(n=e.onSubmit)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onSubmit)||void 0===n?void 0:n.call(e,t)}))},onReset:function(t){var n;null===(n=e.onReset)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onReset)||void 0===n?void 0:n.call(e,t)}))},getSources:function(r){return Promise.all([].concat(i(u.map((function(e){return e.getSources}))),[e.getSources]).filter(Boolean).map((function(e){return function(e,t){var r=[];return Promise.resolve(e(t)).then((function(e){return Promise.all(e.filter((function(e){return Boolean(e)})).map((function(e){if(e.sourceId,r.includes(e.sourceId))throw new Error("[Autocomplete] The `sourceId` ".concat(JSON.stringify(e.sourceId)," is not unique."));r.push(e.sourceId);var t=n({getItemInputValue:function(e){return e.state.query},getItemUrl:function(){},onSelect:function(e){(0,e.setIsOpen)(!1)},onActive:s},e);return Promise.resolve(t)})))}))}(e,r)}))).then((function(e){return a(e)})).then((function(e){return e.map((function(e){return n(n({},e),{},{onSelect:function(n){e.onSelect(n),t.forEach((function(e){var t;return null===(t=e.onSelect)||void 0===t?void 0:t.call(e,n)}))},onActive:function(n){e.onActive(n),t.forEach((function(e){var t;return null===(t=e.onActive)||void 0===t?void 0:t.call(e,n)}))}})}))}))},navigator:n({navigate:function(e){var t=e.itemUrl;o.location.assign(t)},navigateNewTab:function(e){var t=e.itemUrl,n=o.open(t,"_blank","noopener");null==n||n.focus()},navigateNewWindow:function(e){var t=e.itemUrl;o.open(t,"_blank","noopener")}},e.navigator)})}function y(e){return Boolean(e.execute)}function S(e,t){return r=e,Boolean(null==r?void 0:r.execute)?n(n({},e),{},{requests:e.queries.map((function(n){return{query:n,sourceId:t,transformResponse:e.transformResponse}}))}):{items:e,sourceId:t};var r}function b(e){var t=e.reduce((function(e,t){if(!y(t))return e.push(t),e;var n=t.searchClient,r=t.execute,o=t.requesterId,u=t.requests,a=e.find((function(e){return y(t)&&y(e)&&e.searchClient===n&&Boolean(o)&&e.requesterId===o}));if(a){var c;(c=a.items).push.apply(c,i(u))}else{var l={execute:r,requesterId:o,items:u,searchClient:n};e.push(l)}return e}),[]).map((function(e){if(!y(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 O(e,t){return t.map((function(t){var r=e.filter((function(e){return e.sourceId===t.sourceId})),o=r.map((function(e){return e.items})),i=r[0].transformResponse,u=i?i(function(e){var t=e.map((function(e){var t;return n(n({},e),{},{hits:null===(t=e.hits)||void 0===t?void 0:t.map((function(t){return n(n({},t),{},{__autocomplete_indexName:e.index,__autocomplete_queryID:e.queryID})}))})}));return{results:t,hits:t.map((function(e){return e.hits})).filter(Boolean),facetHits:t.map((function(e){var t;return null===(t=e.facetHits)||void 0===t?void 0:t.map((function(e){return{label:e.value,count:e.count,_highlightResult:{label:{value:e.highlighted}}}}))})).filter(Boolean)}}(o)):o;return u.every(Boolean),'The `getItems` function from source "'.concat(t.sourceId,'" must return an array of items but returned ').concat(JSON.stringify(void 0),".\n\nDid you forget to return items?\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"),{source:t,items:u}}))}var A,w,q,P=["event","nextState","props","query","refresh","store"],_=null,E=(A=-1,w=-1,q=void 0,function(e){var t=++A;return Promise.resolve(e).then((function(e){return q&&t<w?q:(w=t,q=e,e)}))});function C(e){var t=e.event,i=e.nextState,u=void 0===i?{}:i,c=e.props,l=e.query,s=e.refresh,f=e.store,p=o(e,P);_&&c.environment.clearTimeout(_);var d=p.setCollections,v=p.setIsOpen,h=p.setQuery,I=p.setActiveItemId,y=p.setStatus;if(h(l),I(c.defaultActiveItemId),!l&&!1===c.openOnFocus){var A,w=f.getState().collections.map((function(e){return n(n({},e),{},{items:[]})}));y("idle"),d(w),v(null!==(A=u.isOpen)&&void 0!==A?A:c.shouldPanelOpen({state:f.getState()}));var q=m(E(w).then((function(){return Promise.resolve()})));return f.pendingRequests.add(q)}y("loading"),_=c.environment.setTimeout((function(){y("stalled")}),c.stallThreshold);var C=m(E(c.getSources(n({query:l,refresh:s,state:f.getState()},p)).then((function(e){return Promise.all(e.map((function(e){return Promise.resolve(e.getItems(n({query:l,refresh:s,state:f.getState()},p))).then((function(t){return S(t,e.sourceId)}))}))).then(b).then((function(t){return O(t,e)})).then((function(e){return function(e){var t=e.collections,o=e.props,i=e.state,u=t.reduce((function(e,t){return n(n({},e),{},r({},t.source.sourceId,n(n({},t.source),{},{getItems:function(){return a(t.items)}})))}),{});return a(o.reshape({sources:Object.values(u),sourcesBySourceId:u,state:i})).filter(Boolean).map((function(e){return{source:e,items:e.getItems()}}))}({collections:e,props:c,state:f.getState()})}))})))).then((function(e){var r;y("idle"),d(e);var o=c.shouldPanelOpen({state:f.getState()});v(null!==(r=u.isOpen)&&void 0!==r?r:c.openOnFocus&&!l&&o||o);var i=g(f.getState());if(null!==f.getState().activeItemId&&i){var a=i.item,m=i.itemInputValue,h=i.itemUrl,I=i.source;I.onActive(n({event:t,item:a,itemInputValue:m,itemUrl:h,refresh:s,source:I,state:f.getState()},p))}})).finally((function(){y("idle"),_&&c.environment.clearTimeout(_)}));return f.pendingRequests.add(C)}var x=["event","props","refresh","store"];var U=["props","refresh","store"],j=["inputElement","formElement","panelElement"],V=["inputElement"],D=["inputElement","maxLength"],k=["item","source"];function T(e){var t=e.props,r=e.refresh,i=e.store,u=o(e,U);return{getEnvironmentProps:function(e){var r=e.inputElement,u=e.formElement,a=e.panelElement;return n({onTouchStart:function(e){!i.getState().isOpen&&i.pendingRequests.isEmpty()||e.target===r||!1===[u,a].some((function(t){return n=t,r=e.target,n===r||n.contains(r);var n,r}))&&(i.dispatch("blur",null),t.debug||i.pendingRequests.cancelAll())},onTouchMove:function(e){!1!==i.getState().isOpen&&r===t.environment.document.activeElement&&e.target!==r&&r.blur()}},o(e,j))},getRootProps:function(e){return n({role:"combobox","aria-expanded":i.getState().isOpen,"aria-haspopup":"listbox","aria-owns":i.getState().isOpen?"".concat(t.id,"-list"):void 0,"aria-labelledby":"".concat(t.id,"-label")},e)},getFormProps:function(e){return e.inputElement,n({action:"",noValidate:!0,role:"search",onSubmit:function(o){var a;o.preventDefault(),t.onSubmit(n({event:o,refresh:r,state:i.getState()},u)),i.dispatch("submit",null),null===(a=e.inputElement)||void 0===a||a.blur()},onReset:function(o){var a;o.preventDefault(),t.onReset(n({event:o,refresh:r,state:i.getState()},u)),i.dispatch("reset",null),null===(a=e.inputElement)||void 0===a||a.focus()}},o(e,V))},getLabelProps:function(e){return n({htmlFor:"".concat(t.id,"-input"),id:"".concat(t.id,"-label")},e)},getInputProps:function(e){var a;function c(e){(t.openOnFocus||Boolean(i.getState().query))&&C(n({event:e,props:t,query:i.getState().completion||i.getState().query,refresh:r,store:i},u)),i.dispatch("focus",null)}var l="ontouchstart"in t.environment,s=e||{};s.inputElement;var f=s.maxLength,p=void 0===f?512:f,m=o(s,D),d=g(i.getState()),v=function(e){return Boolean(e&&e.match(h))}(null===(a=t.environment.navigator)||void 0===a?void 0:a.userAgent),I=null!=d&&d.itemUrl&&!v?"go":"search";return n({"aria-autocomplete":"both","aria-activedescendant":i.getState().isOpen&&null!==i.getState().activeItemId?"".concat(t.id,"-item-").concat(i.getState().activeItemId):void 0,"aria-controls":i.getState().isOpen?"".concat(t.id,"-list"):void 0,"aria-labelledby":"".concat(t.id,"-label"),value:i.getState().completion||i.getState().query,id:"".concat(t.id,"-input"),autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",enterKeyHint:I,spellCheck:"false",autoFocus:t.autoFocus,placeholder:t.placeholder,maxLength:p,type:"search",onChange:function(e){C(n({event:e,props:t,query:e.currentTarget.value.slice(0,p),refresh:r,store:i},u))},onKeyDown:function(e){!function(e){var t=e.event,r=e.props,i=e.refresh,u=e.store,a=o(e,x);if("ArrowUp"===t.key||"ArrowDown"===t.key){var c=function(){var e=r.environment.document.getElementById("".concat(r.id,"-item-").concat(u.getState().activeItemId));e&&(e.scrollIntoViewIfNeeded?e.scrollIntoViewIfNeeded(!1):e.scrollIntoView(!1))},l=function(){var e=g(u.getState());if(null!==u.getState().activeItemId&&e){var r=e.item,o=e.itemInputValue,c=e.itemUrl,l=e.source;l.onActive(n({event:t,item:r,itemInputValue:o,itemUrl:c,refresh:i,source:l,state:u.getState()},a))}};t.preventDefault(),!1===u.getState().isOpen&&(r.openOnFocus||Boolean(u.getState().query))?C(n({event:t,props:r,query:u.getState().query,refresh:i,store:u},a)).then((function(){u.dispatch(t.key,{nextActiveItemId:r.defaultActiveItemId}),l(),setTimeout(c,0)})):(u.dispatch(t.key,{}),l(),c())}else if("Escape"===t.key)t.preventDefault(),u.dispatch(t.key,null),u.pendingRequests.cancelAll();else if("Enter"===t.key){if(null===u.getState().activeItemId||u.getState().collections.every((function(e){return 0===e.items.length})))return;t.preventDefault();var s=g(u.getState()),f=s.item,p=s.itemInputValue,m=s.itemUrl,d=s.source;if(t.metaKey||t.ctrlKey)void 0!==m&&(d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),r.navigator.navigateNewTab({itemUrl:m,item:f,state:u.getState()}));else if(t.shiftKey)void 0!==m&&(d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),r.navigator.navigateNewWindow({itemUrl:m,item:f,state:u.getState()}));else if(t.altKey);else{if(void 0!==m)return d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),void r.navigator.navigate({itemUrl:m,item:f,state:u.getState()});C(n({event:t,nextState:{isOpen:!1},props:r,query:p,refresh:i,store:u},a)).then((function(){d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a))}))}}}(n({event:e,props:t,refresh:r,store:i},u))},onFocus:c,onBlur:function(){l||(i.dispatch("blur",null),t.debug||i.pendingRequests.cancelAll())},onClick:function(n){e.inputElement!==t.environment.document.activeElement||i.getState().isOpen||c(n)}},m)},getPanelProps:function(e){return n({onMouseDown:function(e){e.preventDefault()},onMouseLeave:function(){i.dispatch("mouseleave",null)}},e)},getListProps:function(e){return n({role:"listbox","aria-labelledby":"".concat(t.id,"-label"),id:"".concat(t.id,"-list")},e)},getItemProps:function(e){var a=e.item,c=e.source,l=o(e,k);return n({id:"".concat(t.id,"-item-").concat(a.__autocomplete_id),role:"option","aria-selected":i.getState().activeItemId===a.__autocomplete_id,onMouseMove:function(e){if(a.__autocomplete_id!==i.getState().activeItemId){i.dispatch("mousemove",a.__autocomplete_id);var t=g(i.getState());if(null!==i.getState().activeItemId&&t){var o=t.item,c=t.itemInputValue,l=t.itemUrl,s=t.source;s.onActive(n({event:e,item:o,itemInputValue:c,itemUrl:l,refresh:r,source:s,state:i.getState()},u))}}},onMouseDown:function(e){e.preventDefault()},onClick:function(e){var o=c.getItemInputValue({item:a,state:i.getState()}),l=c.getItemUrl({item:a,state:i.getState()});(l?Promise.resolve():C(n({event:e,nextState:{isOpen:!1},props:t,query:o,refresh:r,store:i},u))).then((function(){c.onSelect(n({event:e,item:a,itemInputValue:o,itemUrl:l,refresh:r,source:c,state:i.getState()},u))}))}},l)}}}function R(e){var t,o,i,u,a=e.plugins,c=e.options,l=null===(t=((null===(o=c.__autocomplete_metadata)||void 0===o?void 0:o.userAgents)||[])[0])||void 0===t?void 0:t.segment,s=l?r({},l,Object.keys((null===(i=c.__autocomplete_metadata)||void 0===i?void 0:i.options)||{})):{};return{plugins:a.map((function(e){return{name:e.name,options:Object.keys(e.__autocomplete_pluginOptions||[])}})),options:n({"autocomplete-core":Object.keys(c)},s),ua:f.concat((null===(u=c.__autocomplete_metadata)||void 0===u?void 0:u.userAgents)||[])}}function B(e){var t,n=e.state;return!1===n.isOpen||null===n.activeItemId?null:(null===(t=g(n))||void 0===t?void 0:t.itemInputValue)||null}var F=function(e,t){switch(t.type){case"setActiveItemId":case"mousemove":return n(n({},e),{},{activeItemId:t.payload});case"setQuery":return n(n({},e),{},{query:t.payload,completion:null});case"setCollections":return n(n({},e),{},{collections:t.payload});case"setIsOpen":return n(n({},e),{},{isOpen:t.payload});case"setStatus":return n(n({},e),{},{status:t.payload});case"setContext":return n(n({},e),{},{context:n(n({},e.context),t.payload)});case"ArrowDown":var r=n(n({},e),{},{activeItemId:t.payload.hasOwnProperty("nextActiveItemId")?t.payload.nextActiveItemId:v(1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},r),{},{completion:B({state:r})});case"ArrowUp":var o=n(n({},e),{},{activeItemId:v(-1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},o),{},{completion:B({state:o})});case"Escape":return e.isOpen?n(n({},e),{},{activeItemId:null,isOpen:!1,completion:null}):n(n({},e),{},{activeItemId:null,query:"",status:"idle",collections:[]});case"submit":return n(n({},e),{},{activeItemId:null,isOpen:!1,status:"idle"});case"reset":return n(n({},e),{},{activeItemId:!0===t.props.openOnFocus?t.props.defaultActiveItemId:null,status:"idle",query:""});case"focus":return n(n({},e),{},{activeItemId:t.props.defaultActiveItemId,isOpen:(t.props.openOnFocus||Boolean(e.query))&&t.props.shouldPanelOpen({state:e})});case"blur":return t.props.debug?e:n(n({},e),{},{isOpen:!1,activeItemId:null});case"mouseleave":return n(n({},e),{},{activeItemId:t.props.defaultActiveItemId});default:return"The reducer action ".concat(JSON.stringify(t.type)," is not supported."),e}};e.createAutocomplete=function(e){var t=[],r=I(e,t),o=function(e,t,r){var o,i=t.initialState;return{getState:function(){return i},dispatch:function(o,u){var a=n({},i);i=e(i,{type:o,props:t,payload:u}),r({state:i,prevState:a})},pendingRequests:(o=[],{add:function(e){return o.push(e),e.finally((function(){o=o.filter((function(t){return t!==e}))}))},cancelAll:function(){o.forEach((function(e){return e.cancel()}))},isEmpty:function(){return 0===o.length}})}}(F,r,(function(e){var t=e.prevState,o=e.state;r.onStateChange(n({prevState:t,state:o,refresh:c},i))})),i=function(e){var t=e.store;return{setActiveItemId:function(e){t.dispatch("setActiveItemId",e)},setQuery:function(e){t.dispatch("setQuery",e)},setCollections:function(e){var r=0,o=e.map((function(e){return n(n({},e),{},{items:a(e.items).map((function(e){return n(n({},e),{},{__autocomplete_id:r++})}))})}));t.dispatch("setCollections",o)},setIsOpen:function(e){t.dispatch("setIsOpen",e)},setStatus:function(e){t.dispatch("setStatus",e)},setContext:function(e){t.dispatch("setContext",e)}}}({store:o}),u=T(n({props:r,refresh:c,store:o},i));function c(){return C(n({event:new Event("input"),nextState:{isOpen:o.getState().isOpen},props:r,query:o.getState().query,refresh:c,store:o},i))}return r.plugins.forEach((function(e){var r;return null===(r=e.subscribe)||void 0===r?void 0:r.call(e,n(n({},i),{},{refresh:c,onSelect:function(e){t.push({onSelect:e})},onActive:function(e){t.push({onActive:e})}}))})),function(e){var t,n=e.metadata,r=e.environment;if(null===(t=r.navigator)||void 0===t?void 0:t.userAgent.includes("Algolia Crawler")){var o=r.document.createElement("meta"),i=r.document.querySelector("head");o.name="algolia:metadata",setTimeout((function(){o.content=JSON.stringify(n),i.appendChild(o)}),0)}}({metadata:R({plugins:r.plugins,options:e}),environment:r.environment}),n(n({refresh:c},u),i)},e.getDefaultProps=I,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
/*! @algolia/autocomplete-core 1.7.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/autocomplete-core"]={})}(this,(function(e){"use strict";function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function n(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function i(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(e){return e.reduce((function(e,t){return e.concat(t)}),[])}var c=0;function l(e){return 0===e.collections.length?0:e.collections.reduce((function(e,t){return e+t.items.length}),0)}var s=function(){},f=[{segment:"autocomplete-core",version:"1.7.0"}];function p(e,t){var n=t;return{then:function(t,r){return p(e.then(d(t,n,e),d(r,n,e)),n)},catch:function(t){return p(e.catch(d(t,n,e)),n)},finally:function(t){return t&&n.onCancelList.push(t),p(e.finally(d(t&&function(){return n.onCancelList=[],t()},n,e)),n)},cancel:function(){n.isCanceled=!0;var e=n.onCancelList;n.onCancelList=[],e.forEach((function(e){e()}))},isCanceled:function(){return!0===n.isCanceled}}}function m(e){return p(e,{isCanceled:!1,onCancelList:[]})}function d(e,t,n){return e?function(n){return t.isCanceled?n:e(n)}:n}function v(e,t,n,r){if(!n)return null;if(e<0&&(null===t||null!==r&&0===t))return n+e;var o=(null===t?-1:t)+e;return o<=-1||o>=n?null===r?null:0:o}function g(e){var t=function(e){var t=e.collections.map((function(e){return e.items.length})).reduce((function(e,t,n){var r=(e[n-1]||0)+t;return e.push(r),e}),[]).reduce((function(t,n){return n<=e.activeItemId?t+1:t}),0);return e.collections[t]}(e);if(!t)return null;var n=t.items[function(e){for(var t=e.state,n=e.collection,r=!1,o=0,i=0;!1===r;){var u=t.collections[o];if(u===n){r=!0;break}i+=u.items.length,o++}return t.activeItemId-i}({state:e,collection:t})],r=t.source;return{item:n,itemInputValue:r.getItemInputValue({item:n,state:e}),itemUrl:r.getItemUrl({item:n,state:e}),source:r}}var h=/((gt|sm)-|galaxy nexus)|samsung[- ]/i;function I(e,t){var r,o="undefined"!=typeof window?window:{},u=e.plugins||[];return n(n({debug:!1,openOnFocus:!1,placeholder:"",autoFocus:!1,defaultActiveItemId:null,stallThreshold:300,environment:o,shouldPanelOpen:function(e){return l(e.state)>0},reshape:function(e){return e.sources}},e),{},{id:null!==(r=e.id)&&void 0!==r?r:"autocomplete-".concat(c++),plugins:u,initialState:n({activeItemId:null,query:"",completion:null,collections:[],isOpen:!1,status:"idle",context:{}},e.initialState),onStateChange:function(t){var n;null===(n=e.onStateChange)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onStateChange)||void 0===n?void 0:n.call(e,t)}))},onSubmit:function(t){var n;null===(n=e.onSubmit)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onSubmit)||void 0===n?void 0:n.call(e,t)}))},onReset:function(t){var n;null===(n=e.onReset)||void 0===n||n.call(e,t),u.forEach((function(e){var n;return null===(n=e.onReset)||void 0===n?void 0:n.call(e,t)}))},getSources:function(r){return Promise.all([].concat(i(u.map((function(e){return e.getSources}))),[e.getSources]).filter(Boolean).map((function(e){return function(e,t){var r=[];return Promise.resolve(e(t)).then((function(e){return Promise.all(e.filter((function(e){return Boolean(e)})).map((function(e){if(e.sourceId,r.includes(e.sourceId))throw new Error("[Autocomplete] The `sourceId` ".concat(JSON.stringify(e.sourceId)," is not unique."));r.push(e.sourceId);var t=n({getItemInputValue:function(e){return e.state.query},getItemUrl:function(){},onSelect:function(e){(0,e.setIsOpen)(!1)},onActive:s},e);return Promise.resolve(t)})))}))}(e,r)}))).then((function(e){return a(e)})).then((function(e){return e.map((function(e){return n(n({},e),{},{onSelect:function(n){e.onSelect(n),t.forEach((function(e){var t;return null===(t=e.onSelect)||void 0===t?void 0:t.call(e,n)}))},onActive:function(n){e.onActive(n),t.forEach((function(e){var t;return null===(t=e.onActive)||void 0===t?void 0:t.call(e,n)}))}})}))}))},navigator:n({navigate:function(e){var t=e.itemUrl;o.location.assign(t)},navigateNewTab:function(e){var t=e.itemUrl,n=o.open(t,"_blank","noopener");null==n||n.focus()},navigateNewWindow:function(e){var t=e.itemUrl;o.open(t,"_blank","noopener")}},e.navigator)})}function y(e){return Boolean(e.execute)}function S(e,t){return r=e,Boolean(null==r?void 0:r.execute)?n(n({},e),{},{requests:e.queries.map((function(n){return{query:n,sourceId:t,transformResponse:e.transformResponse}}))}):{items:e,sourceId:t};var r}function b(e){var t=e.reduce((function(e,t){if(!y(t))return e.push(t),e;var n=t.searchClient,r=t.execute,o=t.requesterId,u=t.requests,a=e.find((function(e){return y(t)&&y(e)&&e.searchClient===n&&Boolean(o)&&e.requesterId===o}));if(a){var c;(c=a.items).push.apply(c,i(u))}else{var l={execute:r,requesterId:o,items:u,searchClient:n};e.push(l)}return e}),[]).map((function(e){if(!y(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 O(e,t){return t.map((function(t){var r=e.filter((function(e){return e.sourceId===t.sourceId})),o=r.map((function(e){return e.items})),i=r[0].transformResponse,u=i?i(function(e){var t=e.map((function(e){var t;return n(n({},e),{},{hits:null===(t=e.hits)||void 0===t?void 0:t.map((function(t){return n(n({},t),{},{__autocomplete_indexName:e.index,__autocomplete_queryID:e.queryID})}))})}));return{results:t,hits:t.map((function(e){return e.hits})).filter(Boolean),facetHits:t.map((function(e){var t;return null===(t=e.facetHits)||void 0===t?void 0:t.map((function(e){return{label:e.value,count:e.count,_highlightResult:{label:{value:e.highlighted}}}}))})).filter(Boolean)}}(o)):o;return u.every(Boolean),'The `getItems` function from source "'.concat(t.sourceId,'" must return an array of items but returned ').concat(JSON.stringify(void 0),".\n\nDid you forget to return items?\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"),{source:t,items:u}}))}var A,w,q,P=["event","nextState","props","query","refresh","store"],_=null,E=(A=-1,w=-1,q=void 0,function(e){var t=++A;return Promise.resolve(e).then((function(e){return q&&t<w?q:(w=t,q=e,e)}))});function C(e){var t=e.event,i=e.nextState,u=void 0===i?{}:i,c=e.props,l=e.query,s=e.refresh,f=e.store,p=o(e,P);_&&c.environment.clearTimeout(_);var d=p.setCollections,v=p.setIsOpen,h=p.setQuery,I=p.setActiveItemId,y=p.setStatus;if(h(l),I(c.defaultActiveItemId),!l&&!1===c.openOnFocus){var A,w=f.getState().collections.map((function(e){return n(n({},e),{},{items:[]})}));y("idle"),d(w),v(null!==(A=u.isOpen)&&void 0!==A?A:c.shouldPanelOpen({state:f.getState()}));var q=m(E(w).then((function(){return Promise.resolve()})));return f.pendingRequests.add(q)}y("loading"),_=c.environment.setTimeout((function(){y("stalled")}),c.stallThreshold);var C=m(E(c.getSources(n({query:l,refresh:s,state:f.getState()},p)).then((function(e){return Promise.all(e.map((function(e){return Promise.resolve(e.getItems(n({query:l,refresh:s,state:f.getState()},p))).then((function(t){return S(t,e.sourceId)}))}))).then(b).then((function(t){return O(t,e)})).then((function(e){return function(e){var t=e.collections,o=e.props,i=e.state,u=t.reduce((function(e,t){return n(n({},e),{},r({},t.source.sourceId,n(n({},t.source),{},{getItems:function(){return a(t.items)}})))}),{});return a(o.reshape({sources:Object.values(u),sourcesBySourceId:u,state:i})).filter(Boolean).map((function(e){return{source:e,items:e.getItems()}}))}({collections:e,props:c,state:f.getState()})}))})))).then((function(e){var r;y("idle"),d(e);var o=c.shouldPanelOpen({state:f.getState()});v(null!==(r=u.isOpen)&&void 0!==r?r:c.openOnFocus&&!l&&o||o);var i=g(f.getState());if(null!==f.getState().activeItemId&&i){var a=i.item,m=i.itemInputValue,h=i.itemUrl,I=i.source;I.onActive(n({event:t,item:a,itemInputValue:m,itemUrl:h,refresh:s,source:I,state:f.getState()},p))}})).finally((function(){y("idle"),_&&c.environment.clearTimeout(_)}));return f.pendingRequests.add(C)}var x=["event","props","refresh","store"];var U=["props","refresh","store"],j=["inputElement","formElement","panelElement"],D=["inputElement"],V=["inputElement","maxLength"],k=["item","source"];function T(e){var t=e.props,r=e.refresh,i=e.store,u=o(e,U);return{getEnvironmentProps:function(e){var r=e.inputElement,u=e.formElement,a=e.panelElement;function c(e){!i.getState().isOpen&&i.pendingRequests.isEmpty()||e.target===r||!1===[u,a].some((function(t){return n=t,r=e.target,n===r||n.contains(r);var n,r}))&&(i.dispatch("blur",null),t.debug||i.pendingRequests.cancelAll())}return n({onTouchStart:c,onMouseDown:c,onTouchMove:function(e){!1!==i.getState().isOpen&&r===t.environment.document.activeElement&&e.target!==r&&r.blur()}},o(e,j))},getRootProps:function(e){return n({role:"combobox","aria-expanded":i.getState().isOpen,"aria-haspopup":"listbox","aria-owns":i.getState().isOpen?"".concat(t.id,"-list"):void 0,"aria-labelledby":"".concat(t.id,"-label")},e)},getFormProps:function(e){return e.inputElement,n({action:"",noValidate:!0,role:"search",onSubmit:function(o){var a;o.preventDefault(),t.onSubmit(n({event:o,refresh:r,state:i.getState()},u)),i.dispatch("submit",null),null===(a=e.inputElement)||void 0===a||a.blur()},onReset:function(o){var a;o.preventDefault(),t.onReset(n({event:o,refresh:r,state:i.getState()},u)),i.dispatch("reset",null),null===(a=e.inputElement)||void 0===a||a.focus()}},o(e,D))},getLabelProps:function(e){return n({htmlFor:"".concat(t.id,"-input"),id:"".concat(t.id,"-label")},e)},getInputProps:function(e){var a;function c(e){(t.openOnFocus||Boolean(i.getState().query))&&C(n({event:e,props:t,query:i.getState().completion||i.getState().query,refresh:r,store:i},u)),i.dispatch("focus",null)}var l=e||{};l.inputElement;var f=l.maxLength,p=void 0===f?512:f,m=o(l,V),d=g(i.getState()),v=function(e){return Boolean(e&&e.match(h))}(null===(a=t.environment.navigator)||void 0===a?void 0:a.userAgent),I=null!=d&&d.itemUrl&&!v?"go":"search";return n({"aria-autocomplete":"both","aria-activedescendant":i.getState().isOpen&&null!==i.getState().activeItemId?"".concat(t.id,"-item-").concat(i.getState().activeItemId):void 0,"aria-controls":i.getState().isOpen?"".concat(t.id,"-list"):void 0,"aria-labelledby":"".concat(t.id,"-label"),value:i.getState().completion||i.getState().query,id:"".concat(t.id,"-input"),autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",enterKeyHint:I,spellCheck:"false",autoFocus:t.autoFocus,placeholder:t.placeholder,maxLength:p,type:"search",onChange:function(e){C(n({event:e,props:t,query:e.currentTarget.value.slice(0,p),refresh:r,store:i},u))},onKeyDown:function(e){!function(e){var t=e.event,r=e.props,i=e.refresh,u=e.store,a=o(e,x);if("ArrowUp"===t.key||"ArrowDown"===t.key){var c=function(){var e=r.environment.document.getElementById("".concat(r.id,"-item-").concat(u.getState().activeItemId));e&&(e.scrollIntoViewIfNeeded?e.scrollIntoViewIfNeeded(!1):e.scrollIntoView(!1))},l=function(){var e=g(u.getState());if(null!==u.getState().activeItemId&&e){var r=e.item,o=e.itemInputValue,c=e.itemUrl,l=e.source;l.onActive(n({event:t,item:r,itemInputValue:o,itemUrl:c,refresh:i,source:l,state:u.getState()},a))}};t.preventDefault(),!1===u.getState().isOpen&&(r.openOnFocus||Boolean(u.getState().query))?C(n({event:t,props:r,query:u.getState().query,refresh:i,store:u},a)).then((function(){u.dispatch(t.key,{nextActiveItemId:r.defaultActiveItemId}),l(),setTimeout(c,0)})):(u.dispatch(t.key,{}),l(),c())}else if("Escape"===t.key)t.preventDefault(),u.dispatch(t.key,null),u.pendingRequests.cancelAll();else if("Tab"===t.key)u.dispatch("blur",null),u.pendingRequests.cancelAll();else if("Enter"===t.key){if(null===u.getState().activeItemId||u.getState().collections.every((function(e){return 0===e.items.length})))return void(r.debug||u.pendingRequests.cancelAll());t.preventDefault();var s=g(u.getState()),f=s.item,p=s.itemInputValue,m=s.itemUrl,d=s.source;if(t.metaKey||t.ctrlKey)void 0!==m&&(d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),r.navigator.navigateNewTab({itemUrl:m,item:f,state:u.getState()}));else if(t.shiftKey)void 0!==m&&(d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),r.navigator.navigateNewWindow({itemUrl:m,item:f,state:u.getState()}));else if(t.altKey);else{if(void 0!==m)return d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a)),void r.navigator.navigate({itemUrl:m,item:f,state:u.getState()});C(n({event:t,nextState:{isOpen:!1},props:r,query:p,refresh:i,store:u},a)).then((function(){d.onSelect(n({event:t,item:f,itemInputValue:p,itemUrl:m,refresh:i,source:d,state:u.getState()},a))}))}}}(n({event:e,props:t,refresh:r,store:i},u))},onFocus:c,onBlur:s,onClick:function(n){e.inputElement!==t.environment.document.activeElement||i.getState().isOpen||c(n)}},m)},getPanelProps:function(e){return n({onMouseDown:function(e){e.preventDefault()},onMouseLeave:function(){i.dispatch("mouseleave",null)}},e)},getListProps:function(e){return n({role:"listbox","aria-labelledby":"".concat(t.id,"-label"),id:"".concat(t.id,"-list")},e)},getItemProps:function(e){var a=e.item,c=e.source,l=o(e,k);return n({id:"".concat(t.id,"-item-").concat(a.__autocomplete_id),role:"option","aria-selected":i.getState().activeItemId===a.__autocomplete_id,onMouseMove:function(e){if(a.__autocomplete_id!==i.getState().activeItemId){i.dispatch("mousemove",a.__autocomplete_id);var t=g(i.getState());if(null!==i.getState().activeItemId&&t){var o=t.item,c=t.itemInputValue,l=t.itemUrl,s=t.source;s.onActive(n({event:e,item:o,itemInputValue:c,itemUrl:l,refresh:r,source:s,state:i.getState()},u))}}},onMouseDown:function(e){e.preventDefault()},onClick:function(e){var o=c.getItemInputValue({item:a,state:i.getState()}),l=c.getItemUrl({item:a,state:i.getState()});(l?Promise.resolve():C(n({event:e,nextState:{isOpen:!1},props:t,query:o,refresh:r,store:i},u))).then((function(){c.onSelect(n({event:e,item:a,itemInputValue:o,itemUrl:l,refresh:r,source:c,state:i.getState()},u))}))}},l)}}}function R(e){var t,o,i,u,a=e.plugins,c=e.options,l=null===(t=((null===(o=c.__autocomplete_metadata)||void 0===o?void 0:o.userAgents)||[])[0])||void 0===t?void 0:t.segment,s=l?r({},l,Object.keys((null===(i=c.__autocomplete_metadata)||void 0===i?void 0:i.options)||{})):{};return{plugins:a.map((function(e){return{name:e.name,options:Object.keys(e.__autocomplete_pluginOptions||[])}})),options:n({"autocomplete-core":Object.keys(c)},s),ua:f.concat((null===(u=c.__autocomplete_metadata)||void 0===u?void 0:u.userAgents)||[])}}function B(e){var t,n=e.state;return!1===n.isOpen||null===n.activeItemId?null:(null===(t=g(n))||void 0===t?void 0:t.itemInputValue)||null}var F=function(e,t){switch(t.type){case"setActiveItemId":case"mousemove":return n(n({},e),{},{activeItemId:t.payload});case"setQuery":return n(n({},e),{},{query:t.payload,completion:null});case"setCollections":return n(n({},e),{},{collections:t.payload});case"setIsOpen":return n(n({},e),{},{isOpen:t.payload});case"setStatus":return n(n({},e),{},{status:t.payload});case"setContext":return n(n({},e),{},{context:n(n({},e.context),t.payload)});case"ArrowDown":var r=n(n({},e),{},{activeItemId:t.payload.hasOwnProperty("nextActiveItemId")?t.payload.nextActiveItemId:v(1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},r),{},{completion:B({state:r})});case"ArrowUp":var o=n(n({},e),{},{activeItemId:v(-1,e.activeItemId,l(e),t.props.defaultActiveItemId)});return n(n({},o),{},{completion:B({state:o})});case"Escape":return e.isOpen?n(n({},e),{},{activeItemId:null,isOpen:!1,completion:null}):n(n({},e),{},{activeItemId:null,query:"",status:"idle",collections:[]});case"submit":return n(n({},e),{},{activeItemId:null,isOpen:!1,status:"idle"});case"reset":return n(n({},e),{},{activeItemId:!0===t.props.openOnFocus?t.props.defaultActiveItemId:null,status:"idle",query:""});case"focus":return n(n({},e),{},{activeItemId:t.props.defaultActiveItemId,isOpen:(t.props.openOnFocus||Boolean(e.query))&&t.props.shouldPanelOpen({state:e})});case"blur":return t.props.debug?e:n(n({},e),{},{isOpen:!1,activeItemId:null});case"mouseleave":return n(n({},e),{},{activeItemId:t.props.defaultActiveItemId});default:return"The reducer action ".concat(JSON.stringify(t.type)," is not supported."),e}};e.createAutocomplete=function(e){var t=[],r=I(e,t),o=function(e,t,r){var o,i=t.initialState;return{getState:function(){return i},dispatch:function(o,u){var a=n({},i);i=e(i,{type:o,props:t,payload:u}),r({state:i,prevState:a})},pendingRequests:(o=[],{add:function(e){return o.push(e),e.finally((function(){o=o.filter((function(t){return t!==e}))}))},cancelAll:function(){o.forEach((function(e){return e.cancel()}))},isEmpty:function(){return 0===o.length}})}}(F,r,(function(e){var t=e.prevState,o=e.state;r.onStateChange(n({prevState:t,state:o,refresh:c},i))})),i=function(e){var t=e.store;return{setActiveItemId:function(e){t.dispatch("setActiveItemId",e)},setQuery:function(e){t.dispatch("setQuery",e)},setCollections:function(e){var r=0,o=e.map((function(e){return n(n({},e),{},{items:a(e.items).map((function(e){return n(n({},e),{},{__autocomplete_id:r++})}))})}));t.dispatch("setCollections",o)},setIsOpen:function(e){t.dispatch("setIsOpen",e)},setStatus:function(e){t.dispatch("setStatus",e)},setContext:function(e){t.dispatch("setContext",e)}}}({store:o}),u=T(n({props:r,refresh:c,store:o},i));function c(){return C(n({event:new Event("input"),nextState:{isOpen:o.getState().isOpen},props:r,query:o.getState().query,refresh:c,store:o},i))}return r.plugins.forEach((function(e){var r;return null===(r=e.subscribe)||void 0===r?void 0:r.call(e,n(n({},i),{},{refresh:c,onSelect:function(e){t.push({onSelect:e})},onActive:function(e){t.push({onActive:e})}}))})),function(e){var t,n=e.metadata,r=e.environment;if(null===(t=r.navigator)||void 0===t?void 0:t.userAgent.includes("Algolia Crawler")){var o=r.document.createElement("meta"),i=r.document.querySelector("head");o.name="algolia:metadata",setTimeout((function(){o.content=JSON.stringify(n),i.appendChild(o)}),0)}}({metadata:R({plugins:r.plugins,options:e}),environment:r.environment}),n(n({refresh:c},u),i)},e.getDefaultProps=I,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@algolia/autocomplete-core", | ||
"description": "Core primitives for building autocomplete experiences.", | ||
"version": "1.6.3", | ||
"version": "1.7.0", | ||
"license": "MIT", | ||
@@ -34,6 +34,6 @@ "homepage": "https://github.com/algolia/autocomplete", | ||
"dependencies": { | ||
"@algolia/autocomplete-shared": "1.6.3" | ||
"@algolia/autocomplete-shared": "1.7.0" | ||
}, | ||
"devDependencies": { | ||
"@algolia/autocomplete-preset-algolia": "1.6.3", | ||
"@algolia/autocomplete-preset-algolia": "1.7.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
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
392617
4043
+ Added@algolia/autocomplete-shared@1.7.0(transitive)
- Removed@algolia/autocomplete-shared@1.6.3(transitive)