@appbaseio/searchbase
Advanced tools
Comparing version 1.3.0 to 1.3.2
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Searchbase={})}(this,(function(e){"use strict";function t(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function a(e,t){if(null==e)return{};var r,n,i={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(i[r]=e[r]);return i}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var u=function(){function e(){this.observers=[]}var t=e.prototype;return t.subscribe=function(e,t){this.observers.push({callback:e,properties:t})},t.unsubscribe=function(e){this.observers=e?this.observers.filter((function(t){return t.callback!==e?t:null})):[]},t.next=function(e,t,r){var n=r||window;this.observers.forEach((function(r){(void 0===r.properties||r.properties instanceof Array&&r.properties.length&&r.properties.includes(t)||"string"==typeof r.properties&&r.properties&&r.properties===t)&&r.callback.call(n,e)}))},e}(),c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var h=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){var r=function(e){function t(){this.fetch=!1,this.DOMException=e.DOMException}return t.prototype=e,new t}("undefined"!=typeof self?self:c);!function(e){!function(t){var r="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,i="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,a="ArrayBuffer"in e;if(a)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function h(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function d(e){this.map={},e instanceof d?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function f(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function g(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function p(e){var t=new FileReader,r=g(t);return t.readAsArrayBuffer(e),r}function y(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:i&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&i&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=y(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=y(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var e=f(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(p)}),this.text=function(){var e,t,r,n=f(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=g(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(e,t){e=c(e),t=h(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},d.prototype.delete=function(e){delete this.map[c(e)]},d.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},d.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},d.prototype.set=function(e,t){this.map[c(e)]=h(t)},d.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},d.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),l(e)},d.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},d.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),l(e)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var r,n,i=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new d(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,i||null==e._bodyInit||(i=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new d(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),m.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function _(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(i))}})),t}function w(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new d(t.headers),this.url=t.url||"",this._initBody(e)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},v.call(b.prototype),v.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},w.error=function(){var e=new w(null,{status:0,statusText:""});return e.type="error",e};var S=[301,302,303,307,308];w.redirect=function(e,t){if(-1===S.indexOf(t))throw new RangeError("Invalid status code");return new w(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function C(e,r){return new Promise((function(n,s){var a=new b(e,r);if(a.signal&&a.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function u(){o.abort()}o.onload=function(){var e,t,r={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new d,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();t.append(n,i)}})),t)};r.url="responseURL"in o?o.responseURL:r.headers.get("X-Request-URL");var i="response"in o?o.response:o.responseText;n(new w(i,r))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(a.method,a.url,!0),"include"===a.credentials?o.withCredentials=!0:"omit"===a.credentials&&(o.withCredentials=!1),"responseType"in o&&i&&(o.responseType="blob"),a.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),a.signal&&(a.signal.addEventListener("abort",u),o.onreadystatechange=function(){4===o.readyState&&a.signal.removeEventListener("abort",u)}),o.send(void 0===a._bodyInit?null:a._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=d,e.Request=b,e.Response=w),t.Headers=d,t.Request=b,t.Response=w,t.fetch=C}({})}(r),delete r.fetch.polyfill,(t=r.fetch).default=r.fetch,t.fetch=r.fetch,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,e.exports=t}));h.fetch,h.Headers,h.Request,h.Response;function l(){return(l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function d(e){void 0===e&&(e="");for(var t,r=e,n="",i=0,s=0,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|s)||(a="=",s%1);n+=a.charAt(63&i>>8-s%1*8)){if((t=r.charCodeAt(s+=3/4))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');i=i<<8|t}return n}function f(e,t){if(null==e&&!t)throw new Error("appbase-analytics: query or queryID must be present to register a click/conversion event")}var g={init:function(e){void 0===e&&(e={});var t={credentials:e.credentials,index:e.index,url:e.url,userID:e.userID,globalEventData:e.globalEventData,queryID:"",headers:null};return function(e){if(!e)throw new Error("appbase-analytics: A valid index must be present to record analytics events.")}(t.index),function(e){if(!e)throw new Error("appbase-analytics: Auth credentials is missing.")}(t.credentials),function(e){if(!e)throw new Error("appbase-analytics: URL is missing.")}(t.url),t._request=function(e,r,n){var i=l({},r,{user_id:t.userID,event_data:l({},r&&r.event_data,{},t.globalEventData)});return h(t.url+"/"+t.index+"/_analytics/"+e,{method:"PUT",headers:l({},t.headers,{"Content-Type":"application/json",Authorization:"Basic "+d(t.credentials)}),body:JSON.stringify(i)}).then((function(e){n&&n(null,e)})).catch((function(e){console.error(e),n&&n(e,null)}))},t.search=function(e,r){f(e.query,e.queryID);if(t._request){var n={query:e.query,query_id:e.queryID,event_data:e.eventData,filters:e.filters,hits:e.hits};t._request("search",n,(function(e,n){n&&n.json().then((function(e){e&&e.query_id&&(t.queryID=e.query_id)})).catch((function(e){console.error(e)})),r&&r(e,n)}))}},t.click=function(e,r){if(f(e.query,e.queryID),function(e){if(!e||Object.keys(e).length<1)throw new Error("appbase-analytics: at least one click object must be present to register a click event")}(e.objects),t._request){var n={click_on:e.objects,click_type:e.isSuggestionClick?"suggestion":"result",query:e.query,query_id:e.queryID,event_data:e.eventData};t._request("click",n,r)}},t.conversion=function(e,r){if(f(e.query,e.queryID),function(e){if(!e||Object.keys(e).length<1)throw new Error("appbase-analytics: at least one click object must be present to register a click event")}(e.objects),t._request){var n={conversion_on:e.objects,query:e.query,query_id:e.queryID,event_data:e.eventData};t._request("conversion",n,r)}},t.setUserID=function(e){t.userID=e},t.setGlobalEventData=function(e){t.globalEventData=e},t.setHeaders=function(e){t.headers=e},t}};function p(e){return"SearchBase: "+e}var y={invalidIndex:p("Please provide a valid index."),invalidURL:p("Please provide a valid url."),invalidComponentId:p("Please provide component id."),invalidDataField:p("Please provide data field."),dataFieldAsArray:p("Only components with `search` type supports the multiple data fields. Please define `dataField` as a string.")},v=["key","key.autosuggest"],m="search",b=function(e){var t=[];return e&&(t=[].concat(e).map((function(e){var t=function(e){var t=i({},e);return t.highlight&&Object.keys(t.highlight).forEach((function(e){var r,n=t.highlight[e][0];t._source=i({},t._source,((r={})[e]=n,r))})),t}(e);return Object.keys(t).filter((function(e){return"_source"!==e})).reduce((function(e,r){return e[r]=t[r],e}),i({},t._source))}))),t},_=function(e){if(e){if(!Array.isArray(e))return[e];if(e.length){var t=[];return e.forEach((function(e){"string"==typeof e?t.push(e):e.field&&t.push(e.field)})),t}}};var w=function(e){if(e&&Array.isArray(e)&&e.length){var t=[];return e.forEach((function(e){var r;r=e.weight,!Number.isNaN(parseFloat(r))&&Number.isFinite(r)?t.push(e.weight):t.push(1)})),t}};function S(e,t){var r=[];return function e(t){t&&Object.keys(t)&&Object.keys(t).forEach((function(n){t[n]&&("string"==typeof t[n]?r=[].concat(r,[t[n]]):Array.isArray(t[n])?r=[].concat(r,t[n]):"object"==typeof t[n]&&e(t[n]))}))}(e),r=r.filter((function(e){return e!==t}))}var C=function(e){return"object"==typeof e?Array.isArray(e)?function e(t){return t.reduce((function(t,r){return t.concat(Array.isArray(r)?e(r):r)}),[])}(e):null:e};function q(e,t){if(e===t)return!0;if(!(e instanceof Object&&t instanceof Object))return!1;if(e.constructor!==t.constructor)return!1;for(var r in e)if(e.hasOwnProperty(r)){if(!t.hasOwnProperty(r))return!1;if(e[r]!==t[r]){if("object"!=typeof e[r])return!1;if(!q(e[r],t[r]))return!1}}for(var n in t)if(t.hasOwnProperty(n)&&!e.hasOwnProperty(n))return!1;return!0}var D={id:"id",type:"type",react:"react",queryFormat:"queryFormat",dataField:"dataField",categoryField:"categoryField",categoryValue:"categoryValue",nestedField:"nestedField",from:"from",size:"size",sortBy:"sortBy",value:"value",aggregationField:"aggregationField",aggregationSize:"aggregationSize",after:"after",includeNullValues:"includeNullValues",includeFields:"includeFields",excludeFields:"excludeFields",fuzziness:"fuzziness",searchOperators:"searchOperators",highlight:"highlight",highlightField:"highlightField",customHighlight:"customHighlight",interval:"interval",aggregations:"aggregations",missingLabel:"missingLabel",showMissing:"showMissing",enableSynonyms:"enableSynonyms",selectAllLabel:"selectAllLabel",pagination:"pagination",queryString:"queryString",enablePopularSuggestions:"enablePopularSuggestions",showDistinctSuggestions:"showDistinctSuggestions",error:"error",defaultQuery:"defaultQuery",customQuery:"customQuery",requestStatus:"requestStatus",results:"results",aggregationData:"aggregationData",micStatus:"micStatus",micInstance:"micInstance",micActive:"micActive",micInactive:"micInactive",micDenied:"micDenied",query:"query",requestPending:"loading",appbaseSettings:"appbaseConfig",suggestions:"suggestions",queryId:"queryId",recentSearches:"recentSearches",distinctField:"distinctField",distinctFieldConfig:"distinctFieldConfig",onMicClick:"handleMicClick",triggerDefaultQuery:"triggerDefaultQuery",triggerCustomQuery:"triggerCustomQuery",recordClick:"recordClick",recordConversions:"recordConversions",subscribeToStateChanges:"subscribeToStateChanges",unsubscribeToStateChanges:"unsubscribeToStateChanges",setDataField:"setDataField",setValue:"setValue",setSize:"setSize",setFrom:"setFrom",setFuzziness:"setFuzziness",setIncludeFields:"setIncludeFields",setExcludeFields:"setExcludeFields",setSortBy:"setSortBy",setReact:"setReact",setDefaultQuery:"setDefaultQuery",setCustomQuery:"setCustomQuery",setAfter:"setAfter"};function R(e){void 0===e&&(e="");for(var t,r=e,n="",i=0,s=0,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|s)||(a="=",s%1);n+=a.charAt(63&i>>8-s%1*8)){if((t=r.charCodeAt(s+=3/4))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');i=i<<8|t}return n}var F=function(){function e(e){var t=e.index,r=e.url,n=e.credentials,s=e.headers,a=e.appbaseConfig,o=e.transformRequest,u=e.transformResponse;if(!t)throw new Error(y.invalidIndex);if(!r)throw new Error(y.invalidURL);this.index=t,this.url=r,this.credentials=n||"",a&&(this.appbaseConfig=a),o&&(this.transformRequest=o),u&&(this.transformResponse=u),this.headers={Accept:"application/json","Content-Type":"application/json"},this.credentials&&(this.headers=i({},this.headers,{Authorization:"Basic "+R(this.credentials)})),s&&this.setHeaders(s),this._analyticsInstance=g.init({index:t,url:r,credentials:n})}var t=e.prototype;return t.setHeaders=function(e){this.headers=i({},this.headers,e)},t.setQueryID=function(e){this._queryId=e},e}(),A=function(){function e(e){var t=this;n(this,"setRaw",(function(e){t.raw=e,e.hits&&e.hits.hits&&t.setData(e.hits.hits)})),this.data=e||[]}return e.prototype.setData=function(e){var t,r=b(e);if(this.promotedData.length){var n=this.promotedData.map((function(e){return e._id})).filter(Boolean);n&&(r=r.filter((function(e){return!n.includes(e._id)}))),r=[].concat(this.promotedData.map((function(e){return i({},e,{_promoted:!0})})),r)}this.parseResults?this.data=this.parseResults(r,e):this.data=r,this.data=(void 0===(t=this.data)&&(t=[]),t.map((function(e,t){return i({},e,{_click_id:t+1})})))},r(e,[{key:"numberOfResults",get:function(){return this.raw&&this.raw.hits?"object"==typeof this.raw.hits.total?this.raw.hits.total.value:this.raw.hits.total:0}},{key:"time",get:function(){return this.raw?this.raw.took:0}},{key:"hidden",get:function(){return this.raw&&this.raw.hits&&this.raw.hits.hidden||0}},{key:"promotedData",get:function(){return this.raw&&this.raw.promoted&&this.raw.promoted||[]}},{key:"promoted",get:function(){return this.promotedData.length||0}},{key:"rawData",get:function(){return this.raw||{}}},{key:"customData",get:function(){return this.raw&&this.raw.customData&&this.raw.customData||{}}}]),e}(),E=function(){function e(e){this.data=e||[]}var t=e.prototype;return t.setRaw=function(e){this.raw=e,e.after_key&&this.setAfterKey(e.after_key)},t.setAfterKey=function(e){this.afterKey=e},t.setData=function(e,t,r){void 0===r&&(r=!1);var n,s,a=(n=e,void 0===(s=t)&&(s=[]),s.map((function(e){var t=e.doc_count,r=e.key,s=e[n];return i({_doc_count:t,_key:void 0!==r[n]?r[n]:r},s)})));this.data=r?[].concat(this.data,a):a},r(e,[{key:"rawData",get:function(){return this.raw||{}}}]),e}(),O={triggerDefaultQuery:!0,triggerCustomQuery:!1,stateChanges:!0},x={stateChanges:!0},I="INACTIVE",k="ACTIVE",Q="DENIED",P="INACTIVE",j="PENDING",B="ERROR",T=function(e){function t(t){var r,s=t.index,c=t.url,h=t.credentials,l=t.appbaseConfig,d=t.headers,f=t.transformRequest,g=t.transformResponse,p=t.beforeValueChange,v=t.onValueChange,b=t.onResults,_=t.onAggregationData,w=t.onError,S=t.onRequestStatusChange,C=t.onQueryChange,D=t.onMicStatusChange,R=t.enablePopularSuggestions,F=t.maxPopularSuggestions,B=t.results,T=t.showDistinctSuggestions,z=t.enablePredictiveSuggestions,V=t.preserveResults,M=t.clearOnQueryChange,L=a(t,["index","url","credentials","appbaseConfig","headers","transformRequest","transformResponse","beforeValueChange","onValueChange","onResults","onAggregationData","onError","onRequestStatusChange","onQueryChange","onMicStatusChange","enablePopularSuggestions","maxPopularSuggestions","results","showDistinctSuggestions","enablePredictiveSuggestions","preserveResults","clearOnQueryChange"]);n(o(r=e.call(this,{index:s,url:c,credentials:h,headers:d,appbaseConfig:l,transformRequest:f,transformResponse:g})||this),"onMicClick",(function(e,t){void 0===e&&(e={}),void 0===t&&(t={triggerDefaultQuery:!1,triggerCustomQuery:!1,stateChanges:!0});var n=r._micStatus;if("undefined"!=typeof window&&(window.SpeechRecognition=window.webkitSpeechRecognition||window.SpeechRecognition||null),window&&window.SpeechRecognition&&n!==Q){n===k&&r._setMicStatus(I,t);var i=window.SpeechRecognition;if(r._micInstance)return void r._stopMic();r._micInstance=new i,r._micInstance.continuous=!0,r._micInstance.interimResults=!0,Object.assign(r._micInstance,e),r._micInstance.start(),r._micInstance.onstart=function(){r._setMicStatus(k,t)},r._micInstance.onresult=function(e){var n=e.results;n&&n[0]&&n[0].isFinal&&r._stopMic(),r._handleVoiceResults({results:n},t)},r._micInstance.onerror=function(e){"no-speech"===e.error||"audio-capture"===e.error?r._setMicStatus(I,t):"not-allowed"===e.error&&r._setMicStatus(Q,t),console.error(e)}}})),n(o(r),"setDataField",(function(e,t){void 0===t&&(t=O);var n=r.dataField;r.dataField=e,r._applyOptions(t,"dataField",n,e)})),n(o(r),"setParent",(function(e){r._parent=e})),n(o(r),"setValue",(function(e,t){void 0===t&&(t=O);var n=function(){var n=r.value;r.value=e,r._applyOptions(t,"value",n,r.value)};r.beforeValueChange?r.beforeValueChange(e).then(n).catch((function(e){console.warn("beforeValueChange rejected the promise with ",e)})):n()})),n(o(r),"setSize",(function(e,t){void 0===t&&(t=O);var n=r.size;r.size=e,r._applyOptions(t,"size",n,r.size)})),n(o(r),"setFrom",(function(e,t){void 0===t&&(t=O);var n=r.from;r.from=e,r._applyOptions(t,"from",n,r.from)})),n(o(r),"setFuzziness",(function(e,t){void 0===t&&(t=O);var n=r.fuzziness;r.fuzziness=e,r._applyOptions(t,"fuzziness",n,r.fuzziness)})),n(o(r),"setIncludeFields",(function(e,t){void 0===t&&(t=O);var n=r.includeFields;r.includeFields=e,r._applyOptions(t,"includeFields",n,e)})),n(o(r),"setExcludeFields",(function(e,t){void 0===t&&(t=O);var n=r.excludeFields;r.excludeFields=e,r._applyOptions(t,"excludeFields",n,e)})),n(o(r),"setSortBy",(function(e,t){void 0===t&&(t=O);var n=r.sortBy;r.sortBy=e,r._applyOptions(t,"sortBy",n,e)})),n(o(r),"setReact",(function(e,t){void 0===t&&(t=O);var n=r.react;r.react=e,r._applyOptions(t,"react",n,e)})),n(o(r),"setDefaultQuery",(function(e,t){void 0===t&&(t=O);var n=r.defaultQuery;r.defaultQuery=e,r._applyOptions(t,"defaultQuery",n,e)})),n(o(r),"setCustomQuery",(function(e,t){void 0===t&&(t=O);var n=r.customQuery;r.customQuery=e,r._applyOptions(t,"customQuery",n,e)})),n(o(r),"setAfter",(function(e,t){void 0===t&&(t=O);var n=r.after;r.after=e,r.aggregationData.setAfterKey(e),r._applyOptions(t,"after",n,e)})),n(o(r),"triggerDefaultQuery",(function(e){if(void 0===e&&(e=x),q(r._query,r.componentQuery))return Promise.resolve(!0);var t=function(t){return r._setError(t,{stateChanges:e.stateChanges}),console.error(t),Promise.reject(t)};try{return r._updateQuery(),r._setRequestStatus(j),r._fetchRequest({query:Array.isArray(r.query)?r.query:[r.query],settings:r.appbaseSettings}).then((function(n){var s=r.results,a=n&&n[r.id],o=function(){a.aggregations&&r._handleAggregationResponse(a.aggregations,i({defaultOptions:O},e)),r._setRequestStatus(P),r._applyOptions({stateChanges:e.stateChanges},"results",s,r.results)};return r.type&&r.type!==m||!r.enablePopularSuggestions?(r._appendResults(a),o()):r._fetchRequest(r.getSuggestionsQuery(),!0).then((function(e){var t=e.DataSearch__suggestions;t&&t.hits&&t.hits.hits&&a.hits&&a.hits.hits&&(a.hits.hits=[].concat((t.hits.hits||[]).map((function(e){return i({},e,{_popular_suggestion:!0})})),a.hits.hits)),r._appendResults(a),o()})).catch(t),Promise.resolve(a)})).catch(t)}catch(e){return t(e)}})),n(o(r),"triggerCustomQuery",(function(e){void 0===e&&(e=x);var t=r._generateQuery(),n=t.requestBody,s=t.orderOfQueries;if(!n.length)return Promise.resolve({});if(q(r._query,n))return Promise.resolve(!0);var a=function(t){return r._setError(t,{stateChanges:e.stateChanges}),console.error(t),Promise.reject(t)};try{s.forEach((function(e){var t=r._parent.getComponent(e);t&&(t.setFrom(0,{stateChanges:!0,triggerDefaultQuery:!1,triggerCustomQuery:!1}),t.setAfter(void 0,{stateChanges:!0,triggerDefaultQuery:!1,triggerCustomQuery:!1}),r.clearOnQueryChange&&r._query&&t.setValue(void 0,{stateChanges:!0,triggerDefaultQuery:!1,triggerCustomQuery:!1}),t._setRequestStatus(j),t._updateQuery())}));var o=r._generateQuery().requestBody;return r._fetchRequest({query:o,settings:r.appbaseSettings}).then((function(t){return s.forEach((function(n){var s=r._parent.getComponent(n);if(s){s._setRequestStatus(P);var a=s.results,o=t&&t[n];o.hits&&(s.results.setRaw(o),s._applyOptions({stateChanges:e.stateChanges},"results",a,s.results)),o.aggregations&&s._handleAggregationResponse(o.aggregations,i({defaultOptions:O},e),!1)}})),Promise.resolve(t)})).catch(a)}catch(e){return a(e)}})),n(o(r),"recordClick",(function(e,t){void 0===t&&(t=!1),r._analyticsInstance&&r.queryId&&r._analyticsInstance.click({queryID:r.queryId,objects:e,isSuggestionClick:t})})),n(o(r),"recordConversions",(function(e){r._analyticsInstance&&r.queryId&&r._analyticsInstance.conversion({queryID:r.queryId,objects:e})})),n(o(r),"subscribeToStateChanges",(function(e,t){r.stateChanges.subscribe(e,t)})),n(o(r),"unsubscribeToStateChanges",(function(e){r.stateChanges.unsubscribe(e)})),n(o(r),"clearResults",(function(e){void 0===e&&(e=x);var t=r.results;r.results.setRaw({hits:{hits:[]}}),r._applyOptions({stateChanges:e.stateChanges},"results",t,r.results)})),n(o(r),"getRecentSearches",(function(e,t){void 0===e&&(e={size:5,minChars:3}),void 0===t&&(t=x);var n={headers:i({},r.headers)},s="",a=function(e,t){s+=s?"&"+e+"="+t:e+"="+t};return r.appbaseSettings&&r.appbaseSettings.userId&&a("user_id",r.appbaseSettings.userId),e&&(e.size&&a("size",String(e.size)),e.from&&a("from",e.from),e.to&&a("to",e.to),e.minChars&&a("min_chars",String(e.minChars)),e.customEvents&&Object.keys(e.customEvents).forEach((function(t){a(t,e.customEvents[t])}))),new Promise((function(e,i){fetch(r.url+"/_analytics/"+r._getSearchIndex()+"/recent-searches?"+s,n).then((function(n){return n.status>=500||n.status>=400?i(n):n.json().then((function(n){var i=r.recentSearches;r.recentSearches=n.map((function(e){return{label:e.key,value:e.key}})),r._applyOptions({stateChanges:t.stateChanges},"recentSearches",i,r.recentSearches),e(r.recentSearches)})).catch((function(e){return console.warn("SearchBase: error while fetching the recent searches ",e),i(e)}))})).catch((function(e){return console.warn("SearchBase: error while fetching the recent searches ",e),i(e)}))}))})),n(o(r),"_handleVoiceResults",(function(e,t){var n=e.results;void 0===t&&(t=O),n&&n[0]&&n[0].isFinal&&n[0][0]&&n[0][0].transcript&&n[0][0].transcript.trim()&&r.setValue(n[0][0].transcript.trim(),i({},t,{triggerCustomQuery:!0,triggerDefaultQuery:!0}))})),n(o(r),"_stopMic",(function(){r._micInstance&&(r._micInstance.stop(),r._micInstance=null,r._setMicStatus(I))})),n(o(r),"_setMicStatus",(function(e,t){void 0===t&&(t=O);var n=r._micStatus;r._micStatus=e,r._applyOptions(t,"micStatus",n,r._micStatus)}));var U=L.id,H=L.type,N=L.react,G=L.queryFormat,K=L.dataField,J=L.categoryField,X=L.categoryValue,W=L.nestedField,Y=L.from,Z=L.size,$=L.sortBy,ee=L.value,te=L.aggregationField,re=L.aggregationSize,ne=L.after,ie=L.includeNullValues,se=L.includeFields,ae=L.excludeFields,oe=L.fuzziness,ue=L.searchOperators,ce=L.highlight,he=L.highlightField,le=L.customHighlight,de=L.interval,fe=L.aggregations,ge=L.missingLabel,pe=L.showMissing,ye=L.defaultQuery,ve=L.customQuery,me=L.execute,be=L.enableSynonyms,_e=L.selectAllLabel,we=L.pagination,Se=L.queryString,Ce=L.distinctField,qe=L.distinctFieldConfig;if(!U)throw new Error(y.invalidComponentId);if(H&&H!==m){if(!K)throw new Error(y.invalidDataField);if(Array.isArray(K))throw new Error(y.dataFieldAsArray)}return r.id=U,r.type=H,r.react=N,r.queryFormat=G,r.dataField=K,r.categoryField=J,r.categoryValue=X,r.nestedField=W,r.from=Y,r.size=Z,r.sortBy=$,r.aggregationField=te,r.aggregationSize=re,r.after=ne,r.includeNullValues=ie,r.includeFields=se,r.excludeFields=ae,r.fuzziness=oe,r.searchOperators=ue,r.highlight=ce,r.highlightField=he,r.customHighlight=le,r.interval=de,r.aggregations=fe,r.missingLabel=ge,r.showMissing=pe,r.execute=me,r.enableSynonyms=be,r.selectAllLabel=_e,r.pagination=we,r.queryString=Se,r.defaultQuery=ye,r.customQuery=ve,r.beforeValueChange=p,r.onValueChange=v,r.onResults=b,r.onAggregationData=_,r.onError=w,r.onRequestStatusChange=S,r.onQueryChange=C,r.onMicStatusChange=D,r.distinctField=Ce,r.distinctFieldConfig=qe,r.enablePopularSuggestions=R,r.maxPopularSuggestions=F,r.showDistinctSuggestions=T,r.enablePredictiveSuggestions=z,r.preserveResults=V,r.clearOnQueryChange=M,r.stateChanges=new u,r.results=new A(B),r.aggregationData=new E,ee?r.setValue(ee,{stateChanges:!0}):r.value=ee,r}s(t,e);var c=t.prototype;return c.getSuggestionsQuery=function(){return{query:[{id:"DataSearch__suggestions",dataField:v,size:this.maxPopularSuggestions||5,value:this.value,defaultQuery:{query:{bool:{minimum_should_match:1,should:[{function_score:{field_value_factor:{field:"count",modifier:"sqrt",missing:1}}},{multi_match:{fields:["key^9","key.autosuggest^1","key.keyword^10"],fuzziness:0,operator:"or",query:this.value,type:"best_fields"}},{multi_match:{fields:["key^9","key.autosuggest^1","key.keyword^10"],operator:"or",query:this.value,type:"phrase"}},{multi_match:{fields:["key^9"],operator:"or",query:this.value,type:"phrase_prefix"}}]}}}}]}},c._appendResults=function(e){this.preserveResults&&e&&Array.isArray(e.hits&&e.hits.hits)&&Array.isArray(this.results.rawData&&this.results.rawData.hits&&this.results.rawData.hits.hits)?this.results.setRaw(i({},e,{hits:i({},e.hits,{hits:[].concat(this.results.rawData.hits.hits,e.hits.hits)})})):this.results.setRaw(e)},c._applyOptions=function(e,t,r,n){var i;("micStatus"===t&&this.onMicStatusChange&&this.onMicStatusChange(n,r),"query"===t&&this.onQueryChange&&this.onQueryChange(n,r),"value"===t&&this.onValueChange&&this.onValueChange(n,r),"error"===t&&this.onError&&this.onError(n),"results"===t&&this.onResults&&this.onResults(n,r),"aggregationData"===t&&this.onAggregationData&&this.onAggregationData(n,r),"requestStatus"===t&&this.onRequestStatusChange&&this.onRequestStatusChange(n,r),e.triggerDefaultQuery&&this.triggerDefaultQuery(),e.triggerCustomQuery&&this.triggerCustomQuery(),!1!==e.stateChanges)&&this.stateChanges.next(((i={})[t]={prev:r,next:n},i),t)},c._getSearchIndex=function(e){void 0===e&&(e=!1);var t=this.index;return e?t=".suggestions":this._parent&&this._parent.index&&(t=this._parent.index),t},c._fetchRequest=function(e,t){var r=this;void 0===t&&(t=!1);var n={method:"POST",body:JSON.stringify(e),headers:i({},this.headers)};return new Promise((function(e,s){r._handleTransformRequest(n).then((function(n){var a=Date.now(),o=r._getSearchIndex(t);return fetch(r.url+"/"+o+"/_reactivesearch.v3",n).then((function(t){var n=t.headers;if(t.headers){var o=t.headers.get("X-Search-Id");o&&(r._parent?r._parent.setQueryID(o):r.setQueryID(o))}return t.status>=500||t.status>=400?s(t):t.json().then((function(t){r._handleTransformResponse(t).then((function(t){t&&Object.prototype.hasOwnProperty.call(t,"error")&&s(t);var r=i({},t,{_timestamp:a,_headers:n});return e(r)})).catch((function(e){return console.warn("SearchBase: transformResponse rejected the promise with ",e),s(e)}))}))})).catch((function(e){return s(e)}))})).catch((function(e){return console.warn("SearchBase: transformRequest rejected the promise with ",e),s(e)}))}))},c._generateQuery=function(){var e=this;if(this._parent){var t=this._parent.getComponents(),r=[];Object.keys(t).forEach((function(n){var i=t[n];i&&i.react&&(S(i.react,n).indexOf(e.id)>-1&&r.push(n))}));var n={};return r.forEach((function(t){var r=e._parent.getComponent(t);r&&(n[t]=r.componentQuery,S(r.react,r.id).forEach((function(t){if(!n[t]){var r=e._parent.getComponent(t);if(r&&r.value){var i=r.componentQuery;i.execute=!1,n[t]=i}}})))})),{requestBody:Object.values(n),orderOfQueries:r}}return{requestBody:[],orderOfQueries:[]}},c._handleTransformResponse=function(e){return this.transformResponse&&"function"==typeof this.transformResponse?this.transformResponse(e):new Promise((function(t){return t(e)}))},c._handleTransformRequest=function(e){return this.transformRequest&&"function"==typeof this.transformRequest?this.transformRequest(e):new Promise((function(t){return t(e)}))},c._handleAggregationResponse=function(e,t,r){void 0===t&&(t=O),void 0===r&&(r=!0);var n=this.aggregationField;n||"string"!=typeof this.dataField||(n=this.dataField);var i=this.aggregationData;this.aggregationData.setRaw(e[n]),this.aggregationData.setData(n,e[n].buckets,this.preserveResults&&r),this._applyOptions({stateChanges:t.stateChanges},"aggregationData",i,this.aggregationData)},c._setError=function(e,t){void 0===t&&(t=O),this._setRequestStatus(B);var r=this.error;this.error=e,this._applyOptions(t,"error",r,this.error)},c._setRequestStatus=function(e){var t=this.requestStatus;this.requestStatus=e,this._applyOptions({stateChanges:!0},"requestStatus",t,this.requestStatus)},c._updateQuery=function(e){var t,r=this;t=i({},this._query);var n=[this.componentQuery];S(this.react,this.id).forEach((function(e){var t=r._parent.getComponent(e);if(t&&t.value){var i=t.componentQuery;i.execute=!1,n.push(i)}})),this._query=e||n,this._applyOptions({stateChanges:!1},"query",t,this._query)},r(t,[{key:"micStatus",get:function(){return this._micStatus}},{key:"micInstance",get:function(){return this._micInstance}},{key:"micActive",get:function(){return this._micStatus===k}},{key:"micInactive",get:function(){return this._micStatus===I}},{key:"micDenied",get:function(){return this._micStatus===Q}},{key:"query",get:function(){return this._query}},{key:"requestPending",get:function(){return this.requestStatus===j}},{key:"appbaseSettings",get:function(){var e=this.appbaseConfig||{};return{recordAnalytics:e.recordAnalytics,customEvents:e.customEvents,enableQueryRules:e.enableQueryRules,userId:e.userId}}},{key:"suggestions",get:function(){if(this.type&&this.type!==m)return[];if(this.results){var e=_(this.dataField)||[];return 0===e.length&&this.results.data&&Array.isArray(this.results.data)&&this.results.data.length>0&&this.results.data[0]&&(e=Object.keys(this.results.data[0]).filter((function(e){return!["_id","_click_id","_index","_score","_type"].includes(e)}))),this.enablePopularSuggestions&&(e=[].concat(e,v)),function(e,t,r,n,s){void 0===e&&(e=[]),void 0===r&&(r=""),void 0===n&&(n=!0),void 0===s&&(s=!1);var o=[],u=[],c=!1,h=r||"",l=function(e,t,r){if((c||h.trim().split(" ").some((function(t){return String(e).toLowerCase().includes(t)})))&&!u.includes(e)||r._promoted){var s=i({},{label:e,value:e,source:r});if(u=[].concat(u,[e]),o=[].concat(o,[s]),n)return!0}return!1},d=function e(t,r,i){if(void 0===r&&(r=""),void 0===i&&(i=t),"object"==typeof t){var s=r.split("."),a=t[s[0]];if(a)if(s.length>1){var o=r.substring(s[0].length+1);Array.isArray(a)?a.forEach((function(t){e(t,o,i)})):e(a,o,i)}else{var u=C(a);if(u){if(Array.isArray(u)){if(n)return u.some((function(e){return l(e,0,i)}));u.forEach((function(e){return l(e,0,i)}))}return l(u,0,i)}}}return!1},f=function(){n?t.forEach((function(t){e.some((function(e){return d(t,e)}))})):t.forEach((function(t){e.forEach((function(e){d(t,e)}))}))};f(),o.length<t.length&&!c&&(c=!0,f());var g,p,y,v,m,b;return s?(p=(g={predictiveSuggestions:o,currentValuePredictive:r,wordsToShowAfterHighlight:!0}).predictiveSuggestions,y=g.currentValuePredictive,v=g.wordsToShowAfterHighlight,m={},(b=y.trim())?p.reduce((function(e,t){var r=t.label,n=a(t,["label"]),s=(new DOMParser).parseFromString(r,"text/html").documentElement.textContent,o="^("+b+")\\w+",u=new RegExp(o,"i"),c=u.exec(s);if(c||(o="^("+b+")",c=(u=new RegExp(o,"i")).exec(s)),c){var h=s.slice(c.index,s.length),l=b+'<mark class="highlight-class">'+h.slice(b.length).split(" ").slice(0,v+1).join(" ")+"</mark>";return m[l]?e:(m[l]=1,[].concat(e,[i({label:l,isPredictiveSuggestion:!0},n)]))}return e}),[]):[]):o}(e,this.results.data,this.value,this.showDistinctSuggestions,this.enablePredictiveSuggestions).slice(0,this.size)}return[]}},{key:"componentQuery",get:function(){return{id:this.id,type:this.type,dataField:_(this.dataField),react:this.react,highlight:this.highlight,highlightField:_(this.highlightField),fuzziness:this.fuzziness,searchOperators:this.searchOperators,includeFields:this.includeFields,excludeFields:this.excludeFields,size:this.size,from:this.from,queryFormat:this.queryFormat,sortBy:this.sortBy,fieldWeights:w(this.dataField),includeNullValues:this.includeNullValues,aggregationField:this.aggregationField,aggregationSize:this.aggregationSize,categoryField:this.categoryField,missingLabel:this.missingLabel,showMissing:this.showMissing,nestedField:this.nestedField,interval:this.interval,customHighlight:this.customHighlight,customQuery:this.customQuery?this.customQuery(this):void 0,defaultQuery:this.defaultQuery?this.defaultQuery(this):void 0,value:this.value,categoryValue:this.categoryValue,after:this.after,aggregations:this.aggregations,enableSynonyms:this.enableSynonyms,selectAllLabel:this.selectAllLabel,pagination:this.pagination,queryString:this.queryString,distinctField:this.distinctField,distinctFieldConfig:this.distinctFieldConfig,index:this.index}}},{key:"queryId",get:function(){return this._parent&&this._parent._queryId?this._parent._queryId:this._queryId?this._queryId:""}},{key:"mappedProps",get:function(){var e=this,t={};return Object.keys(D).forEach((function(r){t[D[r]]=e[r]})),t}}]),t}(F),z=function(e){function t(t){var r,s=t.index,a=t.url,u=t.credentials,c=t.headers,h=t.appbaseConfig;return n(o(r=e.call(this,{index:s,url:a,credentials:u,headers:c,appbaseConfig:h})||this),"register",(function(e,t){if(!e)throw new Error(y.invalidComponentId);if(r._components[e])return r._components[e];var n=t;return!t||t instanceof T?n.id=e:n=new T(i({},t,{id:e,index:t.index||r.index,url:t.url||r.url,credentials:t.credentials||r.credentials,headers:t.headers||r.headers,transformRequest:t.transformRequest||r.transformRequest,transformResponse:t.transformResponse||r.transformResponse,appbaseConfig:t.appbaseConfig||r.appbaseConfig})),r._components[e]=n,n.setParent(o(r)),n})),n(o(r),"unregister",(function(e){e&&delete r._components[e]})),n(o(r),"getComponent",(function(e){return r._components[e]})),n(o(r),"getComponents",(function(){return r._components})),r._components={},r}return s(t,e),t}(F);e.SearchBase=z,e.SearchComponent=T,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Searchbase={})}(this,(function(e){"use strict";function t(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function a(e,t){if(null==e)return{};var r,n,i={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(i[r]=e[r]);return i}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var u=function(){function e(){this.observers=[]}var t=e.prototype;return t.subscribe=function(e,t){this.observers.push({callback:e,properties:t})},t.unsubscribe=function(e){this.observers=e?this.observers.filter((function(t){return t.callback!==e?t:null})):[]},t.next=function(e,t,r){var n=r;!n&&window&&(n=window),this.observers.forEach((function(r){(void 0===r.properties||r.properties instanceof Array&&r.properties.length&&r.properties.includes(t)||"string"==typeof r.properties&&r.properties&&r.properties===t)&&r.callback.call(n,e)}))},e}(),c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var h=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){var r=function(e){function t(){this.fetch=!1,this.DOMException=e.DOMException}return t.prototype=e,new t}("undefined"!=typeof self?self:c);!function(e){!function(t){var r="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,i="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,a="ArrayBuffer"in e;if(a)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function h(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function d(e){this.map={},e instanceof d?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function f(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function g(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function p(e){var t=new FileReader,r=g(t);return t.readAsArrayBuffer(e),r}function y(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:i&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&i&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=y(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=y(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var e=f(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(p)}),this.text=function(){var e,t,r,n=f(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=g(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(e,t){e=c(e),t=h(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},d.prototype.delete=function(e){delete this.map[c(e)]},d.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},d.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},d.prototype.set=function(e,t){this.map[c(e)]=h(t)},d.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},d.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),l(e)},d.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},d.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),l(e)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var r,n,i=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new d(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,i||null==e._bodyInit||(i=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new d(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),m.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function _(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(i))}})),t}function w(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new d(t.headers),this.url=t.url||"",this._initBody(e)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},v.call(b.prototype),v.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},w.error=function(){var e=new w(null,{status:0,statusText:""});return e.type="error",e};var S=[301,302,303,307,308];w.redirect=function(e,t){if(-1===S.indexOf(t))throw new RangeError("Invalid status code");return new w(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function C(e,r){return new Promise((function(n,s){var a=new b(e,r);if(a.signal&&a.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function u(){o.abort()}o.onload=function(){var e,t,r={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new d,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();t.append(n,i)}})),t)};r.url="responseURL"in o?o.responseURL:r.headers.get("X-Request-URL");var i="response"in o?o.response:o.responseText;n(new w(i,r))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(a.method,a.url,!0),"include"===a.credentials?o.withCredentials=!0:"omit"===a.credentials&&(o.withCredentials=!1),"responseType"in o&&i&&(o.responseType="blob"),a.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),a.signal&&(a.signal.addEventListener("abort",u),o.onreadystatechange=function(){4===o.readyState&&a.signal.removeEventListener("abort",u)}),o.send(void 0===a._bodyInit?null:a._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=d,e.Request=b,e.Response=w),t.Headers=d,t.Request=b,t.Response=w,t.fetch=C}({})}(r),delete r.fetch.polyfill,(t=r.fetch).default=r.fetch,t.fetch=r.fetch,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,e.exports=t}));h.fetch,h.Headers,h.Request,h.Response;function l(){return(l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function d(e){void 0===e&&(e="");for(var t,r=e,n="",i=0,s=0,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|s)||(a="=",s%1);n+=a.charAt(63&i>>8-s%1*8)){if((t=r.charCodeAt(s+=3/4))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');i=i<<8|t}return n}function f(e,t){if(null==e&&!t)throw new Error("appbase-analytics: query or queryID must be present to register a click/conversion event")}var g={init:function(e){void 0===e&&(e={});var t={credentials:e.credentials,index:e.index,url:e.url,userID:e.userID,globalEventData:e.globalEventData,queryID:"",headers:null};return function(e){if(!e)throw new Error("appbase-analytics: A valid index must be present to record analytics events.")}(t.index),function(e){if(!e)throw new Error("appbase-analytics: Auth credentials is missing.")}(t.credentials),function(e){if(!e)throw new Error("appbase-analytics: URL is missing.")}(t.url),t._request=function(e,r,n){var i=l({},r,{user_id:t.userID,event_data:l({},r&&r.event_data,{},t.globalEventData)});return h(t.url+"/"+t.index+"/_analytics/"+e,{method:"PUT",headers:l({},t.headers,{"Content-Type":"application/json",Authorization:"Basic "+d(t.credentials)}),body:JSON.stringify(i)}).then((function(e){n&&n(null,e)})).catch((function(e){console.error(e),n&&n(e,null)}))},t.search=function(e,r){f(e.query,e.queryID);if(t._request){var n={query:e.query,query_id:e.queryID,event_data:e.eventData,filters:e.filters,hits:e.hits};t._request("search",n,(function(e,n){n&&n.json().then((function(e){e&&e.query_id&&(t.queryID=e.query_id)})).catch((function(e){console.error(e)})),r&&r(e,n)}))}},t.click=function(e,r){if(f(e.query,e.queryID),function(e){if(!e||Object.keys(e).length<1)throw new Error("appbase-analytics: at least one click object must be present to register a click event")}(e.objects),t._request){var n={click_on:e.objects,click_type:e.isSuggestionClick?"suggestion":"result",query:e.query,query_id:e.queryID,event_data:e.eventData};t._request("click",n,r)}},t.conversion=function(e,r){if(f(e.query,e.queryID),function(e){if(!e||Object.keys(e).length<1)throw new Error("appbase-analytics: at least one click object must be present to register a click event")}(e.objects),t._request){var n={conversion_on:e.objects,query:e.query,query_id:e.queryID,event_data:e.eventData};t._request("conversion",n,r)}},t.setUserID=function(e){t.userID=e},t.setGlobalEventData=function(e){t.globalEventData=e},t.setHeaders=function(e){t.headers=e},t}};function p(e){return"SearchBase: "+e}var y={invalidIndex:p("Please provide a valid index."),invalidURL:p("Please provide a valid url."),invalidComponentId:p("Please provide component id."),invalidDataField:p("Please provide data field."),dataFieldAsArray:p("Only components with `search` type supports the multiple data fields. Please define `dataField` as a string.")},v=["key","key.autosuggest"],m="search",b=function(e){var t=[];return e&&(t=[].concat(e).map((function(e){var t=function(e){var t=i({},e);return t.highlight&&Object.keys(t.highlight).forEach((function(e){var r,n=t.highlight[e][0];t._source=i({},t._source,((r={})[e]=n,r))})),t}(e);return Object.keys(t).filter((function(e){return"_source"!==e})).reduce((function(e,r){return e[r]=t[r],e}),i({},t._source))}))),t},_=function(e){if(e){if(!Array.isArray(e))return[e];if(e.length){var t=[];return e.forEach((function(e){"string"==typeof e?t.push(e):e.field&&t.push(e.field)})),t}}};var w=function(e){if(e&&Array.isArray(e)&&e.length){var t=[];return e.forEach((function(e){var r;r=e.weight,!Number.isNaN(parseFloat(r))&&Number.isFinite(r)?t.push(e.weight):t.push(1)})),t}};function S(e,t){var r=[];return function e(t){t&&Object.keys(t)&&Object.keys(t).forEach((function(n){t[n]&&("string"==typeof t[n]?r=[].concat(r,[t[n]]):Array.isArray(t[n])?r=[].concat(r,t[n]):"object"==typeof t[n]&&e(t[n]))}))}(e),r=r.filter((function(e){return e!==t}))}var C=function(e){return"object"==typeof e?Array.isArray(e)?function e(t){return t.reduce((function(t,r){return t.concat(Array.isArray(r)?e(r):r)}),[])}(e):null:e};function q(e,t){if(e===t)return!0;if(!(e instanceof Object&&t instanceof Object))return!1;if(e.constructor!==t.constructor)return!1;for(var r in e)if(e.hasOwnProperty(r)){if(!t.hasOwnProperty(r))return!1;if(e[r]!==t[r]){if("object"!=typeof e[r])return!1;if(!q(e[r],t[r]))return!1}}for(var n in t)if(t.hasOwnProperty(n)&&!e.hasOwnProperty(n))return!1;return!0}var D={id:"id",type:"type",react:"react",queryFormat:"queryFormat",dataField:"dataField",categoryField:"categoryField",categoryValue:"categoryValue",nestedField:"nestedField",from:"from",size:"size",sortBy:"sortBy",value:"value",aggregationField:"aggregationField",aggregationSize:"aggregationSize",after:"after",includeNullValues:"includeNullValues",includeFields:"includeFields",excludeFields:"excludeFields",fuzziness:"fuzziness",searchOperators:"searchOperators",highlight:"highlight",highlightField:"highlightField",customHighlight:"customHighlight",interval:"interval",aggregations:"aggregations",missingLabel:"missingLabel",showMissing:"showMissing",enableSynonyms:"enableSynonyms",selectAllLabel:"selectAllLabel",pagination:"pagination",queryString:"queryString",enablePopularSuggestions:"enablePopularSuggestions",showDistinctSuggestions:"showDistinctSuggestions",error:"error",defaultQuery:"defaultQuery",customQuery:"customQuery",requestStatus:"requestStatus",results:"results",aggregationData:"aggregationData",micStatus:"micStatus",micInstance:"micInstance",micActive:"micActive",micInactive:"micInactive",micDenied:"micDenied",query:"query",requestPending:"loading",appbaseSettings:"appbaseConfig",suggestions:"suggestions",queryId:"queryId",recentSearches:"recentSearches",distinctField:"distinctField",distinctFieldConfig:"distinctFieldConfig",onMicClick:"handleMicClick",triggerDefaultQuery:"triggerDefaultQuery",triggerCustomQuery:"triggerCustomQuery",recordClick:"recordClick",recordConversions:"recordConversions",subscribeToStateChanges:"subscribeToStateChanges",unsubscribeToStateChanges:"unsubscribeToStateChanges",setDataField:"setDataField",setValue:"setValue",setSize:"setSize",setFrom:"setFrom",setFuzziness:"setFuzziness",setIncludeFields:"setIncludeFields",setExcludeFields:"setExcludeFields",setSortBy:"setSortBy",setReact:"setReact",setDefaultQuery:"setDefaultQuery",setCustomQuery:"setCustomQuery",setAfter:"setAfter"};function R(e){void 0===e&&(e="");for(var t,r=e,n="",i=0,s=0,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|s)||(a="=",s%1);n+=a.charAt(63&i>>8-s%1*8)){if((t=r.charCodeAt(s+=3/4))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');i=i<<8|t}return n}var F=function(){function e(e){var t=e.index,r=e.url,n=e.credentials,s=e.headers,a=e.appbaseConfig,o=e.transformRequest,u=e.transformResponse;if(!t)throw new Error(y.invalidIndex);if(!r)throw new Error(y.invalidURL);this.index=t,this.url=r,this.credentials=n||"",a&&(this.appbaseConfig=a),o&&(this.transformRequest=o),u&&(this.transformResponse=u),this.headers={Accept:"application/json","Content-Type":"application/json"},this.credentials&&(this.headers=i({},this.headers,{Authorization:"Basic "+R(this.credentials)})),s&&this.setHeaders(s),this._analyticsInstance=g.init({index:t,url:r,credentials:n})}var t=e.prototype;return t.setHeaders=function(e){this.headers=i({},this.headers,e)},t.setQueryID=function(e){this._queryId=e},e}(),A=function(){function e(e){var t=this;n(this,"setRaw",(function(e){t.raw=e,e.hits&&e.hits.hits&&t.setData(e.hits.hits)})),this.data=e||[]}return e.prototype.setData=function(e){var t,r=b(e);if(this.promotedData.length){var n=this.promotedData.map((function(e){return e._id})).filter(Boolean);n&&(r=r.filter((function(e){return!n.includes(e._id)}))),r=[].concat(this.promotedData.map((function(e){return i({},e,{_promoted:!0})})),r)}this.parseResults?this.data=this.parseResults(r,e):this.data=r,this.data=(void 0===(t=this.data)&&(t=[]),t.map((function(e,t){return i({},e,{_click_id:t+1})})))},r(e,[{key:"numberOfResults",get:function(){return this.raw&&this.raw.hits?"object"==typeof this.raw.hits.total?this.raw.hits.total.value:this.raw.hits.total:0}},{key:"time",get:function(){return this.raw?this.raw.took:0}},{key:"hidden",get:function(){return this.raw&&this.raw.hits&&this.raw.hits.hidden||0}},{key:"promotedData",get:function(){return this.raw&&this.raw.promoted&&this.raw.promoted||[]}},{key:"promoted",get:function(){return this.promotedData.length||0}},{key:"rawData",get:function(){return this.raw||{}}},{key:"customData",get:function(){return this.raw&&this.raw.customData&&this.raw.customData||{}}}]),e}(),E=function(){function e(e){this.data=e||[]}var t=e.prototype;return t.setRaw=function(e){this.raw=e,e.after_key&&this.setAfterKey(e.after_key)},t.setAfterKey=function(e){this.afterKey=e},t.setData=function(e,t,r){void 0===r&&(r=!1);var n,s,a=(n=e,void 0===(s=t)&&(s=[]),s.map((function(e){var t=e.doc_count,r=e.key,s=e[n];return i({_doc_count:t,_key:void 0!==r[n]?r[n]:r},s)})));this.data=r?[].concat(this.data,a):a},r(e,[{key:"rawData",get:function(){return this.raw||{}}}]),e}(),O={triggerDefaultQuery:!0,triggerCustomQuery:!1,stateChanges:!0},x={stateChanges:!0},I="INACTIVE",k="ACTIVE",Q="DENIED",P="INACTIVE",j="PENDING",B="ERROR",T=function(e){function t(t){var r,s=t.index,c=t.url,h=t.credentials,l=t.appbaseConfig,d=t.headers,f=t.transformRequest,g=t.transformResponse,p=t.beforeValueChange,v=t.onValueChange,b=t.onResults,_=t.onAggregationData,w=t.onError,S=t.onRequestStatusChange,C=t.onQueryChange,D=t.onMicStatusChange,R=t.enablePopularSuggestions,F=t.maxPopularSuggestions,B=t.results,T=t.showDistinctSuggestions,z=t.enablePredictiveSuggestions,V=t.preserveResults,M=t.clearOnQueryChange,L=a(t,["index","url","credentials","appbaseConfig","headers","transformRequest","transformResponse","beforeValueChange","onValueChange","onResults","onAggregationData","onError","onRequestStatusChange","onQueryChange","onMicStatusChange","enablePopularSuggestions","maxPopularSuggestions","results","showDistinctSuggestions","enablePredictiveSuggestions","preserveResults","clearOnQueryChange"]);n(o(r=e.call(this,{index:s,url:c,credentials:h,headers:d,appbaseConfig:l,transformRequest:f,transformResponse:g})||this),"onMicClick",(function(e,t){void 0===e&&(e={}),void 0===t&&(t={triggerDefaultQuery:!1,triggerCustomQuery:!1,stateChanges:!0});var n=r._micStatus;if("undefined"!=typeof window&&(window.SpeechRecognition=window.webkitSpeechRecognition||window.SpeechRecognition||null),window&&window.SpeechRecognition&&n!==Q){n===k&&r._setMicStatus(I,t);var i=window.SpeechRecognition;if(r._micInstance)return void r._stopMic();r._micInstance=new i,r._micInstance.continuous=!0,r._micInstance.interimResults=!0,Object.assign(r._micInstance,e),r._micInstance.start(),r._micInstance.onstart=function(){r._setMicStatus(k,t)},r._micInstance.onresult=function(e){var n=e.results;n&&n[0]&&n[0].isFinal&&r._stopMic(),r._handleVoiceResults({results:n},t)},r._micInstance.onerror=function(e){"no-speech"===e.error||"audio-capture"===e.error?r._setMicStatus(I,t):"not-allowed"===e.error&&r._setMicStatus(Q,t),console.error(e)}}})),n(o(r),"setDataField",(function(e,t){void 0===t&&(t=O);var n=r.dataField;r.dataField=e,r._applyOptions(t,"dataField",n,e)})),n(o(r),"setParent",(function(e){r._parent=e})),n(o(r),"setValue",(function(e,t){void 0===t&&(t=O);var n=function(){var n=r.value;r.value=e,r._applyOptions(t,"value",n,r.value)};r.beforeValueChange?r.beforeValueChange(e).then(n).catch((function(e){console.warn("beforeValueChange rejected the promise with ",e)})):n()})),n(o(r),"setSize",(function(e,t){void 0===t&&(t=O);var n=r.size;r.size=e,r._applyOptions(t,"size",n,r.size)})),n(o(r),"setFrom",(function(e,t){void 0===t&&(t=O);var n=r.from;r.from=e,r._applyOptions(t,"from",n,r.from)})),n(o(r),"setFuzziness",(function(e,t){void 0===t&&(t=O);var n=r.fuzziness;r.fuzziness=e,r._applyOptions(t,"fuzziness",n,r.fuzziness)})),n(o(r),"setIncludeFields",(function(e,t){void 0===t&&(t=O);var n=r.includeFields;r.includeFields=e,r._applyOptions(t,"includeFields",n,e)})),n(o(r),"setExcludeFields",(function(e,t){void 0===t&&(t=O);var n=r.excludeFields;r.excludeFields=e,r._applyOptions(t,"excludeFields",n,e)})),n(o(r),"setSortBy",(function(e,t){void 0===t&&(t=O);var n=r.sortBy;r.sortBy=e,r._applyOptions(t,"sortBy",n,e)})),n(o(r),"setReact",(function(e,t){void 0===t&&(t=O);var n=r.react;r.react=e,r._applyOptions(t,"react",n,e)})),n(o(r),"setDefaultQuery",(function(e,t){void 0===t&&(t=O);var n=r.defaultQuery;r.defaultQuery=e,r._applyOptions(t,"defaultQuery",n,e)})),n(o(r),"setCustomQuery",(function(e,t){void 0===t&&(t=O);var n=r.customQuery;r.customQuery=e,r._applyOptions(t,"customQuery",n,e)})),n(o(r),"setAfter",(function(e,t){void 0===t&&(t=O);var n=r.after;r.after=e,r.aggregationData.setAfterKey(e),r._applyOptions(t,"after",n,e)})),n(o(r),"triggerDefaultQuery",(function(e){if(void 0===e&&(e=x),q(r._query,r.componentQuery))return Promise.resolve(!0);var t=function(t){return r._setError(t,{stateChanges:e.stateChanges}),console.error(t),Promise.reject(t)};try{return r._updateQuery(),r._setRequestStatus(j),r._fetchRequest({query:Array.isArray(r.query)?r.query:[r.query],settings:r.appbaseSettings}).then((function(n){var s=r.results,a=n&&n[r.id],o=function(){a.aggregations&&r._handleAggregationResponse(a.aggregations,i({defaultOptions:O},e)),r._setRequestStatus(P),r._applyOptions({stateChanges:e.stateChanges},"results",s,r.results)};return r.type&&r.type!==m||!r.enablePopularSuggestions?(r._appendResults(a),o()):r._fetchRequest(r.getSuggestionsQuery(),!0).then((function(e){var t=e.DataSearch__suggestions;t&&t.hits&&t.hits.hits&&a.hits&&a.hits.hits&&(a.hits.hits=[].concat((t.hits.hits||[]).map((function(e){return i({},e,{_popular_suggestion:!0})})),a.hits.hits)),r._appendResults(a),o()})).catch(t),Promise.resolve(a)})).catch(t)}catch(e){return t(e)}})),n(o(r),"triggerCustomQuery",(function(e){void 0===e&&(e=x);var t=r._generateQuery(),n=t.requestBody,s=t.orderOfQueries;if(!n.length)return Promise.resolve({});if(q(r._query,n))return Promise.resolve(!0);var a=function(t){return r._setError(t,{stateChanges:e.stateChanges}),console.error(t),Promise.reject(t)};try{s.forEach((function(e){var t=r._parent.getComponent(e);t&&(t.setFrom(0,{stateChanges:!0,triggerDefaultQuery:!1,triggerCustomQuery:!1}),t.setAfter(void 0,{stateChanges:!0,triggerDefaultQuery:!1,triggerCustomQuery:!1}),r.clearOnQueryChange&&r._query&&t.setValue(void 0,{stateChanges:!0,triggerDefaultQuery:!1,triggerCustomQuery:!1}),t._setRequestStatus(j),t._updateQuery())}));var o=r._generateQuery().requestBody;return r._fetchRequest({query:o,settings:r.appbaseSettings}).then((function(t){return s.forEach((function(n){var s=r._parent.getComponent(n);if(s){s._setRequestStatus(P);var a=s.results,o=t&&t[n];o.hits&&(s.results.setRaw(o),s._applyOptions({stateChanges:e.stateChanges},"results",a,s.results)),o.aggregations&&s._handleAggregationResponse(o.aggregations,i({defaultOptions:O},e),!1)}})),Promise.resolve(t)})).catch(a)}catch(e){return a(e)}})),n(o(r),"recordClick",(function(e,t){void 0===t&&(t=!1),r._analyticsInstance&&r.queryId&&r._analyticsInstance.click({queryID:r.queryId,objects:e,isSuggestionClick:t})})),n(o(r),"recordConversions",(function(e){r._analyticsInstance&&r.queryId&&r._analyticsInstance.conversion({queryID:r.queryId,objects:e})})),n(o(r),"subscribeToStateChanges",(function(e,t){r.stateChanges.subscribe(e,t)})),n(o(r),"unsubscribeToStateChanges",(function(e){r.stateChanges.unsubscribe(e)})),n(o(r),"clearResults",(function(e){void 0===e&&(e=x);var t=r.results;r.results.setRaw({hits:{hits:[]}}),r._applyOptions({stateChanges:e.stateChanges},"results",t,r.results)})),n(o(r),"getRecentSearches",(function(e,t){void 0===e&&(e={size:5,minChars:3}),void 0===t&&(t=x);var n={headers:i({},r.headers)},s="",a=function(e,t){s+=s?"&"+e+"="+t:e+"="+t};return r.appbaseSettings&&r.appbaseSettings.userId&&a("user_id",r.appbaseSettings.userId),e&&(e.size&&a("size",String(e.size)),e.from&&a("from",e.from),e.to&&a("to",e.to),e.minChars&&a("min_chars",String(e.minChars)),e.customEvents&&Object.keys(e.customEvents).forEach((function(t){a(t,e.customEvents[t])}))),new Promise((function(e,i){fetch(r.url+"/_analytics/"+r._getSearchIndex()+"/recent-searches?"+s,n).then((function(n){return n.status>=500||n.status>=400?i(n):n.json().then((function(n){var i=r.recentSearches;r.recentSearches=n.map((function(e){return{label:e.key,value:e.key}})),r._applyOptions({stateChanges:t.stateChanges},"recentSearches",i,r.recentSearches),e(r.recentSearches)})).catch((function(e){return console.warn("SearchBase: error while fetching the recent searches ",e),i(e)}))})).catch((function(e){return console.warn("SearchBase: error while fetching the recent searches ",e),i(e)}))}))})),n(o(r),"_handleVoiceResults",(function(e,t){var n=e.results;void 0===t&&(t=O),n&&n[0]&&n[0].isFinal&&n[0][0]&&n[0][0].transcript&&n[0][0].transcript.trim()&&r.setValue(n[0][0].transcript.trim(),i({},t,{triggerCustomQuery:!0,triggerDefaultQuery:!0}))})),n(o(r),"_stopMic",(function(){r._micInstance&&(r._micInstance.stop(),r._micInstance=null,r._setMicStatus(I))})),n(o(r),"_setMicStatus",(function(e,t){void 0===t&&(t=O);var n=r._micStatus;r._micStatus=e,r._applyOptions(t,"micStatus",n,r._micStatus)}));var U=L.id,H=L.type,N=L.react,G=L.queryFormat,K=L.dataField,J=L.categoryField,X=L.categoryValue,W=L.nestedField,Y=L.from,Z=L.size,$=L.sortBy,ee=L.value,te=L.aggregationField,re=L.aggregationSize,ne=L.after,ie=L.includeNullValues,se=L.includeFields,ae=L.excludeFields,oe=L.fuzziness,ue=L.searchOperators,ce=L.highlight,he=L.highlightField,le=L.customHighlight,de=L.interval,fe=L.aggregations,ge=L.missingLabel,pe=L.showMissing,ye=L.defaultQuery,ve=L.customQuery,me=L.execute,be=L.enableSynonyms,_e=L.selectAllLabel,we=L.pagination,Se=L.queryString,Ce=L.distinctField,qe=L.distinctFieldConfig;if(!U)throw new Error(y.invalidComponentId);if(H&&H!==m){if(!K)throw new Error(y.invalidDataField);if(Array.isArray(K))throw new Error(y.dataFieldAsArray)}return r.id=U,r.type=H,r.react=N,r.queryFormat=G,r.dataField=K,r.categoryField=J,r.categoryValue=X,r.nestedField=W,r.from=Y,r.size=Z,r.sortBy=$,r.aggregationField=te,r.aggregationSize=re,r.after=ne,r.includeNullValues=ie,r.includeFields=se,r.excludeFields=ae,r.fuzziness=oe,r.searchOperators=ue,r.highlight=ce,r.highlightField=he,r.customHighlight=le,r.interval=de,r.aggregations=fe,r.missingLabel=ge,r.showMissing=pe,r.execute=me,r.enableSynonyms=be,r.selectAllLabel=_e,r.pagination=we,r.queryString=Se,r.defaultQuery=ye,r.customQuery=ve,r.beforeValueChange=p,r.onValueChange=v,r.onResults=b,r.onAggregationData=_,r.onError=w,r.onRequestStatusChange=S,r.onQueryChange=C,r.onMicStatusChange=D,r.distinctField=Ce,r.distinctFieldConfig=qe,r.enablePopularSuggestions=R,r.maxPopularSuggestions=F,r.showDistinctSuggestions=T,r.enablePredictiveSuggestions=z,r.preserveResults=V,r.clearOnQueryChange=M,r.stateChanges=new u,r.results=new A(B),r.aggregationData=new E,ee?r.setValue(ee,{stateChanges:!0}):r.value=ee,r}s(t,e);var c=t.prototype;return c.getSuggestionsQuery=function(){return{query:[{id:"DataSearch__suggestions",dataField:v,size:this.maxPopularSuggestions||5,value:this.value,defaultQuery:{query:{bool:{minimum_should_match:1,should:[{function_score:{field_value_factor:{field:"count",modifier:"sqrt",missing:1}}},{multi_match:{fields:["key^9","key.autosuggest^1","key.keyword^10"],fuzziness:0,operator:"or",query:this.value,type:"best_fields"}},{multi_match:{fields:["key^9","key.autosuggest^1","key.keyword^10"],operator:"or",query:this.value,type:"phrase"}},{multi_match:{fields:["key^9"],operator:"or",query:this.value,type:"phrase_prefix"}}]}}}}]}},c._appendResults=function(e){this.preserveResults&&e&&Array.isArray(e.hits&&e.hits.hits)&&Array.isArray(this.results.rawData&&this.results.rawData.hits&&this.results.rawData.hits.hits)?this.results.setRaw(i({},e,{hits:i({},e.hits,{hits:[].concat(this.results.rawData.hits.hits,e.hits.hits)})})):this.results.setRaw(e)},c._applyOptions=function(e,t,r,n){var i;("micStatus"===t&&this.onMicStatusChange&&this.onMicStatusChange(n,r),"query"===t&&this.onQueryChange&&this.onQueryChange(n,r),"value"===t&&this.onValueChange&&this.onValueChange(n,r),"error"===t&&this.onError&&this.onError(n),"results"===t&&this.onResults&&this.onResults(n,r),"aggregationData"===t&&this.onAggregationData&&this.onAggregationData(n,r),"requestStatus"===t&&this.onRequestStatusChange&&this.onRequestStatusChange(n,r),e.triggerDefaultQuery&&this.triggerDefaultQuery(),e.triggerCustomQuery&&this.triggerCustomQuery(),!1!==e.stateChanges)&&this.stateChanges.next(((i={})[t]={prev:r,next:n},i),t,this)},c._getSearchIndex=function(e){void 0===e&&(e=!1);var t=this.index;return e?t=".suggestions":this._parent&&this._parent.index&&(t=this._parent.index),t},c._fetchRequest=function(e,t){var r=this;void 0===t&&(t=!1);var n={method:"POST",body:JSON.stringify(e),headers:i({},this.headers)};return new Promise((function(e,s){r._handleTransformRequest(n).then((function(n){var a=Date.now(),o=r._getSearchIndex(t);return fetch(r.url+"/"+o+"/_reactivesearch.v3",n).then((function(t){var n=t.headers;if(t.headers){var o=t.headers.get("X-Search-Id");o&&(r._parent?r._parent.setQueryID(o):r.setQueryID(o))}return t.status>=500||t.status>=400?s(t):t.json().then((function(t){r._handleTransformResponse(t).then((function(t){t&&Object.prototype.hasOwnProperty.call(t,"error")&&s(t);var r=i({},t,{_timestamp:a,_headers:n});return e(r)})).catch((function(e){return console.warn("SearchBase: transformResponse rejected the promise with ",e),s(e)}))}))})).catch((function(e){return s(e)}))})).catch((function(e){return console.warn("SearchBase: transformRequest rejected the promise with ",e),s(e)}))}))},c._generateQuery=function(){var e=this;if(this._parent){var t=this._parent.getComponents(),r=[];Object.keys(t).forEach((function(n){var i=t[n];i&&i.react&&(S(i.react,n).indexOf(e.id)>-1&&r.push(n))}));var n={};return r.forEach((function(t){var r=e._parent.getComponent(t);r&&(n[t]=r.componentQuery,S(r.react,r.id).forEach((function(t){if(!n[t]){var r=e._parent.getComponent(t);if(r&&r.value){var i=r.componentQuery;i.execute=!1,n[t]=i}}})))})),{requestBody:Object.values(n),orderOfQueries:r}}return{requestBody:[],orderOfQueries:[]}},c._handleTransformResponse=function(e){return this.transformResponse&&"function"==typeof this.transformResponse?this.transformResponse(e):new Promise((function(t){return t(e)}))},c._handleTransformRequest=function(e){return this.transformRequest&&"function"==typeof this.transformRequest?this.transformRequest(e):new Promise((function(t){return t(e)}))},c._handleAggregationResponse=function(e,t,r){void 0===t&&(t=O),void 0===r&&(r=!0);var n=this.aggregationField;n||"string"!=typeof this.dataField||(n=this.dataField);var i=this.aggregationData;this.aggregationData.setRaw(e[n]),this.aggregationData.setData(n,e[n].buckets,this.preserveResults&&r),this._applyOptions({stateChanges:t.stateChanges},"aggregationData",i,this.aggregationData)},c._setError=function(e,t){void 0===t&&(t=O),this._setRequestStatus(B);var r=this.error;this.error=e,this._applyOptions(t,"error",r,this.error)},c._setRequestStatus=function(e){var t=this.requestStatus;this.requestStatus=e,this._applyOptions({stateChanges:!0},"requestStatus",t,this.requestStatus)},c._updateQuery=function(e){var t,r=this;t=i({},this._query);var n=[this.componentQuery];S(this.react,this.id).forEach((function(e){var t=r._parent.getComponent(e);if(t&&t.value){var i=t.componentQuery;i.execute=!1,n.push(i)}})),this._query=e||n,this._applyOptions({stateChanges:!1},"query",t,this._query)},r(t,[{key:"micStatus",get:function(){return this._micStatus}},{key:"micInstance",get:function(){return this._micInstance}},{key:"micActive",get:function(){return this._micStatus===k}},{key:"micInactive",get:function(){return this._micStatus===I}},{key:"micDenied",get:function(){return this._micStatus===Q}},{key:"query",get:function(){return this._query}},{key:"requestPending",get:function(){return this.requestStatus===j}},{key:"appbaseSettings",get:function(){var e=this.appbaseConfig||{};return{recordAnalytics:e.recordAnalytics,customEvents:e.customEvents,enableQueryRules:e.enableQueryRules,userId:e.userId}}},{key:"suggestions",get:function(){if(this.type&&this.type!==m)return[];if(this.results){var e=_(this.dataField)||[];return 0===e.length&&this.results.data&&Array.isArray(this.results.data)&&this.results.data.length>0&&this.results.data[0]&&(e=Object.keys(this.results.data[0]).filter((function(e){return!["_id","_click_id","_index","_score","_type"].includes(e)}))),this.enablePopularSuggestions&&(e=[].concat(e,v)),function(e,t,r,n,s){void 0===e&&(e=[]),void 0===r&&(r=""),void 0===n&&(n=!0),void 0===s&&(s=!1);var o=[],u=[],c=!1,h=r||"",l=function(e,t,r){if((c||h.trim().split(" ").some((function(t){return String(e).toLowerCase().includes(t)})))&&!u.includes(e)||r._promoted){var s=i({},{label:e,value:e,source:r});if(u=[].concat(u,[e]),o=[].concat(o,[s]),n)return!0}return!1},d=function e(t,r,i){if(void 0===r&&(r=""),void 0===i&&(i=t),"object"==typeof t){var s=r.split("."),a=t[s[0]];if(a)if(s.length>1){var o=r.substring(s[0].length+1);Array.isArray(a)?a.forEach((function(t){e(t,o,i)})):e(a,o,i)}else{var u=C(a);if(u){if(Array.isArray(u)){if(n)return u.some((function(e){return l(e,0,i)}));u.forEach((function(e){return l(e,0,i)}))}return l(u,0,i)}}}return!1},f=function(){n?t.forEach((function(t){e.some((function(e){return d(t,e)}))})):t.forEach((function(t){e.forEach((function(e){d(t,e)}))}))};f(),o.length<t.length&&!c&&(c=!0,f());var g,p,y,v,m,b;return s?(p=(g={predictiveSuggestions:o,currentValuePredictive:r,wordsToShowAfterHighlight:!0}).predictiveSuggestions,y=g.currentValuePredictive,v=g.wordsToShowAfterHighlight,m={},(b=y.trim())?p.reduce((function(e,t){var r=t.label,n=a(t,["label"]),s=(new DOMParser).parseFromString(r,"text/html").documentElement.textContent,o="^("+b+")\\w+",u=new RegExp(o,"i"),c=u.exec(s);if(c||(o="^("+b+")",c=(u=new RegExp(o,"i")).exec(s)),c){var h=s.slice(c.index,s.length),l=b+'<mark class="highlight-class">'+h.slice(b.length).split(" ").slice(0,v+1).join(" ")+"</mark>";return m[l]?e:(m[l]=1,[].concat(e,[i({label:l,isPredictiveSuggestion:!0},n)]))}return e}),[]):[]):o}(e,this.results.data,this.value,this.showDistinctSuggestions,this.enablePredictiveSuggestions).slice(0,this.size)}return[]}},{key:"componentQuery",get:function(){return{id:this.id,type:this.type,dataField:_(this.dataField),react:this.react,highlight:this.highlight,highlightField:_(this.highlightField),fuzziness:this.fuzziness,searchOperators:this.searchOperators,includeFields:this.includeFields,excludeFields:this.excludeFields,size:this.size,from:this.from,queryFormat:this.queryFormat,sortBy:this.sortBy,fieldWeights:w(this.dataField),includeNullValues:this.includeNullValues,aggregationField:this.aggregationField,aggregationSize:this.aggregationSize,categoryField:this.categoryField,missingLabel:this.missingLabel,showMissing:this.showMissing,nestedField:this.nestedField,interval:this.interval,customHighlight:this.customHighlight,customQuery:this.customQuery?this.customQuery(this):void 0,defaultQuery:this.defaultQuery?this.defaultQuery(this):void 0,value:this.value,categoryValue:this.categoryValue,after:this.after,aggregations:this.aggregations,enableSynonyms:this.enableSynonyms,selectAllLabel:this.selectAllLabel,pagination:this.pagination,queryString:this.queryString,distinctField:this.distinctField,distinctFieldConfig:this.distinctFieldConfig,index:this.index}}},{key:"queryId",get:function(){return this._parent&&this._parent._queryId?this._parent._queryId:this._queryId?this._queryId:""}},{key:"mappedProps",get:function(){var e=this,t={};return Object.keys(D).forEach((function(r){t[D[r]]=e[r]})),t}}]),t}(F),z=function(e){function t(t){var r,s=t.index,a=t.url,u=t.credentials,c=t.headers,h=t.appbaseConfig;return n(o(r=e.call(this,{index:s,url:a,credentials:u,headers:c,appbaseConfig:h})||this),"register",(function(e,t){if(!e)throw new Error(y.invalidComponentId);if(r._components[e])return r._components[e];var n=t;return!t||t instanceof T?n.id=e:n=new T(i({},t,{id:e,index:t.index||r.index,url:t.url||r.url,credentials:t.credentials||r.credentials,headers:t.headers||r.headers,transformRequest:t.transformRequest||r.transformRequest,transformResponse:t.transformResponse||r.transformResponse,appbaseConfig:t.appbaseConfig||r.appbaseConfig})),r._components[e]=n,n.setParent(o(r)),n})),n(o(r),"unregister",(function(e){e&&delete r._components[e]})),n(o(r),"getComponent",(function(e){return r._components[e]})),n(o(r),"getComponents",(function(){return r._components})),r._components={},r}return s(t,e),t}(F);e.SearchBase=z,e.SearchComponent=T,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=searchbase.umd.min.js.map |
{ | ||
"name": "@appbaseio/searchbase", | ||
"version": "1.3.0", | ||
"version": "1.3.2", | ||
"private": false, | ||
@@ -24,3 +24,3 @@ "description": "Headless core + common utilities for search", | ||
}, | ||
"author": "kuldepsaxena155@gmail.com", | ||
"author": "kuldepsaxena155@gmailcom", | ||
"license": "MIT", | ||
@@ -27,0 +27,0 @@ "bugs": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
292715
6835