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

@algolia/autocomplete-core

Package Overview
Dependencies
Maintainers
62
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/autocomplete-core - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

dist/esm/version.d.ts

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

export declare const version = "1.0.1";
export declare const version = "1.1.0";

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

export var version = '1.0.1';
export var version = '1.1.0';

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

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

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

var version = '1.0.1';
var version = '1.1.0';

@@ -1432,0 +1432,0 @@ exports.createAutocomplete = createAutocomplete;

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

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

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

"dependencies": {
"@algolia/autocomplete-shared": "1.0.1"
"@algolia/autocomplete-shared": "1.1.0"
},
"devDependencies": {
"@algolia/autocomplete-preset-algolia": "1.0.1",
"@algolia/autocomplete-preset-algolia": "1.1.0",
"@algolia/client-search": "4.9.1",

@@ -40,0 +40,0 @@ "algoliasearch": "4.9.1"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc