@sajari/react-hooks
Advanced tools
Comparing version 1.4.12 to 1.4.13
# Change Log | ||
## 1.4.13 | ||
### Patch Changes | ||
- [`66761119`](https://github.com/sajari/sdk-react/commit/66761119165a94ec3a779e0c651ecfb77406dcba) [#490](https://github.com/sajari/sdk-react/pull/490) Thanks [@zlatanpham](https://github.com/zlatanpham)! - Add support `reset` all filters method. | ||
* [`2fc33184`](https://github.com/sajari/sdk-react/commit/2fc33184d950aaec616a80c24d7a5fa8a9963806) [#485](https://github.com/sajari/sdk-react/pull/485) Thanks [@tuanddd](https://github.com/tuanddd)! - Fix array match empty value where if using a FilterBuilder with the `group` option and not having any options selected the filter will produce a false string (`ARRAY_MATCH()` instead of `''`) | ||
## 1.4.12 | ||
@@ -4,0 +12,0 @@ |
@@ -5,2 +5,3 @@ import { Range, RangeFilterOptions } from './types'; | ||
private range; | ||
private aggregateMaxRange; | ||
private name; | ||
@@ -20,2 +21,3 @@ private group; | ||
set(range: Range | null, emitEvent?: boolean): void; | ||
getAggregateMaxRange(): Range | null; | ||
getName(): string; | ||
@@ -36,2 +38,3 @@ getGroup(): string | undefined; | ||
protected emitRangeUpdated(): void; | ||
private updateAggregateMaxRange; | ||
} |
@@ -37,2 +37,3 @@ import { isArray, roundToStep } from '@sajari/react-sdk-utils'; | ||
this.range = this.initial; | ||
this.aggregateMaxRange = this.initial; | ||
this.name = name; | ||
@@ -74,2 +75,3 @@ this.group = group; | ||
this.range = range ? this.formatter(range) : range; | ||
this.updateAggregateMaxRange(); | ||
@@ -81,2 +83,6 @@ if (emitEvent) { | ||
_proto.getAggregateMaxRange = function getAggregateMaxRange() { | ||
return this.aggregateMaxRange; | ||
}; | ||
_proto.getName = function getName() { | ||
@@ -101,2 +107,3 @@ return this.name; | ||
this.min = value; | ||
this.updateAggregateMaxRange(); | ||
} | ||
@@ -108,2 +115,3 @@ }; | ||
this.max = value; | ||
this.updateAggregateMaxRange(); | ||
} | ||
@@ -153,3 +161,9 @@ }; | ||
this.range = isArray(this.initial) ? [].concat(this.initial) : this.initial; | ||
if (isArray(this.initial)) { | ||
this.range = [].concat(this.initial); | ||
} else if (this.aggregate) { | ||
this.range = this.aggregateMaxRange; | ||
} else { | ||
this.range = this.initial; | ||
} | ||
@@ -173,2 +187,14 @@ if (emitEvent) { | ||
_proto.updateAggregateMaxRange = function updateAggregateMaxRange() { | ||
if (!this.range || !this.aggregate) { | ||
return; | ||
} | ||
var aggregateMaxRange = this.range[1] - this.range[0] > this.max - this.min ? this.range : [this.min, this.max]; | ||
if (!this.aggregateMaxRange || aggregateMaxRange[1] - aggregateMaxRange[0] > this.aggregateMaxRange[1] - this.aggregateMaxRange[0]) { | ||
this.aggregateMaxRange = aggregateMaxRange; | ||
} | ||
}; | ||
return RangeFilterBuilder; | ||
@@ -175,0 +201,0 @@ }(); |
import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js'; | ||
import { groupBy, isEmpty } from '@sajari/react-sdk-utils'; | ||
import { groupBy, isEmpty, isEmptyArray } from '@sajari/react-sdk-utils'; | ||
import FilterBuilder from './FilterBuilder.esm.js'; | ||
@@ -14,2 +14,6 @@ | ||
if (isEmptyArray(list)) { | ||
return ''; | ||
} | ||
return "ARRAY_MATCH(" + list.join(' AND ') + ")"; | ||
@@ -16,0 +20,0 @@ }; |
@@ -321,2 +321,10 @@ import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js'; | ||
var resetFilters = function resetFilters() { | ||
var _search$filters2; | ||
(_search$filters2 = search.filters) == null ? void 0 : _search$filters2.forEach(function (f) { | ||
return f == null ? void 0 : f.reset(); | ||
}); | ||
}; | ||
var getContext = function getContext(state) { | ||
@@ -332,2 +340,3 @@ var _autocomplete$current, _autocomplete$current2; | ||
clear: clear('search'), | ||
resetFilters: resetFilters, | ||
fields: search.fields, | ||
@@ -342,2 +351,3 @@ searching: searching | ||
clear: clear('autocomplete'), | ||
resetFilters: resetFilters, | ||
fields: (_autocomplete$current2 = autocomplete.current) == null ? void 0 : _autocomplete$current2.fields, | ||
@@ -344,0 +354,0 @@ searching: autocompleteSearching |
@@ -7,2 +7,3 @@ import { Config } from './Config'; | ||
}) => void; | ||
export declare type ResetFiltersFn = () => void; | ||
export declare type ResultClickedFn = (url: string) => void; | ||
@@ -20,2 +21,3 @@ export declare type PaginateFn = (page: number) => void; | ||
clear: ClearFn; | ||
resetFilters: ResetFiltersFn; | ||
fields?: FieldDictionary; | ||
@@ -22,0 +24,0 @@ searching: boolean; |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("@sajari/react-sdk-utils"),n=require("react"),i=e(n),r=require("@sajari/sdk-js"),s=e(require("js-cookie"));function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var a,c={qParam:"q",qOverrideParam:"q.override",qSuggestionsParam:"q.suggestions",resultsPerPageParam:"resultsPerPage",pageParam:"page",maxSuggestions:10},l=function(){function e(){this.listeners=[]}var t=e.prototype;return t.listen=function(e){var t=this;return this.listeners.push(e),function(){return t.unlisten(e)}},t.unlisten=function(e){var t=this.listeners.indexOf(e);t>=0&&this.listeners.splice(t,1)},t.notify=function(e){this.listeners.forEach((function(t){try{e(t)}catch(e){console&&console.error&&console.error(e)}}))},e}(),f=["page-close-analytics","body-reset-analytics","result-clicked-analytics"],p=function(){function e(e,n){var i,r=this;this.beforeunload=function(){r.enabled&&r.body&&(r.listeners.get("page-close-analytics").notify((function(e){e(r.body)})),r.enabled=!1)},this.resetBody=function(){r.enabled&&(r.listeners.get("body-reset-analytics").notify((function(e){e(r.body)})),r.longestNonAutocompletedBody="",r.longestAutocompletedBody="",r.enabled=!1)},this.responseUpdated=function(e){if(!e.isEmpty()&&!e.isError()){r.enabled=!0;var t=e.getQueryValues().get(r.bodyLabel)||"",n=e.getValues().get(r.bodyAutocompletedLabel)||t;r.body=n,t.length>=r.longestNonAutocompletedBody.length&&(r.longestNonAutocompletedBody=t,r.longestAutocompletedBody=n)}},this.resultClicked=function(){r.enabled&&r.body&&(r.listeners.get("result-clicked-analytics").notify((function(e){e(r.body)})),r.longestNonAutocompletedBody="",r.longestAutocompletedBody="",r.enabled=!1)},this.enabled=!1,this.body="",this.pipeline=e,this.tracking=n,this.listeners=new Map(Object.entries(((i={})["page-close-analytics"]=new l,i["body-reset-analytics"]=new l,i["result-clicked-analytics"]=new l,i))),this.longestNonAutocompletedBody="",this.longestAutocompletedBody="",this.bodyLabel="q",this.bodyAutocompletedLabel="q",t.isSSR()||window.addEventListener("beforeunload",this.beforeunload),this.pipeline.listen("response-updated",this.responseUpdated),this.pipeline.listen("result-clicked",this.resultClicked),this.tracking.listen("tracking-reset",this.resetBody)}return e.prototype.listen=function(e,t){if(-1===f.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},e}();!function(e){e.UniversalAnalytics="_ua",e.AnalyticsJS="ga",e.GTag="gtag"}(a||(a={}));var g={decodeUriArgs:function(e){var t={},n=e.split("&");for(var i in n)if(n.hasOwnProperty(i)){var r=n[i].split("=");t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t},encodeUriArgs:function(e){var t=[];return Object.keys(e).forEach((function(n){return t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]))})),t.join("&")},mergeQueryStr:function(e){for(var t=this,n="string"==typeof e?this.decodeUriArgs(e):e,i=arguments.length,r=new Array(i>1?i-1:0),s=1;s<i;s++)r[s-1]=arguments[s];return r.forEach((function(e){var i="string"==typeof e?t.decodeUriArgs(e):e;Object.keys(i).forEach((function(e){n[e]=i[e]}))})),this.encodeUriArgs(n)},augmentUri:function(e,t){var n=/^([^?]+)\?(.+)+$/.exec(e);return n?n[1]+"?"+this.mergeQueryStr(n[2],t):e+"?"+this.encodeUriArgs(t)},getURLParameter:function(e){var t=new RegExp("[?|&]"+e+"=([^&;]+?)(&|#|;|$)").exec(window.location.search)||[void 0,""];return decodeURIComponent(t[1].replace(/\+/g,"%20"))||null}},d=function(){function e(e,n,i){var r=this;void 0===i&&(i="q"),this.unregisterFunctions=[],this.detatch=function(){return r.unregisterFunctions.forEach((function(e){return e()}))},this.onBodyReset=function(e){return r.sendGAPageView(e)},this.onResultClicked=function(e){return r.sendGAPageView(e)},this.onPageClose=function(e){return r.sendGAPageView(e)},this.unregisterFunctions.push(e.listen("page-close-analytics",this.onPageClose)),this.unregisterFunctions.push(e.listen("body-reset-analytics",this.onBodyReset)),this.unregisterFunctions.push(e.listen("result-clicked-analytics",this.onResultClicked)),this.id=t.isSSR()?null:void 0!==n?n:t.isFunction(window[a.AnalyticsJS])?a.AnalyticsJS:t.isFunction(window[a.UniversalAnalytics])?a.UniversalAnalytics:t.isFunction(window[a.GTag])?a.GTag:null,this.param=i}return e.prototype.sendGAPageView=function(e){if(this.id&&!t.isSSR()&&t.isFunction(window[this.id])){var n,i=g.augmentUri(window.location.href.substring(window.location.origin.length),((n={})[this.param]=e,n));this.id===a.GTag?window[this.id]("event","page_view",{page_location:i}):window[this.id]("send","pageview",i)}},e}(),h=["selection-updated","options-updated"],v=function(){function e(e){var n,i=e.initial,r=void 0===i?[]:i,s=e.joinOperator,o=void 0===s?"OR":s,u=e.multi,a=void 0===u||u,c=e.options,f=void 0===c?{}:c,p=e.array,g=void 0!==p&&p,d=e.name,h=e.field,v=e.group,m=e.count,y=void 0===m?t.isEmpty(f):m;t.isString(r)&&(r=[r]),this.current=r,this.initial=r,this.name=d,this.group=v,this.field=h,this.count=y,this.options=f,this.multi=a,this.array=g,this.joinOperator=o,this.listeners=((n={})["selection-updated"]=new l,n["options-updated"]=new l,n)}var n=e.prototype;return n.listen=function(e,t){if(!h.includes(e))throw new Error('Unknown event type "'+e+'"');return this.listeners[e].listen(t)},n.set=function(e,t){var n=this;if(void 0===t&&(t=!1),t){var i=e.filter((function(e){return!n.current.includes(e)}));this.current=[].concat(this.current,i)}else this.current=e;this.emitSelectionUpdated()},n.remove=function(e){this.current=this.current.filter((function(t){return!e.includes(t)})),this.emitSelectionUpdated()},n.isSet=function(e){return this.current.includes(e)},n.setOptions=function(e,t){void 0===t&&(t=!1),this.options=t?o({},this.options,e):e,this.emitOptionsUpdated()},n.getName=function(){return this.name},n.getGroup=function(){return this.group},n.getField=function(){return this.field},n.getCount=function(){return this.count},n.getOptions=function(){return this.options},n.get=function(){return this.current},n.isArray=function(){return this.array},n.isMulti=function(){return this.multi},n.filter=function(){var e=this,n=this.current.map((function(n){var i=e.options[n];return t.isFunction(i)&&(i=i()),t.isEmpty(i)||(i=function(e){void 0===e&&(e="");var n=e;return[","].forEach((function(i){n=t.replaceAll(e,i,"\\"+i)})),n}(i)),e.count&&void 0===i&&n&&(i=e.array?e.field+' ~ ["'+n+'"]':e.field+' = "'+n+'"'),i})).filter(Boolean);return n.length<2?n.join(""):n.map((function(e){return"("+e+")"})).join(" "+this.joinOperator+" ")},n.getBuckets=function(){var e=this;return Object.entries(this.options).map((function(t){return e.name+"_"+t[0]+":"+t[1]})).join(",")},n.reset=function(){this.current=[].concat(this.initial),this.emitSelectionUpdated()},n.emitSelectionUpdated=function(){this.listeners["selection-updated"].notify((function(e){e()}))},n.emitOptionsUpdated=function(){this.listeners["options-updated"].notify((function(e){e()}))},e}(),m=["range-updated"],y=function(){function e(e){var n,i=e.field,r=e.name,s=e.group,o=e.aggregate,u=void 0===o||o,a=e.initial,c=e.min,f=void 0===c?0:c,p=e.max,g=void 0===p?u?0:100:p,d=e.step,h=void 0===d?1:d,v=e.formatter,m=void 0===v?function(e){return e.map((function(e){return t.roundToStep(e,h)}))}:v;this.initial=void 0===a?u?null:[f,g]:a,this.range=this.initial,this.name=r,this.group=s,this.field=i,this.formatter=m,this.min=f,this.max=g,this.step=h,this.frozen=!1,this.aggregate=u,this.listeners=((n={})["range-updated"]=new l,n)}var n=e.prototype;return n.listen=function(e,t){if(!m.includes(e))throw new Error('Unknown event type "'+e+'"');return this.listeners[e].listen(t)},n.get=function(){return this.range},n.set=function(e,t){void 0===t&&(t=!0),this.frozen||(this.range=e?this.formatter(e):e,t&&this.emitRangeUpdated())},n.getName=function(){return this.name},n.getGroup=function(){return this.group},n.getField=function(){return this.field},n.getFrozen=function(){return this.frozen},n.setMin=function(e){this.frozen||(this.min=e)},n.setMax=function(e){this.frozen||(this.max=e)},n.getMinMax=function(){return[this.min,this.max]},n.getStep=function(){return this.step},n.filter=function(){return this.range?this.field+" >= "+this.range[0]+" AND "+this.field+" <= "+this.range[1]:""},n.isAggregate=function(){return this.aggregate},n.setFrozen=function(e){this.frozen=e},n.hasChanged=function(){return this.range&&this.initial?this.range[0]!==this.initial[0]||this.range[1]!==this.initial[1]:this.range===this.initial},n.reset=function(e){void 0===e&&(e=!0),this.frozen||(this.range=t.isArray(this.initial)?[].concat(this.initial):this.initial,e&&this.emitRangeUpdated())},n.format=function(e){return this.formatter(e)},n.emitRangeUpdated=function(){var e=this;this.listeners["range-updated"].notify((function(t){t(e)}))},e}(),b=function(e){var t=e.filter(Boolean);return t.length>1&&(t=t.map((function(e){return"("+e+")"}))),"ARRAY_MATCH("+t.join(" AND ")+")"};function w(e,n,i){var r=e.map((function(e){return{group:e.getGroup(),field:e.getField(),expression:e.filter(),count:e instanceof v&&e.getCount()}}));"filter"===n&&(r=r.filter((function(e){return Boolean(e.expression)})));var s=Object.entries(t.groupBy(r,"group")).filter((function(e){return Boolean(e[0])})).reduce((function(e,t){var n;return o({},e,((n={})[t[0]]=t[1].map((function(e){return e.expression})),n))}),{});if("filter"===n){var u,a=r.filter((function(e){return!e.group&&!e.count})).map((function(e){return"("+e.expression+")"}));return(u=Object.entries(s).reduce((function(e,n){var i=n[1];return"undefined"===n[0]||t.isEmpty(i)?e:[].concat(e,[b(i)])}),[])).concat.apply(u,a).join(i)}return r.filter((function(e){var n=e.count;return!t.isEmpty(e.field)&&n})).map((function(e){var n=e.group,i=e.expression,r=e.count;return n&&!t.isEmpty(s[n])?b(s[n]):r?i:null})).filter((function(e){return null!==e})).join(i)}var E=["selection-updated","options-updated","range-updated"];function S(e,t){var n;void 0===t&&(t="AND");var i=((n={})["selection-updated"]=new l,n["options-updated"]=new l,n["range-updated"]=new l,n),r=[];return e.forEach((function(e){e instanceof v&&r.push(e.listen("selection-updated",(function(){i["selection-updated"].notify((function(t){t(e)}))})),e.listen("options-updated",(function(){i["options-updated"].notify((function(t){t(e)}))}))),e instanceof y&&r.push(e.listen("range-updated",(function(){i["range-updated"].notify((function(t){t(e)}))})))})),{filter:function(){return w(e,"filter"," "+t+" ")},listen:function(e,t){if(-1===E.indexOf(e))throw new Error('Unknown event type "'+e+'"');return i[e].listen(t)},buckets:function(){return e.filter((function(e){return e instanceof v&&!e.getCount()})).map((function(e){return e instanceof v&&e.getBuckets()})).filter(Boolean).join(",")},countFilters:function(){return w(e,"countFilters",",")},count:function(){return e.filter((function(e){return e instanceof v&&e.getCount()})).map((function(e){return e instanceof v&&e.getField()})).filter(Boolean).join(",")},removeChildFilterListeners:function(){r.forEach((function(e){return e()}))},max:function(){return e.filter((function(e){return e instanceof y&&e.isAggregate()})).map((function(e){return e.getField()})).join(",")},min:function(){return e.filter((function(e){return e instanceof y&&e.isAggregate()})).map((function(e){return e.getField()})).join(",")}}}var k=function(){function e(e,t,n,i){this.error=e,this.queryValues=t,this.response=n,this.values=i}var t=e.prototype;return t.isEmpty=function(){return null===this.error&&void 0===this.response&&void 0===this.values&&void 0===this.queryValues},t.isError=function(){return null!==this.error},t.getError=function(){return this.error},t.getQueryValues=function(){return this.queryValues},t.getResponse=function(){return this.response},t.getValues=function(){return this.values},t.getResults=function(){return void 0!==this.response?this.response.get("results"):void 0},t.getTotalResults=function(){return void 0!==this.response?this.response.get("totalResults"):void 0},t.getTime=function(){return void 0!==this.response?this.response.get("time"):void 0},t.getAggregates=function(){if(void 0!==this.response){var e=this.response.get("aggregates");if(void 0!==e)return e}},t.getAggregateFilters=function(){if(void 0!==this.response){var e=this.response.get("aggregateFilters");if(void 0!==e)return e}},e}(),P=["tracking-reset"],R=function(){function e(){var e;this.clientTracking=null,this.listeners=new Map(Object.entries(((e={})["tracking-reset"]=new l,e)))}var t=e.prototype;return t.listen=function(e,t){if(-1===P.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},t.emitTrackingReset=function(e){this.listeners.get("tracking-reset").notify((function(t){t(e)}))},t.reset=function(e){this.clientTracking.reset(),void 0!==e&&this.emitTrackingReset(e)},t.next=function(e){if(null===this.clientTracking)throw new Error("clientTracking is null");return this.clientTracking.next(e)},e}(),x=function(){var e={},t=s.get("_ga");t&&(e.ga=t);var n=s.get("sjID");return n&&(e.sjID=n),e},A=function(e){function t(t,n){var i;return void 0===t&&(t="url"),void 0===n&&(n="q"),(i=e.call(this)||this).field=t,i.clientTracking=new r.InteractiveSession(n,new r.DefaultSession(r.TrackingType.Click,i.field,x())),i}return u(t,e),t}(R),C=function(e){function t(){var t;return(t=e.call(this)||this).field="_id",t.clientTracking=new r.DefaultSession(r.TrackingType.None,t.field,x()),t}return u(t,e),t}(R),T=function(e){function t(t){var n;return void 0===t&&(t="url"),(n=e.call(this)||this).field=t,n.clientTracking=new r.DefaultSession(r.TrackingType.PosNeg,n.field,x()),n}return u(t,e),t}(R),O=["search-sent","response-updated","result-clicked"],U=function(){function e(e,n,i,s){var o=this;void 0===i&&(i=new C),void 0===s&&(s=[d]),this.response=new k(null);var u=e.account,a=e.collection,c=e.endpoint,f=e.key,g=e.secret;this.config=e;var h={name:void 0,version:void 0};t.isString(n)?h.name=n:"name"in n&&(h.name=n.name,h.version=n.version),this.client=t.isSSR()?new r.Client(u,a,c,f,g):new r.Client(u,a,c),this.pipeline=this.client.pipeline(h.name,h.version),this.tracking=i,this.listeners=new Map([["search-sent",new l],["response-updated",new l],["result-clicked",new l]]),this.searchCount=0,this.response=new k(null),this.analytics=new p(this,this.tracking),s.forEach((function(e){new e(o.analytics)}))}var n=e.prototype;return n.listen=function(e,t){if(-1===O.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},n._emitSearchSent=function(e){this.listeners.get("search-sent").notify((function(t){t(e)}))},n._emitResponseUpdated=function(e){this.listeners.get("response-updated").notify((function(t){t(e)}))},n.emitResultClicked=function(e){this.listeners.get("result-clicked").notify((function(t){t(e)}))},n.search=function(e){var t=this;this.searchCount+=1;var n=this.searchCount;this.pipeline.search(e,this.tracking.next(e)).then((function(i){var r=i[0],s=i[1];n<t.searchCount||(t.response=new k(null,new Map(Object.entries(e)),new Map(Object.entries(r)),new Map(Object.entries(s))))})).catch((function(i){console.error(i),n<t.searchCount||(t.response=new k(i,new Map(Object.entries(e)),void 0,void 0))})).finally((function(){t._emitResponseUpdated(t.response)})),this._emitSearchSent(e)},n.clearResponse=function(e){this.tracking.next(e),this.searchCount+=1,this.response=new k(null),this._emitResponseUpdated(this.response)},n.getResponse=function(){return this.response},n.getAnalytics=function(){return this.analytics},n.getClient=function(){return this.client},n.getTracking=function(){return this.tracking},e}(),j=function(){function e(e){var t;void 0===e&&(e={}),this.listeners=new Map([["values-changed",new l]]),this.variables=new Map(Object.entries(o(((t={})[c.qParam]="",t[c.resultsPerPageParam]=15,t),e)))}var t=e.prototype;return t.listen=function(e,t){if("values-changed"!==e)throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},t.set=function(e){this._set(e),this._emitUpdated(e)},t.get=function(){var e={};return this.variables.forEach((function(t,n){e[n]="function"==typeof t?t():Array.isArray(t)?t.join(","):String(t)})),e},t._emitUpdated=function(e){var t=this;this.listeners.get("values-changed").notify((function(n){return n(e,(function(e){return t._set(e)}))}))},t._set=function(e){var t=this;Object.keys(e).forEach((function(n){void 0===e[n]?t.variables.delete(n):t.variables.set(n,e[n])}))},e}(),N=function(e,t,n){var i=e&&t&&t.get(n.qParam)||"",r=[];return t&&(r=(t.get(n.qSuggestionsParam)||"").split(",").filter((function(e){return e.length>0})).slice(0,n.maxSuggestions)),{completion:i,query:e,suggestions:r}},_=function(e,t,n){var i=e.get()[t.qParam]||"",r=n.getValues();return N(i,r,t)},F=function(e,t,n){var i=e.get()[n.qParam]||"",r=t.getResponse().getValues();return N(i,r,n)},q=t.createContext({strict:!0,name:"PipelineContext"}),M=q[0],V=q[1],B={response:null,query:"",completion:"",suggestions:[],config:c},D=/\d+\s-\s\d+/gm,I=D.test.bind(D),L=new Intl.Collator(t.isSSR()?"en-US":window.navigator.language,{numeric:!0}),G=function(e,t,n){if(void 0===t&&(t="alpha"),void 0===n&&(n=!0),"none"===t)return e;var i="count"!==t;return[].concat(e).sort((function(e,t){var r=t[0],s=t[1],o=String(i?e[0]:e[1]),u=String(i?r:s);switch(!0){case[o,u].every(I):var a=o.split(" - ").map(Number)[0],c=u.split(" - ").map(Number)[0];return n?L.compare(String(a),String(c)):L.compare(String(c),String(a));case o.startsWith(">"):case u.startsWith("<"):return n?1:-1;case o.startsWith("<"):case u.startsWith(">"):return n?-1:1}return n?L.compare(String(o),String(u)):L.compare(String(u),String(o))}))};function z(e){void 0===e&&(e="search");var t=V(),i=t.paginate,r=t[e],s=r.response,o=r.config,u=null==s?void 0:s.getQueryValues(),a=(null==u?void 0:u.get(o.pageParam))?parseInt(u.get(o.pageParam),10):1,c=(null==u?void 0:u.get(o.resultsPerPageParam))?parseInt(null==u?void 0:u.get(o.resultsPerPageParam),10):15,l=(null==s?void 0:s.getTotalResults())||0,f=Math.ceil(l/c),p=n.useMemo((function(){return a<f}),[a,f]),g=n.useMemo((function(){return a>1}),[a]),d=n.useCallback((function(){return p&&i(a+1)}),[i,p]),h=n.useCallback((function(){return g&&i(a-1)}),[i,g]);return{page:a,pageCount:f,totalResults:l,setPage:i,resultsPerPage:c,hasNext:p,hasPrevious:g,nextPage:d,previousPage:h}}exports.ClickTracking=A,exports.EVENT_ANALYTICS_BODY_RESET="body-reset-analytics",exports.EVENT_ANALYTICS_PAGE_CLOSED="page-close-analytics",exports.EVENT_ANALYTICS_RESULT_CLICKED="result-clicked-analytics",exports.EVENT_OPTIONS_UPDATED="options-updated",exports.EVENT_RANGE_UPDATED="range-updated",exports.EVENT_RESPONSE_UPDATED="response-updated",exports.EVENT_RESULT_CLICKED="result-clicked",exports.EVENT_SEARCH_SENT="search-sent",exports.EVENT_SELECTION_UPDATED="selection-updated",exports.EVENT_TRACKING_RESET="tracking-reset",exports.EVENT_VALUES_UPDATED="values-changed",exports.FieldDictionary=function(e){var t=null!=e?e:{},n=t.id,i=t.url,r=void 0===i?"url":i,s=t.title,o=void 0===s?"title":s,u=t.subtitle,a=void 0===u?"url":u,c=t.description,l=void 0===c?"description":c,f=t.image,p=void 0===f?"image":f,g=t.price,d=void 0===g?"price":g,h=t.originalPrice,v=void 0===h?"originalPrice":h,m=t.rating,y=void 0===m?"rating":m;this.id=void 0===n?"_id":n,this.url=r,this.title=o,this.subtitle=a,this.description=l,this.image=p,this.price=d,this.originalPrice=v,this.rating=y},exports.FilterBuilder=v,exports.Pipeline=U,exports.PosNegTracking=T,exports.RangeFilterBuilder=y,exports.Response=k,exports.SearchProvider=function(e){var r,s,u=e.children,a=e.search,l=e.autocomplete,f=e.defaultFilter,p=e.searchOnLoad,g=function(e){if(!t.isString(e)||t.isEmpty(e))return null;var n=JSON.parse(e),i=n.queryValues,r=n.response,s=void 0===r?{}:r,o=n.values,u=void 0===o?{}:o;return new k(null,new Map(Object.entries(void 0===i?{}:i)),new Map(Object.entries(s)),new Map(Object.entries(u)))}(e.initialResponse),d=n.useState(!1),h=d[0],v=d[1],m=n.useState(!1),y=m[0],b=m[1],w=n.useState(o({},B,{response:g})),E=w[0],P=w[1],R=n.useState(B),x=R[0],A=R[1],C=n.useState(!1),T=C[0],O=C[1],N=n.useRef(),q=n.useRef(),V=n.useRef(l),D=n.useRef(null!=(r=a.variables)?r:new j),I=n.useRef(null!=(s=null==l?void 0:l.variables)?s:new j),L=a.pipeline.getResponse();if(L.isEmpty()&&null!==g&&(L=g),a.variables||T||Object.assign(a,{variables:D.current}),!l||l.variables||T||Object.assign(l,{variables:I.current}),!T){var G,z,Q,J=S(null!=(G=a.filters)?G:[]),Y=null!=(z=D.current.get().filter)?z:"",W=null!=(Q=null==f?void 0:f.toString())?Q:"";D.current.set({filter:function(){var e=J.filter();return[W,Y,t.isEmpty(e)?'_id != ""':e].filter(Boolean).join(" AND ")},countFilters:function(){return J.countFilters()},buckets:function(){return J.buckets()},count:function(){return J.count()},min:function(){return J.min()},max:function(){return J.max()}})}var K=n.useCallback((function(e){return function(t,n){var i;void 0===n&&(n=!1);var r="autocomplete"===e?V.current:a,s="autocomplete"===e?x:E,u="autocomplete"===e?q:N;("autocomplete"===e?b:v)(!0),P((function(e){return o({},e,{query:null!=t?t:e.query})}));var c=r.pipeline,l=r.variables,f=s.config,p=((i={})[f.qParam]=null!=t?t:l.get()[f.qParam],i[f.qOverrideParam]=void 0,i[f.pageParam]=void 0,i);n&&(p[f.qOverrideParam]="true"),l.set(p),u.current&&clearTimeout(u.current),u.current=setTimeout((function(){c.search(l.get())}),50)}}),[]);n.useEffect((function(){var e=o({},c,a.config);P((function(t){return o({},t,{response:L,query:D.current.get()[e.qParam]||"",config:e})})),A((function(e){return o({},e,{config:o({},c,a.config)})}));var t,n=[];if(a.filters){var i=S(a.filters);n.push(i.listen("selection-updated",(function(){return K("search")()})),i.listen("range-updated",(function(){return K("search")()})),i.removeChildFilterListeners)}if(n.push(a.pipeline.listen("response-updated",(function(e){var n;clearTimeout(t),t=setTimeout((function(){v(!1),P((function(t){return o({},t,{response:e},_(D.current,t.config,e))}))}),0===(null==(n=e.getResults())?void 0:n.length)?500:20)}))),n.push(D.current.listen("values-changed",(function(){return P((function(e){return o({},e,F(D.current,a.pipeline,e.config))}))}))),!V.current){var r=a.pipeline.config;V.current={pipeline:new U({account:r.account,collection:r.collection,endpoint:r.endpoint},"autocomplete"),variables:I.current}}return n.push(V.current.pipeline.listen("response-updated",(function(e){b(!1),A((function(t){return o({},t,{response:e},_(I.current,t.config,e))}))}))),n.push(I.current.listen("values-changed",(function(){return A((function(e){return o({},e,F(I.current,V.current.pipeline,e.config))}))}))),p&&a.pipeline.search(D.current.get()),O(!0),function(){n.forEach((function(e){return e()}))}}),[]);var H,$,X,Z=n.useCallback((function(e){return function(t){var n="autocomplete"===e?V.current:a,i=n.pipeline,r=n.variables;void 0!==t&&r.set(t),i.clearResponse(r.get())}}),[]),ee=n.useCallback((function(e){var t,n=a.pipeline,i=a.variables;i.set(((t={})[E.config.pageParam]=String(e),t)),v(!0),n.search(i.get())}),[a.pipeline,a.variables,E.config]),te=n.useCallback((function(e){return a.pipeline.emitResultClicked(e)}),[]);return i.createElement(M,{value:(H={autocomplete:x,search:E},o({},H,{search:o({},H.search,{variables:D.current,filters:a.filters,pipeline:a.pipeline,search:K("search"),clear:Z("search"),fields:a.fields,searching:h}),autocomplete:o({},H.autocomplete,{variables:I.current,filters:a.filters,pipeline:null==($=V.current)?void 0:$.pipeline,search:K("autocomplete"),clear:Z("autocomplete"),fields:null==(X=V.current)?void 0:X.fields,searching:y}),resultClicked:te,paginate:ee}))},u)},exports.Variables=j,exports.combineFilters=S,exports.useAutocomplete=function(){var e=V().autocomplete;return{suggestions:e.suggestions,search:e.search,completion:e.completion,searching:e.searching}},exports.useFilter=function(e,i){void 0===i&&(i={});var r=V().search,s=r.filters,u=void 0===s?[]:s,a=r.response,c=n.useMemo((function(){return u.filter((function(t){return t instanceof v&&t.getName()===e}))[0]}),[]);if(!c)throw new Error('Filter "'+e+"\" doesn't exist.");var l=n.useState(c.get()),f=l[0],p=l[1];n.useEffect((function(){var e=c.listen("selection-updated",(function(){p(c.get())}));return function(){e()}}),[]);var g=i.sort,d=void 0===g?"alpha":g,h=i.sortAscending,m=void 0===h?"count"!==d:h;return{options:n.useMemo((function(){if(!a||(null==a?void 0:a.isEmpty()))return[];var n=a.getAggregates(),i=a.getAggregateFilters(),r=c.getCount(),s=c.getField();if(r&&s){var u=c.isArray(),l={};if(!(l=((i||{})[s]||{}).count)){var f=((n||{})[s]||{}).count;l=void 0===f?{}:f}var p=G(Object.entries(l),d,m).map((function(e){var t=e[0];return{label:t,count:e[1],value:u?s+' ~ ["'+t+'"]':s+' = "'+t+'"'}}));return c.setOptions(p.reduce((function(e,t){var n;return o({},e,((n={})[t.label]=t.value,n))}),{})),p}return G(Object.entries(c.getOptions()),d,m).map((function(n){var i=n[0];return{label:i,value:n[1],count:function(e,n){var i,r,s,o,u;if(!e||(null==e?void 0:e.isEmpty()))return null;var a=0,c=e.getAggregates(),l=e.getAggregateFilters();return l&&Object.keys(null!=(i=null==(r=l.buckets)?void 0:r.count)?i:{}).includes(n)?a=l.buckets.count:c&&Object.keys(null!=(s=null==(o=c.buckets)?void 0:o.count)?s:{}).includes(n)&&(a=c.buckets.count),t.isNumber(a)?0:null!=(u=a[n])?u:0}(a,e+"_"+i)}}))}),[JSON.stringify(null==a?void 0:a.getResults())]),setSelected:function(e,t){void 0===t&&(t=!1),c.set(e,t)},selected:f,reset:function(){c.reset()},multi:c.isMulti()}},exports.usePagination=z,exports.useQuery=function(){var e=V().search,t=e.search,i=e.variables;return{query:e.query,setQuery:n.useCallback((function(e){i.set({q:e}),t(e)}),[t,i])}},exports.useRangeFilter=function(e){var i=V().search,r=i.filters,s=void 0===r?[]:r,o=i.response,u=i.query,a=n.useRef(null),c=n.useRef(!1),l=n.useMemo((function(){return s.filter((function(t){return t instanceof y&&t.getName()===e}))[0]}),[]),f=l.isAggregate(),p=l.getMinMax();if(!l)throw new Error('Filter "'+e+"\" doesn't exist.");var g=n.useState(l.get()),d=g[0],h=g[1],v=n.useState(p[0]),m=v[0],b=v[1],w=n.useState(p[1]),E=w[0],S=w[1];n.useEffect((function(){f&&null!==a.current&&l.reset(!1)}),[u]),n.useEffect((function(){var e=l.listen("range-updated",(function(){h(l.get())}));return function(){e()}}),[]);var k=n.useCallback((function(e){l.set(e)}),[]),P=n.useMemo((function(){return!!d&&(f?d[0]!==m||d[1]!==E:l.hasChanged())}),[d,m,E]);return n.useEffect((function(){if(f&&a.current!==u&&!l.getFrozen()){if(!o||(null==o?void 0:o.isEmpty()))return b(d?d[0]:p[0]),S(d?d[1]:p[1]),void(c.current=!1);var e=l.getField(),n=o.getAggregates(),i=o.getAggregateFilters(),r=0,s=0,g=(n||{})[e]||{},v=(i||{})[e]||{};t.isNullOrUndefined(v.min)?t.isNullOrUndefined(g.min)||(r=g.min):r=v.min,t.isNullOrUndefined(v.max)?t.isNullOrUndefined(g.max)||(s=g.max):s=v.max;var m=l.format([r,s]);s=m[1],b(r=m[0]),S(s),l.setMin(r),l.setMax(s),l.set([r,s],!1),h([r,s]),a.current=u}else a.current=u}),[JSON.stringify(null==o?void 0:o.getResults())]),{min:m,max:E,step:l.getStep(),setRange:k,range:d,reset:function(){f?l.set([].concat(l.getMinMax())):l.reset()},showReset:P}},exports.useResultsPerPage=function(){var e=V().search,i=e.search,r=e.config.resultsPerPageParam,s=e.variables,o=n.useCallback((function(e){var t;s.set(((t={})[r]=e,t)),i()}),[s,i]),u=parseInt(s.get()[r],10);return{resultsPerPage:t.isNumber(u)?u:15,setResultsPerPage:o}},exports.useSearch=function(e){return"object"==typeof e&&"pipeline"in e&&"variables"in e?(i=(t=e).pipeline,r=t.variables,u=(s=n.useState(!1))[0],a=s[1],l=n.useCallback((function(e){var t;a(!0),""===e?i.clearResponse(r.get()):(e&&r.set(((t={})[c.qParam]=e,t)),i.search(r.get()))}),[i,r]),p=(f=n.useState({search:l,error:null}))[0],g=f[1],n.useEffect((function(){return l(),i.listen("response-updated",(function(e){a(!1),g((function(t){return o({},t,{results:null==e?void 0:e.getResults(),latency:null==e?void 0:e.getTime(),totalResults:null==e?void 0:e.getTotalResults(),error:null==e?void 0:e.getError()})}))}))}),[]),n.useEffect((function(){return r.listen("values-changed",(function(){l()}))}),[]),o({},p,{searching:u})):function(e){var t=e.queryOverride,i=e.allowEmptySearch,r=void 0===i||i,s=n.useState(null),o=s[0],u=s[1],a=V(),c=a.search,l=c.searching,f=c.response,p=c.search,g=a.autocomplete,d=g.search,h=g.suggestions,v=null==f?void 0:f.getResults(),m=n.useCallback((function(e){return d(e)}),[]);return n.useEffect((function(){void 0!==t?(r||""!==t)&&p(t):p()}),[t]),n.useEffect((function(){var e,t;if(f)switch(!0){case f.isError():u(null!=(e=null==(t=f.getError())?void 0:t.error)?e:new Error("Something went wrong. Please try again."));break;case!f.isError():u(null)}}),[f]),{latency:null==f?void 0:f.getTime(),totalResults:null==f?void 0:f.getTotalResults(),suggestions:null!=h?h:[],results:v,search:p,searchInstant:m,searching:l,error:o}}(null!=e?e:{});var t,i,r,s,u,a,l,f,p,g},exports.useSearchContext=function(){var e,n,i,r=V().search,s=r.config,o=r.response,u=r.search,a=r.searching,c=r.fields,l=void 0===c?{}:c,f=r.clear,p=z("search"),g=p.page,d=p.resultsPerPage,h=p.totalResults,v=p.pageCount,m=p.setPage,y=(n=null==o?void 0:o.getResponse(),i={},n&&n.forEach((function(e,t){"string"!=typeof e&&"number"!=typeof e||(i[t]=e)})),i),b=null==o?void 0:o.getResults();return{empty:null!=(e=null==o?void 0:o.isEmpty())&&e,error:null==o?void 0:o.getError(),queryValues:null==o?void 0:o.getQueryValues(),latency:null==o?void 0:o.getTime(),page:g,resultsPerPage:d,totalResults:h,pageCount:v,setPage:m,search:u,results:b,response:y,searching:a,searched:!t.isNullOrUndefined(b),fields:l,config:s,clear:f}},exports.useSorting=function(){var e,t=V().search,i=t.search,r=t.variables,s=n.useCallback((function(e){r.set({sort:e}),i()}),[r,i]);return{sorting:null!=(e=r.get().sort)?e:"",setSorting:s}},exports.useTracking=function(){var e=V(),t=e.resultClicked;return{consumeInteractionToken:e.search.pipeline.getClient().interactionConsume,handleResultClicked:t}},exports.useVariables=function(){return{variables:V().search.variables}}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("@sajari/react-sdk-utils"),n=require("react"),i=e(n),r=require("@sajari/sdk-js"),s=e(require("js-cookie"));function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var a,c={qParam:"q",qOverrideParam:"q.override",qSuggestionsParam:"q.suggestions",resultsPerPageParam:"resultsPerPage",pageParam:"page",maxSuggestions:10},l=function(){function e(){this.listeners=[]}var t=e.prototype;return t.listen=function(e){var t=this;return this.listeners.push(e),function(){return t.unlisten(e)}},t.unlisten=function(e){var t=this.listeners.indexOf(e);t>=0&&this.listeners.splice(t,1)},t.notify=function(e){this.listeners.forEach((function(t){try{e(t)}catch(e){console&&console.error&&console.error(e)}}))},e}(),f=["page-close-analytics","body-reset-analytics","result-clicked-analytics"],g=function(){function e(e,n){var i,r=this;this.beforeunload=function(){r.enabled&&r.body&&(r.listeners.get("page-close-analytics").notify((function(e){e(r.body)})),r.enabled=!1)},this.resetBody=function(){r.enabled&&(r.listeners.get("body-reset-analytics").notify((function(e){e(r.body)})),r.longestNonAutocompletedBody="",r.longestAutocompletedBody="",r.enabled=!1)},this.responseUpdated=function(e){if(!e.isEmpty()&&!e.isError()){r.enabled=!0;var t=e.getQueryValues().get(r.bodyLabel)||"",n=e.getValues().get(r.bodyAutocompletedLabel)||t;r.body=n,t.length>=r.longestNonAutocompletedBody.length&&(r.longestNonAutocompletedBody=t,r.longestAutocompletedBody=n)}},this.resultClicked=function(){r.enabled&&r.body&&(r.listeners.get("result-clicked-analytics").notify((function(e){e(r.body)})),r.longestNonAutocompletedBody="",r.longestAutocompletedBody="",r.enabled=!1)},this.enabled=!1,this.body="",this.pipeline=e,this.tracking=n,this.listeners=new Map(Object.entries(((i={})["page-close-analytics"]=new l,i["body-reset-analytics"]=new l,i["result-clicked-analytics"]=new l,i))),this.longestNonAutocompletedBody="",this.longestAutocompletedBody="",this.bodyLabel="q",this.bodyAutocompletedLabel="q",t.isSSR()||window.addEventListener("beforeunload",this.beforeunload),this.pipeline.listen("response-updated",this.responseUpdated),this.pipeline.listen("result-clicked",this.resultClicked),this.tracking.listen("tracking-reset",this.resetBody)}return e.prototype.listen=function(e,t){if(-1===f.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},e}();!function(e){e.UniversalAnalytics="_ua",e.AnalyticsJS="ga",e.GTag="gtag"}(a||(a={}));var p={decodeUriArgs:function(e){var t={},n=e.split("&");for(var i in n)if(n.hasOwnProperty(i)){var r=n[i].split("=");t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t},encodeUriArgs:function(e){var t=[];return Object.keys(e).forEach((function(n){return t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]))})),t.join("&")},mergeQueryStr:function(e){for(var t=this,n="string"==typeof e?this.decodeUriArgs(e):e,i=arguments.length,r=new Array(i>1?i-1:0),s=1;s<i;s++)r[s-1]=arguments[s];return r.forEach((function(e){var i="string"==typeof e?t.decodeUriArgs(e):e;Object.keys(i).forEach((function(e){n[e]=i[e]}))})),this.encodeUriArgs(n)},augmentUri:function(e,t){var n=/^([^?]+)\?(.+)+$/.exec(e);return n?n[1]+"?"+this.mergeQueryStr(n[2],t):e+"?"+this.encodeUriArgs(t)},getURLParameter:function(e){var t=new RegExp("[?|&]"+e+"=([^&;]+?)(&|#|;|$)").exec(window.location.search)||[void 0,""];return decodeURIComponent(t[1].replace(/\+/g,"%20"))||null}},d=function(){function e(e,n,i){var r=this;void 0===i&&(i="q"),this.unregisterFunctions=[],this.detatch=function(){return r.unregisterFunctions.forEach((function(e){return e()}))},this.onBodyReset=function(e){return r.sendGAPageView(e)},this.onResultClicked=function(e){return r.sendGAPageView(e)},this.onPageClose=function(e){return r.sendGAPageView(e)},this.unregisterFunctions.push(e.listen("page-close-analytics",this.onPageClose)),this.unregisterFunctions.push(e.listen("body-reset-analytics",this.onBodyReset)),this.unregisterFunctions.push(e.listen("result-clicked-analytics",this.onResultClicked)),this.id=t.isSSR()?null:void 0!==n?n:t.isFunction(window[a.AnalyticsJS])?a.AnalyticsJS:t.isFunction(window[a.UniversalAnalytics])?a.UniversalAnalytics:t.isFunction(window[a.GTag])?a.GTag:null,this.param=i}return e.prototype.sendGAPageView=function(e){if(this.id&&!t.isSSR()&&t.isFunction(window[this.id])){var n,i=p.augmentUri(window.location.href.substring(window.location.origin.length),((n={})[this.param]=e,n));this.id===a.GTag?window[this.id]("event","page_view",{page_location:i}):window[this.id]("send","pageview",i)}},e}(),h=["selection-updated","options-updated"],v=function(){function e(e){var n,i=e.initial,r=void 0===i?[]:i,s=e.joinOperator,o=void 0===s?"OR":s,u=e.multi,a=void 0===u||u,c=e.options,f=void 0===c?{}:c,g=e.array,p=void 0!==g&&g,d=e.name,h=e.field,v=e.group,m=e.count,y=void 0===m?t.isEmpty(f):m;t.isString(r)&&(r=[r]),this.current=r,this.initial=r,this.name=d,this.group=v,this.field=h,this.count=y,this.options=f,this.multi=a,this.array=p,this.joinOperator=o,this.listeners=((n={})["selection-updated"]=new l,n["options-updated"]=new l,n)}var n=e.prototype;return n.listen=function(e,t){if(!h.includes(e))throw new Error('Unknown event type "'+e+'"');return this.listeners[e].listen(t)},n.set=function(e,t){var n=this;if(void 0===t&&(t=!1),t){var i=e.filter((function(e){return!n.current.includes(e)}));this.current=[].concat(this.current,i)}else this.current=e;this.emitSelectionUpdated()},n.remove=function(e){this.current=this.current.filter((function(t){return!e.includes(t)})),this.emitSelectionUpdated()},n.isSet=function(e){return this.current.includes(e)},n.setOptions=function(e,t){void 0===t&&(t=!1),this.options=t?o({},this.options,e):e,this.emitOptionsUpdated()},n.getName=function(){return this.name},n.getGroup=function(){return this.group},n.getField=function(){return this.field},n.getCount=function(){return this.count},n.getOptions=function(){return this.options},n.get=function(){return this.current},n.isArray=function(){return this.array},n.isMulti=function(){return this.multi},n.filter=function(){var e=this,n=this.current.map((function(n){var i=e.options[n];return t.isFunction(i)&&(i=i()),t.isEmpty(i)||(i=function(e){void 0===e&&(e="");var n=e;return[","].forEach((function(i){n=t.replaceAll(e,i,"\\"+i)})),n}(i)),e.count&&void 0===i&&n&&(i=e.array?e.field+' ~ ["'+n+'"]':e.field+' = "'+n+'"'),i})).filter(Boolean);return n.length<2?n.join(""):n.map((function(e){return"("+e+")"})).join(" "+this.joinOperator+" ")},n.getBuckets=function(){var e=this;return Object.entries(this.options).map((function(t){return e.name+"_"+t[0]+":"+t[1]})).join(",")},n.reset=function(){this.current=[].concat(this.initial),this.emitSelectionUpdated()},n.emitSelectionUpdated=function(){this.listeners["selection-updated"].notify((function(e){e()}))},n.emitOptionsUpdated=function(){this.listeners["options-updated"].notify((function(e){e()}))},e}(),m=["range-updated"],y=function(){function e(e){var n,i=e.field,r=e.name,s=e.group,o=e.aggregate,u=void 0===o||o,a=e.initial,c=e.min,f=void 0===c?0:c,g=e.max,p=void 0===g?u?0:100:g,d=e.step,h=void 0===d?1:d,v=e.formatter,m=void 0===v?function(e){return e.map((function(e){return t.roundToStep(e,h)}))}:v;this.initial=void 0===a?u?null:[f,p]:a,this.range=this.initial,this.aggregateMaxRange=this.initial,this.name=r,this.group=s,this.field=i,this.formatter=m,this.min=f,this.max=p,this.step=h,this.frozen=!1,this.aggregate=u,this.listeners=((n={})["range-updated"]=new l,n)}var n=e.prototype;return n.listen=function(e,t){if(!m.includes(e))throw new Error('Unknown event type "'+e+'"');return this.listeners[e].listen(t)},n.get=function(){return this.range},n.set=function(e,t){void 0===t&&(t=!0),this.frozen||(this.range=e?this.formatter(e):e,this.updateAggregateMaxRange(),t&&this.emitRangeUpdated())},n.getAggregateMaxRange=function(){return this.aggregateMaxRange},n.getName=function(){return this.name},n.getGroup=function(){return this.group},n.getField=function(){return this.field},n.getFrozen=function(){return this.frozen},n.setMin=function(e){this.frozen||(this.min=e,this.updateAggregateMaxRange())},n.setMax=function(e){this.frozen||(this.max=e,this.updateAggregateMaxRange())},n.getMinMax=function(){return[this.min,this.max]},n.getStep=function(){return this.step},n.filter=function(){return this.range?this.field+" >= "+this.range[0]+" AND "+this.field+" <= "+this.range[1]:""},n.isAggregate=function(){return this.aggregate},n.setFrozen=function(e){this.frozen=e},n.hasChanged=function(){return this.range&&this.initial?this.range[0]!==this.initial[0]||this.range[1]!==this.initial[1]:this.range===this.initial},n.reset=function(e){void 0===e&&(e=!0),this.frozen||(this.range=t.isArray(this.initial)?[].concat(this.initial):this.aggregate?this.aggregateMaxRange:this.initial,e&&this.emitRangeUpdated())},n.format=function(e){return this.formatter(e)},n.emitRangeUpdated=function(){var e=this;this.listeners["range-updated"].notify((function(t){t(e)}))},n.updateAggregateMaxRange=function(){if(this.range&&this.aggregate){var e=this.range[1]-this.range[0]>this.max-this.min?this.range:[this.min,this.max];(!this.aggregateMaxRange||e[1]-e[0]>this.aggregateMaxRange[1]-this.aggregateMaxRange[0])&&(this.aggregateMaxRange=e)}},e}(),b=function(e){var n=e.filter(Boolean);return n.length>1&&(n=n.map((function(e){return"("+e+")"}))),t.isEmptyArray(n)?"":"ARRAY_MATCH("+n.join(" AND ")+")"};function w(e,n,i){var r=e.map((function(e){return{group:e.getGroup(),field:e.getField(),expression:e.filter(),count:e instanceof v&&e.getCount()}}));"filter"===n&&(r=r.filter((function(e){return Boolean(e.expression)})));var s=Object.entries(t.groupBy(r,"group")).filter((function(e){return Boolean(e[0])})).reduce((function(e,t){var n;return o({},e,((n={})[t[0]]=t[1].map((function(e){return e.expression})),n))}),{});if("filter"===n){var u,a=r.filter((function(e){return!e.group&&!e.count})).map((function(e){return"("+e.expression+")"}));return(u=Object.entries(s).reduce((function(e,n){var i=n[1];return"undefined"===n[0]||t.isEmpty(i)?e:[].concat(e,[b(i)])}),[])).concat.apply(u,a).join(i)}return r.filter((function(e){var n=e.count;return!t.isEmpty(e.field)&&n})).map((function(e){var n=e.group,i=e.expression,r=e.count;return n&&!t.isEmpty(s[n])?b(s[n]):r?i:null})).filter((function(e){return null!==e})).join(i)}var E=["selection-updated","options-updated","range-updated"];function R(e,t){var n;void 0===t&&(t="AND");var i=((n={})["selection-updated"]=new l,n["options-updated"]=new l,n["range-updated"]=new l,n),r=[];return e.forEach((function(e){e instanceof v&&r.push(e.listen("selection-updated",(function(){i["selection-updated"].notify((function(t){t(e)}))})),e.listen("options-updated",(function(){i["options-updated"].notify((function(t){t(e)}))}))),e instanceof y&&r.push(e.listen("range-updated",(function(){i["range-updated"].notify((function(t){t(e)}))})))})),{filter:function(){return w(e,"filter"," "+t+" ")},listen:function(e,t){if(-1===E.indexOf(e))throw new Error('Unknown event type "'+e+'"');return i[e].listen(t)},buckets:function(){return e.filter((function(e){return e instanceof v&&!e.getCount()})).map((function(e){return e instanceof v&&e.getBuckets()})).filter(Boolean).join(",")},countFilters:function(){return w(e,"countFilters",",")},count:function(){return e.filter((function(e){return e instanceof v&&e.getCount()})).map((function(e){return e instanceof v&&e.getField()})).filter(Boolean).join(",")},removeChildFilterListeners:function(){r.forEach((function(e){return e()}))},max:function(){return e.filter((function(e){return e instanceof y&&e.isAggregate()})).map((function(e){return e.getField()})).join(",")},min:function(){return e.filter((function(e){return e instanceof y&&e.isAggregate()})).map((function(e){return e.getField()})).join(",")}}}var S=function(){function e(e,t,n,i){this.error=e,this.queryValues=t,this.response=n,this.values=i}var t=e.prototype;return t.isEmpty=function(){return null===this.error&&void 0===this.response&&void 0===this.values&&void 0===this.queryValues},t.isError=function(){return null!==this.error},t.getError=function(){return this.error},t.getQueryValues=function(){return this.queryValues},t.getResponse=function(){return this.response},t.getValues=function(){return this.values},t.getResults=function(){return void 0!==this.response?this.response.get("results"):void 0},t.getTotalResults=function(){return void 0!==this.response?this.response.get("totalResults"):void 0},t.getTime=function(){return void 0!==this.response?this.response.get("time"):void 0},t.getAggregates=function(){if(void 0!==this.response){var e=this.response.get("aggregates");if(void 0!==e)return e}},t.getAggregateFilters=function(){if(void 0!==this.response){var e=this.response.get("aggregateFilters");if(void 0!==e)return e}},e}(),k=["tracking-reset"],x=function(){function e(){var e;this.clientTracking=null,this.listeners=new Map(Object.entries(((e={})["tracking-reset"]=new l,e)))}var t=e.prototype;return t.listen=function(e,t){if(-1===k.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},t.emitTrackingReset=function(e){this.listeners.get("tracking-reset").notify((function(t){t(e)}))},t.reset=function(e){this.clientTracking.reset(),void 0!==e&&this.emitTrackingReset(e)},t.next=function(e){if(null===this.clientTracking)throw new Error("clientTracking is null");return this.clientTracking.next(e)},e}(),P=function(){var e={},t=s.get("_ga");t&&(e.ga=t);var n=s.get("sjID");return n&&(e.sjID=n),e},A=function(e){function t(t,n){var i;return void 0===t&&(t="url"),void 0===n&&(n="q"),(i=e.call(this)||this).field=t,i.clientTracking=new r.InteractiveSession(n,new r.DefaultSession(r.TrackingType.Click,i.field,P())),i}return u(t,e),t}(x),C=function(e){function t(){var t;return(t=e.call(this)||this).field="_id",t.clientTracking=new r.DefaultSession(r.TrackingType.None,t.field,P()),t}return u(t,e),t}(x),T=function(e){function t(t){var n;return void 0===t&&(t="url"),(n=e.call(this)||this).field=t,n.clientTracking=new r.DefaultSession(r.TrackingType.PosNeg,n.field,P()),n}return u(t,e),t}(x),O=["search-sent","response-updated","result-clicked"],U=function(){function e(e,n,i,s){var o=this;void 0===i&&(i=new C),void 0===s&&(s=[d]),this.response=new S(null);var u=e.account,a=e.collection,c=e.endpoint,f=e.key,p=e.secret;this.config=e;var h={name:void 0,version:void 0};t.isString(n)?h.name=n:"name"in n&&(h.name=n.name,h.version=n.version),this.client=t.isSSR()?new r.Client(u,a,c,f,p):new r.Client(u,a,c),this.pipeline=this.client.pipeline(h.name,h.version),this.tracking=i,this.listeners=new Map([["search-sent",new l],["response-updated",new l],["result-clicked",new l]]),this.searchCount=0,this.response=new S(null),this.analytics=new g(this,this.tracking),s.forEach((function(e){new e(o.analytics)}))}var n=e.prototype;return n.listen=function(e,t){if(-1===O.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},n._emitSearchSent=function(e){this.listeners.get("search-sent").notify((function(t){t(e)}))},n._emitResponseUpdated=function(e){this.listeners.get("response-updated").notify((function(t){t(e)}))},n.emitResultClicked=function(e){this.listeners.get("result-clicked").notify((function(t){t(e)}))},n.search=function(e){var t=this;this.searchCount+=1;var n=this.searchCount;this.pipeline.search(e,this.tracking.next(e)).then((function(i){var r=i[0],s=i[1];n<t.searchCount||(t.response=new S(null,new Map(Object.entries(e)),new Map(Object.entries(r)),new Map(Object.entries(s))))})).catch((function(i){console.error(i),n<t.searchCount||(t.response=new S(i,new Map(Object.entries(e)),void 0,void 0))})).finally((function(){t._emitResponseUpdated(t.response)})),this._emitSearchSent(e)},n.clearResponse=function(e){this.tracking.next(e),this.searchCount+=1,this.response=new S(null),this._emitResponseUpdated(this.response)},n.getResponse=function(){return this.response},n.getAnalytics=function(){return this.analytics},n.getClient=function(){return this.client},n.getTracking=function(){return this.tracking},e}(),j=function(){function e(e){var t;void 0===e&&(e={}),this.listeners=new Map([["values-changed",new l]]),this.variables=new Map(Object.entries(o(((t={})[c.qParam]="",t[c.resultsPerPageParam]=15,t),e)))}var t=e.prototype;return t.listen=function(e,t){if("values-changed"!==e)throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},t.set=function(e){this._set(e),this._emitUpdated(e)},t.get=function(){var e={};return this.variables.forEach((function(t,n){e[n]="function"==typeof t?t():Array.isArray(t)?t.join(","):String(t)})),e},t._emitUpdated=function(e){var t=this;this.listeners.get("values-changed").notify((function(n){return n(e,(function(e){return t._set(e)}))}))},t._set=function(e){var t=this;Object.keys(e).forEach((function(n){void 0===e[n]?t.variables.delete(n):t.variables.set(n,e[n])}))},e}(),N=function(e,t,n){var i=e&&t&&t.get(n.qParam)||"",r=[];return t&&(r=(t.get(n.qSuggestionsParam)||"").split(",").filter((function(e){return e.length>0})).slice(0,n.maxSuggestions)),{completion:i,query:e,suggestions:r}},_=function(e,t,n){var i=e.get()[t.qParam]||"",r=n.getValues();return N(i,r,t)},F=function(e,t,n){var i=e.get()[n.qParam]||"",r=t.getResponse().getValues();return N(i,r,n)},M=t.createContext({strict:!0,name:"PipelineContext"}),q=M[0],V=M[1],B={response:null,query:"",completion:"",suggestions:[],config:c},D=/\d+\s-\s\d+/gm,I=D.test.bind(D),L=new Intl.Collator(t.isSSR()?"en-US":window.navigator.language,{numeric:!0}),G=function(e,t,n){if(void 0===t&&(t="alpha"),void 0===n&&(n=!0),"none"===t)return e;var i="count"!==t;return[].concat(e).sort((function(e,t){var r=t[0],s=t[1],o=String(i?e[0]:e[1]),u=String(i?r:s);switch(!0){case[o,u].every(I):var a=o.split(" - ").map(Number)[0],c=u.split(" - ").map(Number)[0];return n?L.compare(String(a),String(c)):L.compare(String(c),String(a));case o.startsWith(">"):case u.startsWith("<"):return n?1:-1;case o.startsWith("<"):case u.startsWith(">"):return n?-1:1}return n?L.compare(String(o),String(u)):L.compare(String(u),String(o))}))};function z(e){void 0===e&&(e="search");var t=V(),i=t.paginate,r=t[e],s=r.response,o=r.config,u=null==s?void 0:s.getQueryValues(),a=(null==u?void 0:u.get(o.pageParam))?parseInt(u.get(o.pageParam),10):1,c=(null==u?void 0:u.get(o.resultsPerPageParam))?parseInt(null==u?void 0:u.get(o.resultsPerPageParam),10):15,l=(null==s?void 0:s.getTotalResults())||0,f=Math.ceil(l/c),g=n.useMemo((function(){return a<f}),[a,f]),p=n.useMemo((function(){return a>1}),[a]),d=n.useCallback((function(){return g&&i(a+1)}),[i,g]),h=n.useCallback((function(){return p&&i(a-1)}),[i,p]);return{page:a,pageCount:f,totalResults:l,setPage:i,resultsPerPage:c,hasNext:g,hasPrevious:p,nextPage:d,previousPage:h}}exports.ClickTracking=A,exports.EVENT_ANALYTICS_BODY_RESET="body-reset-analytics",exports.EVENT_ANALYTICS_PAGE_CLOSED="page-close-analytics",exports.EVENT_ANALYTICS_RESULT_CLICKED="result-clicked-analytics",exports.EVENT_OPTIONS_UPDATED="options-updated",exports.EVENT_RANGE_UPDATED="range-updated",exports.EVENT_RESPONSE_UPDATED="response-updated",exports.EVENT_RESULT_CLICKED="result-clicked",exports.EVENT_SEARCH_SENT="search-sent",exports.EVENT_SELECTION_UPDATED="selection-updated",exports.EVENT_TRACKING_RESET="tracking-reset",exports.EVENT_VALUES_UPDATED="values-changed",exports.FieldDictionary=function(e){var t=null!=e?e:{},n=t.id,i=t.url,r=void 0===i?"url":i,s=t.title,o=void 0===s?"title":s,u=t.subtitle,a=void 0===u?"url":u,c=t.description,l=void 0===c?"description":c,f=t.image,g=void 0===f?"image":f,p=t.price,d=void 0===p?"price":p,h=t.originalPrice,v=void 0===h?"originalPrice":h,m=t.rating,y=void 0===m?"rating":m;this.id=void 0===n?"_id":n,this.url=r,this.title=o,this.subtitle=a,this.description=l,this.image=g,this.price=d,this.originalPrice=v,this.rating=y},exports.FilterBuilder=v,exports.Pipeline=U,exports.PosNegTracking=T,exports.RangeFilterBuilder=y,exports.Response=S,exports.SearchProvider=function(e){var r,s,u=e.children,a=e.search,l=e.autocomplete,f=e.defaultFilter,g=e.searchOnLoad,p=function(e){if(!t.isString(e)||t.isEmpty(e))return null;var n=JSON.parse(e),i=n.queryValues,r=n.response,s=void 0===r?{}:r,o=n.values,u=void 0===o?{}:o;return new S(null,new Map(Object.entries(void 0===i?{}:i)),new Map(Object.entries(s)),new Map(Object.entries(u)))}(e.initialResponse),d=n.useState(!1),h=d[0],v=d[1],m=n.useState(!1),y=m[0],b=m[1],w=n.useState(o({},B,{response:p})),E=w[0],k=w[1],x=n.useState(B),P=x[0],A=x[1],C=n.useState(!1),T=C[0],O=C[1],N=n.useRef(),M=n.useRef(),V=n.useRef(l),D=n.useRef(null!=(r=a.variables)?r:new j),I=n.useRef(null!=(s=null==l?void 0:l.variables)?s:new j),L=a.pipeline.getResponse();if(L.isEmpty()&&null!==p&&(L=p),a.variables||T||Object.assign(a,{variables:D.current}),!l||l.variables||T||Object.assign(l,{variables:I.current}),!T){var G,z,Q,J=R(null!=(G=a.filters)?G:[]),Y=null!=(z=D.current.get().filter)?z:"",W=null!=(Q=null==f?void 0:f.toString())?Q:"";D.current.set({filter:function(){var e=J.filter();return[W,Y,t.isEmpty(e)?'_id != ""':e].filter(Boolean).join(" AND ")},countFilters:function(){return J.countFilters()},buckets:function(){return J.buckets()},count:function(){return J.count()},min:function(){return J.min()},max:function(){return J.max()}})}var K=n.useCallback((function(e){return function(t,n){var i;void 0===n&&(n=!1);var r="autocomplete"===e?V.current:a,s="autocomplete"===e?P:E,u="autocomplete"===e?M:N;("autocomplete"===e?b:v)(!0),k((function(e){return o({},e,{query:null!=t?t:e.query})}));var c=r.pipeline,l=r.variables,f=s.config,g=((i={})[f.qParam]=null!=t?t:l.get()[f.qParam],i[f.qOverrideParam]=void 0,i[f.pageParam]=void 0,i);n&&(g[f.qOverrideParam]="true"),l.set(g),u.current&&clearTimeout(u.current),u.current=setTimeout((function(){c.search(l.get())}),50)}}),[]);n.useEffect((function(){var e=o({},c,a.config);k((function(t){return o({},t,{response:L,query:D.current.get()[e.qParam]||"",config:e})})),A((function(e){return o({},e,{config:o({},c,a.config)})}));var t,n=[];if(a.filters){var i=R(a.filters);n.push(i.listen("selection-updated",(function(){return K("search")()})),i.listen("range-updated",(function(){return K("search")()})),i.removeChildFilterListeners)}if(n.push(a.pipeline.listen("response-updated",(function(e){var n;clearTimeout(t),t=setTimeout((function(){v(!1),k((function(t){return o({},t,{response:e},_(D.current,t.config,e))}))}),0===(null==(n=e.getResults())?void 0:n.length)?500:20)}))),n.push(D.current.listen("values-changed",(function(){return k((function(e){return o({},e,F(D.current,a.pipeline,e.config))}))}))),!V.current){var r=a.pipeline.config;V.current={pipeline:new U({account:r.account,collection:r.collection,endpoint:r.endpoint},"autocomplete"),variables:I.current}}return n.push(V.current.pipeline.listen("response-updated",(function(e){b(!1),A((function(t){return o({},t,{response:e},_(I.current,t.config,e))}))}))),n.push(I.current.listen("values-changed",(function(){return A((function(e){return o({},e,F(I.current,V.current.pipeline,e.config))}))}))),g&&a.pipeline.search(D.current.get()),O(!0),function(){n.forEach((function(e){return e()}))}}),[]);var H,$,X,Z=n.useCallback((function(e){return function(t){var n="autocomplete"===e?V.current:a,i=n.pipeline,r=n.variables;void 0!==t&&r.set(t),i.clearResponse(r.get())}}),[]),ee=n.useCallback((function(e){var t,n=a.pipeline,i=a.variables;i.set(((t={})[E.config.pageParam]=String(e),t)),v(!0),n.search(i.get())}),[a.pipeline,a.variables,E.config]),te=n.useCallback((function(e){return a.pipeline.emitResultClicked(e)}),[]),ne=function(){var e;null==(e=a.filters)||e.forEach((function(e){return null==e?void 0:e.reset()}))};return i.createElement(q,{value:(H={autocomplete:P,search:E},o({},H,{search:o({},H.search,{variables:D.current,filters:a.filters,pipeline:a.pipeline,search:K("search"),clear:Z("search"),resetFilters:ne,fields:a.fields,searching:h}),autocomplete:o({},H.autocomplete,{variables:I.current,filters:a.filters,pipeline:null==($=V.current)?void 0:$.pipeline,search:K("autocomplete"),clear:Z("autocomplete"),resetFilters:ne,fields:null==(X=V.current)?void 0:X.fields,searching:y}),resultClicked:te,paginate:ee}))},u)},exports.Variables=j,exports.combineFilters=R,exports.useAutocomplete=function(){var e=V().autocomplete;return{suggestions:e.suggestions,search:e.search,completion:e.completion,searching:e.searching}},exports.useFilter=function(e,i){void 0===i&&(i={});var r=V().search,s=r.filters,u=void 0===s?[]:s,a=r.response,c=n.useMemo((function(){return u.filter((function(t){return t instanceof v&&t.getName()===e}))[0]}),[]);if(!c)throw new Error('Filter "'+e+"\" doesn't exist.");var l=n.useState(c.get()),f=l[0],g=l[1];n.useEffect((function(){var e=c.listen("selection-updated",(function(){g(c.get())}));return function(){e()}}),[]);var p=i.sort,d=void 0===p?"alpha":p,h=i.sortAscending,m=void 0===h?"count"!==d:h;return{options:n.useMemo((function(){if(!a||(null==a?void 0:a.isEmpty()))return[];var n=a.getAggregates(),i=a.getAggregateFilters(),r=c.getCount(),s=c.getField();if(r&&s){var u=c.isArray(),l={};if(!(l=((i||{})[s]||{}).count)){var f=((n||{})[s]||{}).count;l=void 0===f?{}:f}var g=G(Object.entries(l),d,m).map((function(e){var t=e[0];return{label:t,count:e[1],value:u?s+' ~ ["'+t+'"]':s+' = "'+t+'"'}}));return c.setOptions(g.reduce((function(e,t){var n;return o({},e,((n={})[t.label]=t.value,n))}),{})),g}return G(Object.entries(c.getOptions()),d,m).map((function(n){var i=n[0];return{label:i,value:n[1],count:function(e,n){var i,r,s,o,u;if(!e||(null==e?void 0:e.isEmpty()))return null;var a=0,c=e.getAggregates(),l=e.getAggregateFilters();return l&&Object.keys(null!=(i=null==(r=l.buckets)?void 0:r.count)?i:{}).includes(n)?a=l.buckets.count:c&&Object.keys(null!=(s=null==(o=c.buckets)?void 0:o.count)?s:{}).includes(n)&&(a=c.buckets.count),t.isNumber(a)?0:null!=(u=a[n])?u:0}(a,e+"_"+i)}}))}),[JSON.stringify(null==a?void 0:a.getResults())]),setSelected:function(e,t){void 0===t&&(t=!1),c.set(e,t)},selected:f,reset:function(){c.reset()},multi:c.isMulti()}},exports.usePagination=z,exports.useQuery=function(){var e=V().search,t=e.search,i=e.variables;return{query:e.query,setQuery:n.useCallback((function(e){i.set({q:e}),t(e)}),[t,i])}},exports.useRangeFilter=function(e){var i=V().search,r=i.filters,s=void 0===r?[]:r,o=i.response,u=i.query,a=n.useRef(null),c=n.useRef(!1),l=n.useMemo((function(){return s.filter((function(t){return t instanceof y&&t.getName()===e}))[0]}),[]),f=l.isAggregate(),g=l.getMinMax();if(!l)throw new Error('Filter "'+e+"\" doesn't exist.");var p=n.useState(l.get()),d=p[0],h=p[1],v=n.useState(g[0]),m=v[0],b=v[1],w=n.useState(g[1]),E=w[0],R=w[1];n.useEffect((function(){f&&null!==a.current&&l.reset(!1)}),[u]),n.useEffect((function(){var e=l.listen("range-updated",(function(){h(l.get())}));return function(){e()}}),[]);var S=n.useCallback((function(e){l.set(e)}),[]),k=n.useMemo((function(){return!!d&&(f?d[0]!==m||d[1]!==E:l.hasChanged())}),[d,m,E]);return n.useEffect((function(){if(f&&a.current!==u&&!l.getFrozen()){if(!o||(null==o?void 0:o.isEmpty()))return b(d?d[0]:g[0]),R(d?d[1]:g[1]),void(c.current=!1);var e=l.getField(),n=o.getAggregates(),i=o.getAggregateFilters(),r=0,s=0,p=(n||{})[e]||{},v=(i||{})[e]||{};t.isNullOrUndefined(v.min)?t.isNullOrUndefined(p.min)||(r=p.min):r=v.min,t.isNullOrUndefined(v.max)?t.isNullOrUndefined(p.max)||(s=p.max):s=v.max;var m=l.format([r,s]);s=m[1],b(r=m[0]),R(s),l.setMin(r),l.setMax(s),l.set([r,s],!1),h([r,s]),a.current=u}else a.current=u}),[JSON.stringify(null==o?void 0:o.getResults())]),{min:m,max:E,step:l.getStep(),setRange:S,range:d,reset:function(){f?l.set([].concat(l.getMinMax())):l.reset()},showReset:k}},exports.useResultsPerPage=function(){var e=V().search,i=e.search,r=e.config.resultsPerPageParam,s=e.variables,o=n.useCallback((function(e){var t;s.set(((t={})[r]=e,t)),i()}),[s,i]),u=parseInt(s.get()[r],10);return{resultsPerPage:t.isNumber(u)?u:15,setResultsPerPage:o}},exports.useSearch=function(e){return"object"==typeof e&&"pipeline"in e&&"variables"in e?(i=(t=e).pipeline,r=t.variables,u=(s=n.useState(!1))[0],a=s[1],l=n.useCallback((function(e){var t;a(!0),""===e?i.clearResponse(r.get()):(e&&r.set(((t={})[c.qParam]=e,t)),i.search(r.get()))}),[i,r]),g=(f=n.useState({search:l,error:null}))[0],p=f[1],n.useEffect((function(){return l(),i.listen("response-updated",(function(e){a(!1),p((function(t){return o({},t,{results:null==e?void 0:e.getResults(),latency:null==e?void 0:e.getTime(),totalResults:null==e?void 0:e.getTotalResults(),error:null==e?void 0:e.getError()})}))}))}),[]),n.useEffect((function(){return r.listen("values-changed",(function(){l()}))}),[]),o({},g,{searching:u})):function(e){var t=e.queryOverride,i=e.allowEmptySearch,r=void 0===i||i,s=n.useState(null),o=s[0],u=s[1],a=V(),c=a.search,l=c.searching,f=c.response,g=c.search,p=a.autocomplete,d=p.search,h=p.suggestions,v=null==f?void 0:f.getResults(),m=n.useCallback((function(e){return d(e)}),[]);return n.useEffect((function(){void 0!==t?(r||""!==t)&&g(t):g()}),[t]),n.useEffect((function(){var e,t;if(f)switch(!0){case f.isError():u(null!=(e=null==(t=f.getError())?void 0:t.error)?e:new Error("Something went wrong. Please try again."));break;case!f.isError():u(null)}}),[f]),{latency:null==f?void 0:f.getTime(),totalResults:null==f?void 0:f.getTotalResults(),suggestions:null!=h?h:[],results:v,search:g,searchInstant:m,searching:l,error:o}}(null!=e?e:{});var t,i,r,s,u,a,l,f,g,p},exports.useSearchContext=function(){var e,n,i,r=V().search,s=r.config,o=r.response,u=r.search,a=r.searching,c=r.fields,l=void 0===c?{}:c,f=r.clear,g=r.resetFilters,p=z("search"),d=p.page,h=p.resultsPerPage,v=p.totalResults,m=p.pageCount,y=p.setPage,b=(n=null==o?void 0:o.getResponse(),i={},n&&n.forEach((function(e,t){"string"!=typeof e&&"number"!=typeof e||(i[t]=e)})),i),w=null==o?void 0:o.getResults();return{empty:null!=(e=null==o?void 0:o.isEmpty())&&e,error:null==o?void 0:o.getError(),queryValues:null==o?void 0:o.getQueryValues(),latency:null==o?void 0:o.getTime(),page:d,resultsPerPage:h,totalResults:v,pageCount:m,setPage:y,search:u,results:w,response:b,searching:a,searched:!t.isNullOrUndefined(w),fields:l,config:s,clear:f,resetFilters:g}},exports.useSorting=function(){var e,t=V().search,i=t.search,r=t.variables,s=n.useCallback((function(e){r.set({sort:e}),i()}),[r,i]);return{sorting:null!=(e=r.get().sort)?e:"",setSorting:s}},exports.useTracking=function(){var e=V(),t=e.resultClicked;return{consumeInteractionToken:e.search.pipeline.getClient().interactionConsume,handleResultClicked:t}},exports.useVariables=function(){return{variables:V().search.variables}}; | ||
//# sourceMappingURL=react-hooks.cjs.production.min.js.map |
@@ -19,3 +19,4 @@ declare function useSearchContext(): { | ||
clear: import("../ContextProvider/types").ClearFn; | ||
resetFilters: import("../ContextProvider/types").ResetFiltersFn; | ||
}; | ||
export default useSearchContext; |
@@ -18,3 +18,4 @@ import { isNullOrUndefined } from '@sajari/react-sdk-utils'; | ||
fields = _useContext$search$fi === void 0 ? {} : _useContext$search$fi, | ||
clear = _useContext$search.clear; | ||
clear = _useContext$search.clear, | ||
resetFilters = _useContext$search.resetFilters; | ||
@@ -47,3 +48,4 @@ var _usePagination = usePagination('search'), | ||
config: config, | ||
clear: clear | ||
clear: clear, | ||
resetFilters: resetFilters | ||
}; | ||
@@ -50,0 +52,0 @@ } |
{ | ||
"name": "@sajari/react-hooks", | ||
"version": "1.4.12", | ||
"version": "1.4.13", | ||
"description": "Easy to use hooks that allow you to build a powerful search interface powered by Sajari using any component library.", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
620981
4705