react-instantsearch-core 7.29.0 → 7.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! React InstantSearch Core 7.29.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch Core 7.31.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
@@ -24,7 +24,7 @@
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
26
 
27
- var version$2 = '7.29.0';
27
+ var version$2 = '7.31.0';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -1507,6 +1507,12 @@
1507
1507
  * This doesn't contain any beta/hidden features.
1508
1508
  * @private
1509
1509
  */ SearchParameters.PARAMETERS = Object.keys(new SearchParameters());
1510
+ // Returns a finite number or null. Used to reject Infinity/-Infinity from parseFloat.
1511
+ function parseFiniteFloat(value) {
1512
+ var n = parseFloat(value);
1513
+ // global isFinite is safe here: n is always a number type (no string coercion risk)
1514
+ return isFinite(n) ? n : null;
1515
+ }
1510
1516
  /**
1511
1517
  * @private
1512
1518
  * @param {object} partialState full or part of a state
@@ -1532,8 +1538,18 @@
1532
1538
  var value = partialState[k];
1533
1539
  if (typeof value === 'string') {
1534
1540
  var parsedValue = parseFloat(value);
1535
- // global isNaN is ok to use here, value is only number or NaN
1536
- numbers[k] = isNaN(parsedValue) ? value : parsedValue;
1541
+ if (isNaN(parsedValue)) {
1542
+ // originally an unparseable string like "all", keep NaN
1543
+ numbers[k] = value;
1544
+ } else if (!isFinite(parsedValue)) {
1545
+ // Infinity/-Infinity — convert to null
1546
+ numbers[k] = null;
1547
+ } else {
1548
+ numbers[k] = parsedValue;
1549
+ }
1550
+ } else if (typeof value === 'number' && !isFinite(value)) {
1551
+ // Already-numeric Infinity — convert to null
1552
+ numbers[k] = null;
1537
1553
  }
1538
1554
  });
1539
1555
  // there's two formats of insideBoundingBox, we need to parse
@@ -1542,7 +1558,13 @@
1542
1558
  numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
1543
1559
  if (Array.isArray(geoRect)) {
1544
1560
  return geoRect.map(function(value) {
1545
- return parseFloat(value);
1561
+ if (typeof value === 'string') {
1562
+ return parseFiniteFloat(value);
1563
+ }
1564
+ if (typeof value === 'number' && !isFinite(value)) {
1565
+ return null;
1566
+ }
1567
+ return value;
1546
1568
  });
1547
1569
  }
1548
1570
  return geoRect;
@@ -1559,12 +1581,17 @@
1559
1581
  if (Array.isArray(v)) {
1560
1582
  return v.map(function(vPrime) {
1561
1583
  if (typeof vPrime === 'string') {
1562
- return parseFloat(vPrime);
1584
+ return parseFiniteFloat(vPrime);
1585
+ }
1586
+ if (typeof vPrime === 'number' && !isFinite(vPrime)) {
1587
+ return null;
1563
1588
  }
1564
1589
  return vPrime;
1565
1590
  });
1566
1591
  } else if (typeof v === 'string') {
1567
- return parseFloat(v);
1592
+ return parseFiniteFloat(v);
1593
+ } else if (typeof v === 'number' && !isFinite(v)) {
1594
+ return null;
1568
1595
  }
1569
1596
  return v;
1570
1597
  });
@@ -3892,7 +3919,7 @@
3892
3919
  function requireVersion() {
3893
3920
  if (hasRequiredVersion) return version$1;
3894
3921
  hasRequiredVersion = 1;
3895
- version$1 = '3.28.1';
3922
+ version$1 = '3.28.2';
3896
3923
  return version$1;
3897
3924
  }
3898
3925
 
@@ -5938,7 +5965,7 @@
5938
5965
  }
5939
5966
  }
5940
5967
 
5941
- var withUsage$s = createDocumentationMessageGenerator({
5968
+ var withUsage$t = createDocumentationMessageGenerator({
5942
5969
  name: 'configure',
5943
5970
  connector: true
5944
5971
  });
@@ -5954,7 +5981,7 @@
5954
5981
  var renderFn = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : noop, unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
5955
5982
  return function(widgetParams) {
5956
5983
  if (!widgetParams || !isPlainObject(widgetParams.searchParameters)) {
5957
- throw new Error(withUsage$s('The `searchParameters` option expects an object.'));
5984
+ throw new Error(withUsage$t('The `searchParameters` option expects an object.'));
5958
5985
  }
5959
5986
  var connectorState = {};
5960
5987
  function refine(helper) {
@@ -6535,13 +6562,13 @@
6535
6562
  }
6536
6563
  }
6537
6564
 
6538
- var withUsage$r = createDocumentationMessageGenerator({
6565
+ var withUsage$s = createDocumentationMessageGenerator({
6539
6566
  name: 'dynamic-widgets',
6540
6567
  connector: true
6541
6568
  });
6542
6569
  var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
6543
6570
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
6544
- checkRendering(renderFn, withUsage$r());
6571
+ checkRendering(renderFn, withUsage$s());
6545
6572
  return function(widgetParams) {
6546
6573
  var widgets = widgetParams.widgets, _widgetParams_maxValuesPerFacet = widgetParams.maxValuesPerFacet, maxValuesPerFacet = _widgetParams_maxValuesPerFacet === void 0 ? 20 : _widgetParams_maxValuesPerFacet, _widgetParams_facets = widgetParams.facets, facets = _widgetParams_facets === void 0 ? [
6547
6574
  '*'
@@ -6551,10 +6578,10 @@
6551
6578
  if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
6552
6579
  return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
6553
6580
  }))) {
6554
- throw new Error(withUsage$r('The `widgets` option expects an array of widgets.'));
6581
+ throw new Error(withUsage$s('The `widgets` option expects an array of widgets.'));
6555
6582
  }
6556
6583
  if (!Array.isArray(facets)) {
6557
- throw new Error(withUsage$r("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
6584
+ throw new Error(withUsage$s("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
6558
6585
  }
6559
6586
  var localWidgets = new Map();
6560
6587
  return {
@@ -6656,7 +6683,7 @@
6656
6683
  results: results
6657
6684
  });
6658
6685
  if (!Array.isArray(attributesToRender)) {
6659
- throw new Error(withUsage$r('The `transformItems` option expects a function that returns an Array.'));
6686
+ throw new Error(withUsage$s('The `transformItems` option expects a function that returns an Array.'));
6660
6687
  }
6661
6688
  return {
6662
6689
  attributesToRender: attributesToRender,
@@ -6838,7 +6865,7 @@
6838
6865
  };
6839
6866
  }
6840
6867
 
6841
- var withUsage$q = createDocumentationMessageGenerator({
6868
+ var withUsage$r = createDocumentationMessageGenerator({
6842
6869
  name: 'index-widget'
6843
6870
  });
6844
6871
  /**
@@ -6932,7 +6959,7 @@
6932
6959
  }
6933
6960
  var index = function index(widgetParams) {
6934
6961
  if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
6935
- throw new Error(withUsage$q('The `indexName` option is required.'));
6962
+ throw new Error(withUsage$r('The `indexName` option is required.'));
6936
6963
  }
6937
6964
  // When isolated=true, we use an empty string as the default indexName.
6938
6965
  // This is intentional: isolated indices do not require a real index name.
@@ -7022,7 +7049,7 @@
7022
7049
  addWidgets: function addWidgets(widgets) {
7023
7050
  var _this = this;
7024
7051
  if (!Array.isArray(widgets)) {
7025
- throw new Error(withUsage$q('The `addWidgets` method expects an array of widgets.'));
7052
+ throw new Error(withUsage$r('The `addWidgets` method expects an array of widgets.'));
7026
7053
  }
7027
7054
  var flatWidgets = widgets.reduce(function(acc, w) {
7028
7055
  return acc.concat(Array.isArray(w) ? w : [
@@ -7032,7 +7059,7 @@
7032
7059
  if (flatWidgets.some(function(widget) {
7033
7060
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
7034
7061
  })) {
7035
- throw new Error(withUsage$q('The widget definition expects a `render` and/or an `init` method.'));
7062
+ throw new Error(withUsage$r('The widget definition expects a `render` and/or an `init` method.'));
7036
7063
  }
7037
7064
  flatWidgets.forEach(function(widget) {
7038
7065
  widget.parent = _this;
@@ -7092,7 +7119,7 @@
7092
7119
  removeWidgets: function removeWidgets(widgets) {
7093
7120
  var _this = this;
7094
7121
  if (!Array.isArray(widgets)) {
7095
- throw new Error(withUsage$q('The `removeWidgets` method expects an array of widgets.'));
7122
+ throw new Error(withUsage$r('The `removeWidgets` method expects an array of widgets.'));
7096
7123
  }
7097
7124
  var flatWidgets = widgets.reduce(function(acc, w) {
7098
7125
  return acc.concat(Array.isArray(w) ? w : [
@@ -7102,7 +7129,7 @@
7102
7129
  if (flatWidgets.some(function(widget) {
7103
7130
  return typeof widget.dispose !== 'function';
7104
7131
  })) {
7105
- throw new Error(withUsage$q('The widget definition expects a `dispose` method.'));
7132
+ throw new Error(withUsage$r('The widget definition expects a `dispose` method.'));
7106
7133
  }
7107
7134
  localWidgets = localWidgets.filter(function(widget) {
7108
7135
  return flatWidgets.indexOf(widget) === -1;
@@ -9721,7 +9748,7 @@
9721
9748
  };
9722
9749
  }
9723
9750
 
9724
- var version = '4.93.0';
9751
+ var version = '4.95.0';
9725
9752
 
9726
9753
  function hydrateSearchClient(client, results) {
9727
9754
  if (!results) {
@@ -9856,7 +9883,7 @@
9856
9883
  });
9857
9884
  }
9858
9885
 
9859
- var withUsage$p = createDocumentationMessageGenerator({
9886
+ var withUsage$q = createDocumentationMessageGenerator({
9860
9887
  name: 'instantsearch'
9861
9888
  });
9862
9889
  function defaultCreateURL() {
@@ -9912,7 +9939,7 @@
9912
9939
  _this.setMaxListeners(100);
9913
9940
  var _options_indexName = options.indexName, indexName = _options_indexName === void 0 ? '' : _options_indexName, compositionID = options.compositionID, numberLocale = options.numberLocale, _options_initialUiState = options.initialUiState, initialUiState = _options_initialUiState === void 0 ? {} : _options_initialUiState, _options_routing = options.routing, routing = _options_routing === void 0 ? null : _options_routing, _options_insights = options.insights, insights = _options_insights === void 0 ? undefined : _options_insights, searchFunction = options.searchFunction, _options_stalledSearchDelay = options.stalledSearchDelay, stalledSearchDelay = _options_stalledSearchDelay === void 0 ? 200 : _options_stalledSearchDelay, _options_searchClient = options.searchClient, searchClient = _options_searchClient === void 0 ? null : _options_searchClient, _options_insightsClient = options.insightsClient, insightsClient = _options_insightsClient === void 0 ? null : _options_insightsClient, _options_onStateChange = options.onStateChange, onStateChange = _options_onStateChange === void 0 ? null : _options_onStateChange, _options_future1 = options.future, future = _options_future1 === void 0 ? _object_spread({}, INSTANTSEARCH_FUTURE_DEFAULTS, options.future || {}) : _options_future1;
9914
9941
  if (searchClient === null) {
9915
- throw new Error(withUsage$p('The `searchClient` option is required.'));
9942
+ throw new Error(withUsage$q('The `searchClient` option is required.'));
9916
9943
  }
9917
9944
  if (typeof searchClient.search !== 'function') {
9918
9945
  throw new Error("The `searchClient` must implement a `search` method.\n\nSee: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend-search/in-depth/backend-instantsearch/js/");
@@ -9921,7 +9948,7 @@
9921
9948
  searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
9922
9949
  }
9923
9950
  if (insightsClient && typeof insightsClient !== 'function') {
9924
- throw new Error(withUsage$p('The `insightsClient` option should be a function.'));
9951
+ throw new Error(withUsage$q('The `insightsClient` option should be a function.'));
9925
9952
  }
9926
9953
  _this.client = searchClient;
9927
9954
  _this.future = future;
@@ -10069,12 +10096,12 @@
10069
10096
  * @param widgets The array of widgets to add to InstantSearch.
10070
10097
  */ function addWidgets(widgets) {
10071
10098
  if (!Array.isArray(widgets)) {
10072
- throw new Error(withUsage$p('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
10099
+ throw new Error(withUsage$q('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
10073
10100
  }
10074
10101
  if (this.compositionID && widgets.some(function(w) {
10075
10102
  return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
10076
10103
  })) {
10077
- throw new Error(withUsage$p('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
10104
+ throw new Error(withUsage$q('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
10078
10105
  }
10079
10106
  this.mainIndex.addWidgets(widgets);
10080
10107
  return this;
@@ -10103,7 +10130,7 @@
10103
10130
  * The widgets must implement a `dispose()` method to clear their states.
10104
10131
  */ function removeWidgets(widgets) {
10105
10132
  if (!Array.isArray(widgets)) {
10106
- throw new Error(withUsage$p('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
10133
+ throw new Error(withUsage$q('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
10107
10134
  }
10108
10135
  this.mainIndex.removeWidgets(widgets);
10109
10136
  return this;
@@ -10117,7 +10144,7 @@
10117
10144
  */ function start() {
10118
10145
  var _this = this;
10119
10146
  if (this.started) {
10120
- throw new Error(withUsage$p('The `start` method has already been called once.'));
10147
+ throw new Error(withUsage$q('The `start` method has already been called once.'));
10121
10148
  }
10122
10149
  // This Helper is used for the queries, we don't care about its state. The
10123
10150
  // states are managed at the `index` level. We use this Helper to create
@@ -10319,7 +10346,7 @@
10319
10346
  var _this = this;
10320
10347
  var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
10321
10348
  if (!this.mainHelper) {
10322
- throw new Error(withUsage$p('The `start` method needs to be called before `setUiState`.'));
10349
+ throw new Error(withUsage$q('The `start` method needs to be called before `setUiState`.'));
10323
10350
  }
10324
10351
  // We refresh the index UI state to update the local UI state that the
10325
10352
  // main index passes to the function form of `setUiState`.
@@ -10356,7 +10383,7 @@
10356
10383
  value: function createURL() {
10357
10384
  var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
10358
10385
  if (!this.started) {
10359
- throw new Error(withUsage$p('The `start` method needs to be called before `createURL`.'));
10386
+ throw new Error(withUsage$q('The `start` method needs to be called before `createURL`.'));
10360
10387
  }
10361
10388
  return this._createURL(nextState);
10362
10389
  }
@@ -10365,7 +10392,7 @@
10365
10392
  key: "refresh",
10366
10393
  value: function refresh() {
10367
10394
  if (!this.mainHelper) {
10368
- throw new Error(withUsage$p('The `start` method needs to be called before `refresh`.'));
10395
+ throw new Error(withUsage$q('The `start` method needs to be called before `refresh`.'));
10369
10396
  }
10370
10397
  this.mainHelper.clearCache().search();
10371
10398
  }
@@ -11046,17 +11073,36 @@
11046
11073
  return bindEventForHits;
11047
11074
  }
11048
11075
 
11049
- var withUsage$o = createDocumentationMessageGenerator({
11076
+ function addQueryID(hits, queryID) {
11077
+ if (!queryID) {
11078
+ return hits;
11079
+ }
11080
+ return hits.map(function(hit) {
11081
+ return _object_spread_props(_object_spread({}, hit), {
11082
+ __queryID: queryID
11083
+ });
11084
+ });
11085
+ }
11086
+
11087
+ function addAbsolutePosition(hits, page, hitsPerPage) {
11088
+ return hits.map(function(hit, idx) {
11089
+ return _object_spread_props(_object_spread({}, hit), {
11090
+ __position: hitsPerPage * page + idx + 1
11091
+ });
11092
+ });
11093
+ }
11094
+
11095
+ var withUsage$p = createDocumentationMessageGenerator({
11050
11096
  name: 'autocomplete',
11051
11097
  connector: true
11052
11098
  });
11053
11099
  var connectAutocomplete = function connectAutocomplete(renderFn) {
11054
11100
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
11055
- checkRendering(renderFn, withUsage$o());
11101
+ checkRendering(renderFn, withUsage$p());
11056
11102
  return function(widgetParams) {
11057
11103
  var _ref = widgetParams || {}, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(indices) {
11058
11104
  return indices;
11059
- } : _ref_transformItems;
11105
+ } : _ref_transformItems, tmp = _ref.future, _ref1 = tmp === void 0 ? {} : tmp, _ref_undefinedEmptyQuery = _ref1.undefinedEmptyQuery, undefinedEmptyQuery = _ref_undefinedEmptyQuery === void 0 ? false : _ref_undefinedEmptyQuery;
11060
11106
  var connectorState = {};
11061
11107
  return {
11062
11108
  $$type: 'ais.autocomplete',
@@ -11092,7 +11138,7 @@
11092
11138
  }
11093
11139
  var sendEventMap = {};
11094
11140
  var indices = scopedResults.map(function(scopedResult) {
11095
- var _scopedResult_results, _scopedResult_results1;
11141
+ var _scopedResult_results;
11096
11142
  // We need to escape the hits because highlighting
11097
11143
  // exposes HTML tags to the end-user.
11098
11144
  if (scopedResult.results) {
@@ -11103,15 +11149,16 @@
11103
11149
  helper: scopedResult.helper,
11104
11150
  widgetType: _this.$$type
11105
11151
  });
11152
+ var hits = scopedResult.results ? addQueryID(addAbsolutePosition(scopedResult.results.hits, scopedResult.results.page, scopedResult.results.hitsPerPage), scopedResult.results.queryID) : [];
11106
11153
  return {
11107
11154
  indexId: scopedResult.indexId,
11108
11155
  indexName: ((_scopedResult_results = scopedResult.results) === null || _scopedResult_results === void 0 ? void 0 : _scopedResult_results.index) || '',
11109
- hits: ((_scopedResult_results1 = scopedResult.results) === null || _scopedResult_results1 === void 0 ? void 0 : _scopedResult_results1.hits) || [],
11156
+ hits: hits,
11110
11157
  results: scopedResult.results || {}
11111
11158
  };
11112
11159
  });
11113
11160
  return {
11114
- currentRefinement: state.query || '',
11161
+ currentRefinement: undefinedEmptyQuery ? state.query : state.query || '',
11115
11162
  indices: transformItems(indices).map(function(transformedIndex) {
11116
11163
  return _object_spread_props(_object_spread({}, transformedIndex), {
11117
11164
  sendEvent: sendEventMap[transformedIndex.indexId]
@@ -11123,8 +11170,8 @@
11123
11170
  },
11124
11171
  getWidgetUiState: function getWidgetUiState(uiState, param) {
11125
11172
  var searchParameters = param.searchParameters;
11126
- var query = searchParameters.query || '';
11127
- if (query === '' || uiState && uiState.query === query) {
11173
+ var query = undefinedEmptyQuery ? searchParameters.query : searchParameters.query || '';
11174
+ if (!query || query === '' || uiState && uiState.query === query) {
11128
11175
  return uiState;
11129
11176
  }
11130
11177
  return _object_spread_props(_object_spread({}, uiState), {
@@ -11134,7 +11181,7 @@
11134
11181
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, param) {
11135
11182
  var uiState = param.uiState;
11136
11183
  var parameters = {
11137
- query: uiState.query || ''
11184
+ query: undefinedEmptyQuery ? uiState.query : uiState.query || ''
11138
11185
  };
11139
11186
  if (!escapeHTML) {
11140
11187
  return searchParameters.setQueryParameters(parameters);
@@ -11160,20 +11207,20 @@
11160
11207
  return useConnector(connectAutocomplete, props, additionalWidgetProperties);
11161
11208
  }
11162
11209
 
11163
- var withUsage$n = createDocumentationMessageGenerator({
11210
+ var withUsage$o = createDocumentationMessageGenerator({
11164
11211
  name: 'breadcrumb',
11165
11212
  connector: true
11166
11213
  });
11167
11214
  var connectBreadcrumb = function connectBreadcrumb(renderFn) {
11168
11215
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
11169
- checkRendering(renderFn, withUsage$n());
11216
+ checkRendering(renderFn, withUsage$o());
11170
11217
  var connectorState = {};
11171
11218
  return function(widgetParams) {
11172
11219
  var _ref = widgetParams || {}, attributes = _ref.attributes, _ref_separator = _ref.separator, separator = _ref_separator === void 0 ? ' > ' : _ref_separator, _ref_rootPath = _ref.rootPath, rootPath = _ref_rootPath === void 0 ? null : _ref_rootPath, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
11173
11220
  return items;
11174
11221
  } : _ref_transformItems;
11175
11222
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
11176
- throw new Error(withUsage$n('The `attributes` option expects an array of strings.'));
11223
+ throw new Error(withUsage$o('The `attributes` option expects an array of strings.'));
11177
11224
  }
11178
11225
  var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
11179
11226
  function getRefinedState(state, facetValue) {
@@ -11509,12 +11556,81 @@
11509
11556
  return Promise.resolve(value);
11510
11557
  }
11511
11558
 
11559
+ var tryParseJson = function tryParseJson(value) {
11560
+ try {
11561
+ return JSON.parse(value);
11562
+ } catch (unused) {
11563
+ return undefined;
11564
+ }
11565
+ };
11566
+ var repairPartialJson = function repairPartialJson(value) {
11567
+ var repaired = value.trim();
11568
+ if (!repaired) {
11569
+ return repaired;
11570
+ }
11571
+ var inString = false;
11572
+ var isEscaped = false;
11573
+ var stack = [];
11574
+ for(var index = 0; index < repaired.length; index++){
11575
+ var char = repaired[index];
11576
+ if (inString) {
11577
+ if (isEscaped) {
11578
+ isEscaped = false;
11579
+ } else if (char === '\\') {
11580
+ isEscaped = true;
11581
+ } else if (char === '"') {
11582
+ inString = false;
11583
+ }
11584
+ continue;
11585
+ }
11586
+ if (char === '"') {
11587
+ inString = true;
11588
+ continue;
11589
+ }
11590
+ if (char === '{' || char === '[') {
11591
+ stack.push(char);
11592
+ continue;
11593
+ }
11594
+ if (char === '}' && stack[stack.length - 1] === '{') {
11595
+ stack.pop();
11596
+ continue;
11597
+ }
11598
+ if (char === ']' && stack[stack.length - 1] === '[') {
11599
+ stack.pop();
11600
+ }
11601
+ }
11602
+ if (inString && !isEscaped) {
11603
+ repaired += '"';
11604
+ }
11605
+ repaired = repaired.replace(RegExp(",\\s*$", "u"), '');
11606
+ if (stack.length > 0) {
11607
+ repaired += stack.reverse().map(function(opening) {
11608
+ return opening === '{' ? '}' : ']';
11609
+ }).join('');
11610
+ }
11611
+ return repaired.replace(RegExp(",\\s*([}\\]])", "gu"), '$1');
11612
+ };
11613
+ var parseToolInputDelta = function parseToolInputDelta(accumulatedRawInput, fallbackInput) {
11614
+ var normalized = accumulatedRawInput.trim();
11615
+ if (!normalized) {
11616
+ return fallbackInput;
11617
+ }
11618
+ var directParsed = tryParseJson(normalized);
11619
+ if (directParsed !== undefined) {
11620
+ return directParsed;
11621
+ }
11622
+ var repairedParsed = tryParseJson(repairPartialJson(normalized));
11623
+ if (repairedParsed !== undefined) {
11624
+ return repairedParsed;
11625
+ }
11626
+ return fallbackInput;
11627
+ };
11512
11628
  /**
11513
11629
  * Abstract base class for chat implementations.
11514
11630
  */ var AbstractChat = /*#__PURE__*/ function() {
11515
11631
  function AbstractChat(param) {
11516
11632
  var _this = this;
11517
- var _param_generateId = param.generateId, generateId$1 = _param_generateId === void 0 ? generateId : _param_generateId, _param_id = param.id, id = _param_id === void 0 ? generateId$1() : _param_id, transport = param.transport, state = param.state, onError = param.onError, onToolCall = param.onToolCall, onFinish = param.onFinish, onData = param.onData, sendAutomaticallyWhen = param.sendAutomaticallyWhen;
11633
+ var _param_generateId = param.generateId, generateId$1 = _param_generateId === void 0 ? generateId : _param_generateId, _param_id = param.id, id = _param_id === void 0 ? generateId$1() : _param_id, transport = param.transport, state = param.state, onError = param.onError, onToolCall = param.onToolCall, onFinish = param.onFinish, onData = param.onData, sendAutomaticallyWhen = param.sendAutomaticallyWhen, shouldRepairToolInput = param.shouldRepairToolInput;
11518
11634
  var _this1 = this;
11519
11635
  _class_call_check(this, AbstractChat);
11520
11636
  _define_property(this, "id", void 0);
@@ -11526,6 +11642,7 @@
11526
11642
  _define_property(this, "onFinish", void 0);
11527
11643
  _define_property(this, "onData", void 0);
11528
11644
  _define_property(this, "sendAutomaticallyWhen", void 0);
11645
+ _define_property(this, "shouldRepairToolInput", void 0);
11529
11646
  _define_property(this, "activeResponse", null);
11530
11647
  _define_property(this, "jobExecutor", new SerialJobExecutor());
11531
11648
  /**
@@ -11735,6 +11852,7 @@
11735
11852
  this.onFinish = onFinish;
11736
11853
  this.onData = onData;
11737
11854
  this.sendAutomaticallyWhen = sendAutomaticallyWhen;
11855
+ this.shouldRepairToolInput = shouldRepairToolInput;
11738
11856
  }
11739
11857
  _create_class(AbstractChat, [
11740
11858
  {
@@ -11837,6 +11955,7 @@
11837
11955
  // Track current text/reasoning part state
11838
11956
  var currentTextPartId;
11839
11957
  var currentReasoningPartId;
11958
+ var toolRawInputByCallId = {};
11840
11959
  // Promise chain for handling tool calls that return promises
11841
11960
  var pendingToolCall = Promise.resolve();
11842
11961
  return new Promise(function(resolve) {
@@ -11975,11 +12094,14 @@
11975
12094
  case 'tool-input-start':
11976
12095
  {
11977
12096
  if (!currentMessage) break;
12097
+ var initialRawInput = typeof chunk.input === 'string' ? chunk.input : chunk.input !== undefined ? JSON.stringify(chunk.input) : '';
12098
+ toolRawInputByCallId[chunk.toolCallId] = initialRawInput;
11978
12099
  var toolPart = {
11979
12100
  type: "tool-".concat(chunk.toolName),
11980
12101
  toolCallId: chunk.toolCallId,
11981
12102
  state: 'input-streaming',
11982
12103
  input: chunk.input,
12104
+ rawInput: initialRawInput || undefined,
11983
12105
  providerExecuted: chunk.providerExecuted
11984
12106
  };
11985
12107
  currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
@@ -11992,11 +12114,47 @@
11992
12114
  }
11993
12115
  case 'tool-input-delta':
11994
12116
  {
12117
+ var _ref, _ref1, _chunk_toolName, _ref2;
12118
+ var _existingPart_type, _this_shouldRepairToolInput, _this1;
12119
+ if (!currentMessage) break;
12120
+ var toolIndex = currentMessage.parts.findIndex(function(p) {
12121
+ return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
12122
+ });
12123
+ var existingPart = toolIndex >= 0 ? currentMessage.parts[toolIndex] : null;
12124
+ var previousRawInput = (_ref = (_ref1 = existingPart === null || existingPart === void 0 ? void 0 : existingPart.rawInput) !== null && _ref1 !== void 0 ? _ref1 : toolRawInputByCallId[chunk.toolCallId]) !== null && _ref !== void 0 ? _ref : '';
12125
+ var nextRawInput = "".concat(previousRawInput).concat(chunk.inputTextDelta);
12126
+ toolRawInputByCallId[chunk.toolCallId] = nextRawInput;
12127
+ var toolName = (_chunk_toolName = chunk.toolName) !== null && _chunk_toolName !== void 0 ? _chunk_toolName : existingPart === null || existingPart === void 0 ? void 0 : (_existingPart_type = existingPart.type) === null || _existingPart_type === void 0 ? void 0 : _existingPart_type.replace('tool-', '');
12128
+ var shouldRepair = toolName ? (_ref2 = (_this_shouldRepairToolInput = (_this1 = _this).shouldRepairToolInput) === null || _this_shouldRepairToolInput === void 0 ? void 0 : _this_shouldRepairToolInput.call(_this1, toolName)) !== null && _ref2 !== void 0 ? _ref2 : true : true;
12129
+ var parsedInput = shouldRepair ? parseToolInputDelta(nextRawInput, existingPart === null || existingPart === void 0 ? void 0 : existingPart.input) : existingPart === null || existingPart === void 0 ? void 0 : existingPart.input;
12130
+ var nextToolPart = _object_spread_props(_object_spread({}, existingPart !== null && existingPart !== void 0 ? existingPart : {
12131
+ type: "tool-".concat(chunk.toolName),
12132
+ toolCallId: chunk.toolCallId
12133
+ }), {
12134
+ state: 'input-streaming',
12135
+ input: parsedInput,
12136
+ rawInput: nextRawInput
12137
+ });
12138
+ if (toolIndex >= 0) {
12139
+ var updatedParts4 = _to_consumable_array(currentMessage.parts);
12140
+ updatedParts4[toolIndex] = nextToolPart;
12141
+ currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
12142
+ parts: updatedParts4
12143
+ });
12144
+ } else {
12145
+ currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
12146
+ parts: _to_consumable_array(currentMessage.parts).concat([
12147
+ nextToolPart
12148
+ ])
12149
+ });
12150
+ }
12151
+ _this.state.replaceMessage(currentMessageIndex, currentMessage);
11995
12152
  break;
11996
12153
  }
11997
12154
  case 'tool-input-available':
11998
12155
  {
11999
12156
  if (!currentMessage) break;
12157
+ delete toolRawInputByCallId[chunk.toolCallId];
12000
12158
  // Find existing tool part or create new one
12001
12159
  var existingIndex = currentMessage.parts.findIndex(function(p) {
12002
12160
  return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
@@ -12010,10 +12168,10 @@
12010
12168
  providerExecuted: chunk.providerExecuted
12011
12169
  };
12012
12170
  if (existingIndex >= 0) {
12013
- var updatedParts4 = _to_consumable_array(currentMessage.parts);
12014
- updatedParts4[existingIndex] = toolPart1;
12171
+ var updatedParts5 = _to_consumable_array(currentMessage.parts);
12172
+ updatedParts5[existingIndex] = toolPart1;
12015
12173
  currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
12016
- parts: updatedParts4
12174
+ parts: updatedParts5
12017
12175
  });
12018
12176
  } else {
12019
12177
  currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
@@ -12030,7 +12188,8 @@
12030
12188
  toolCall: {
12031
12189
  toolName: chunk.toolName,
12032
12190
  toolCallId: chunk.toolCallId,
12033
- input: chunk.input
12191
+ input: chunk.input,
12192
+ dynamic: 'dynamic' in chunk ? chunk.dynamic : undefined
12034
12193
  }
12035
12194
  });
12036
12195
  if (result && typeof result.then === 'function') {
@@ -12044,20 +12203,21 @@
12044
12203
  case 'tool-output-available':
12045
12204
  {
12046
12205
  if (!currentMessage) break;
12047
- var toolIndex = currentMessage.parts.findIndex(function(p) {
12206
+ var toolIndex1 = currentMessage.parts.findIndex(function(p) {
12048
12207
  return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
12049
12208
  });
12050
- if (toolIndex >= 0) {
12051
- var updatedParts5 = _to_consumable_array(currentMessage.parts);
12052
- var existingPart = updatedParts5[toolIndex];
12053
- updatedParts5[toolIndex] = _object_spread_props(_object_spread({}, existingPart), {
12209
+ if (toolIndex1 >= 0) {
12210
+ delete toolRawInputByCallId[chunk.toolCallId];
12211
+ var updatedParts6 = _to_consumable_array(currentMessage.parts);
12212
+ var existingPart1 = updatedParts6[toolIndex1];
12213
+ updatedParts6[toolIndex1] = _object_spread_props(_object_spread({}, existingPart1), {
12054
12214
  state: 'output-available',
12055
12215
  output: chunk.output,
12056
12216
  callProviderMetadata: chunk.callProviderMetadata,
12057
12217
  preliminary: chunk.preliminary
12058
12218
  });
12059
12219
  currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
12060
- parts: updatedParts5
12220
+ parts: updatedParts6
12061
12221
  });
12062
12222
  _this.state.replaceMessage(currentMessageIndex, currentMessage);
12063
12223
  }
@@ -12066,21 +12226,22 @@
12066
12226
  case 'tool-error':
12067
12227
  {
12068
12228
  if (!currentMessage) break;
12069
- var toolIndex1 = currentMessage.parts.findIndex(function(p) {
12229
+ var toolIndex2 = currentMessage.parts.findIndex(function(p) {
12070
12230
  return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
12071
12231
  });
12072
- if (toolIndex1 >= 0) {
12232
+ if (toolIndex2 >= 0) {
12073
12233
  var _chunk_input;
12074
- var updatedParts6 = _to_consumable_array(currentMessage.parts);
12075
- var existingPart1 = updatedParts6[toolIndex1];
12076
- updatedParts6[toolIndex1] = _object_spread_props(_object_spread({}, existingPart1), {
12234
+ delete toolRawInputByCallId[chunk.toolCallId];
12235
+ var updatedParts7 = _to_consumable_array(currentMessage.parts);
12236
+ var existingPart2 = updatedParts7[toolIndex2];
12237
+ updatedParts7[toolIndex2] = _object_spread_props(_object_spread({}, existingPart2), {
12077
12238
  state: 'output-error',
12078
12239
  errorText: chunk.errorText,
12079
- input: (_chunk_input = chunk.input) !== null && _chunk_input !== void 0 ? _chunk_input : existingPart1.input,
12240
+ input: (_chunk_input = chunk.input) !== null && _chunk_input !== void 0 ? _chunk_input : existingPart2.input,
12080
12241
  callProviderMetadata: chunk.callProviderMetadata
12081
12242
  });
12082
12243
  currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
12083
- parts: updatedParts6
12244
+ parts: updatedParts7
12084
12245
  });
12085
12246
  _this.state.replaceMessage(currentMessageIndex, currentMessage);
12086
12247
  }
@@ -12806,7 +12967,7 @@
12806
12967
  return refinements;
12807
12968
  }
12808
12969
 
12809
- var withUsage$m = createDocumentationMessageGenerator({
12970
+ var withUsage$n = createDocumentationMessageGenerator({
12810
12971
  name: 'chat',
12811
12972
  connector: true
12812
12973
  });
@@ -12857,12 +13018,14 @@
12857
13018
  }
12858
13019
  var connectChat = function connectChat(renderFn) {
12859
13020
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
12860
- checkRendering(renderFn, withUsage$m());
13021
+ checkRendering(renderFn, withUsage$n());
12861
13022
  return function(widgetParams) {
12862
- var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, options = _object_without_properties(_ref, [
13023
+ var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, context = _ref.context, initialUserMessage = _ref.initialUserMessage, options = _object_without_properties(_ref, [
12863
13024
  "resume",
12864
13025
  "tools",
12865
- "type"
13026
+ "type",
13027
+ "context",
13028
+ "initialUserMessage"
12866
13029
  ]);
12867
13030
  var _chatInstance;
12868
13031
  var input = '';
@@ -12904,6 +13067,10 @@
12904
13067
  if (!_chatInstance.messages || _chatInstance.messages.length === 0) {
12905
13068
  return;
12906
13069
  }
13070
+ var status = _chatInstance.status;
13071
+ if (status === 'submitted' || status === 'streaming') {
13072
+ _chatInstance.stop();
13073
+ }
12907
13074
  setIsClearing(true);
12908
13075
  };
12909
13076
  var onClearTransitionEnd = function onClearTransitionEnd() {
@@ -12953,7 +13120,7 @@
12953
13120
  }
12954
13121
  if ('agentId' in options && options.agentId) {
12955
13122
  if (!appId || !apiKey) {
12956
- throw new Error(withUsage$m('Could not extract Algolia credentials from the search client.'));
13123
+ throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
12957
13124
  }
12958
13125
  var baseApi = "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5");
12959
13126
  transport = new DefaultChatTransport({
@@ -12979,7 +13146,7 @@
12979
13146
  });
12980
13147
  }
12981
13148
  if (!transport) {
12982
- throw new Error(withUsage$m('You need to provide either an `agentId` or a `transport`.'));
13149
+ throw new Error(withUsage$n('You need to provide either an `agentId` or a `transport`.'));
12983
13150
  }
12984
13151
  if ('chat' in options) {
12985
13152
  return options.chat;
@@ -12987,6 +13154,14 @@
12987
13154
  return new Chat(_object_spread_props(_object_spread({}, options), {
12988
13155
  transport: transport,
12989
13156
  sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
13157
+ shouldRepairToolInput: function shouldRepairToolInput(toolName) {
13158
+ var tool = tools[toolName];
13159
+ if (!tool && toolName.startsWith("".concat(SearchIndexToolType, "_"))) {
13160
+ tool = tools[SearchIndexToolType];
13161
+ }
13162
+ if (!tool) return true;
13163
+ return Boolean(tool.streamInput);
13164
+ },
12990
13165
  onToolCall: function onToolCall(param) {
12991
13166
  var toolCall = param.toolCall;
12992
13167
  var tool = tools[toolCall.toolName];
@@ -13052,7 +13227,7 @@
13052
13227
  if (agentId && feedback) {
13053
13228
  var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
13054
13229
  if (!appId || !apiKey) {
13055
- throw new Error(withUsage$m('Could not extract Algolia credentials from the search client.'));
13230
+ throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
13056
13231
  }
13057
13232
  feedbackAbortController = new AbortController();
13058
13233
  _sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
@@ -13077,6 +13252,11 @@
13077
13252
  if (resume) {
13078
13253
  _chatInstance.resumeStream();
13079
13254
  }
13255
+ if (initialUserMessage && !resume && _chatInstance.messages.length === 0) {
13256
+ _chatInstance.sendMessage({
13257
+ text: initialUserMessage
13258
+ });
13259
+ }
13080
13260
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
13081
13261
  instantSearchInstance: instantSearchInstance
13082
13262
  }), true);
@@ -13112,10 +13292,65 @@
13112
13292
  var _param = _sliced_to_array(param, 2), key = _param[0], tool = _param[1];
13113
13293
  var toolWithAddToolResult = _object_spread_props(_object_spread({}, tool), {
13114
13294
  addToolResult: _chatInstance.addToolResult,
13115
- applyFilters: applyFilters
13295
+ applyFilters: applyFilters,
13296
+ sendEvent: sendEvent
13116
13297
  });
13117
13298
  toolsWithAddToolResult[key] = toolWithAddToolResult;
13118
13299
  });
13300
+ var sendMessageWithContext = function sendMessageWithContext(message) {
13301
+ for(var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
13302
+ rest[_key - 1] = arguments[_key];
13303
+ }
13304
+ var _chatInstance1;
13305
+ if (!context || !message) {
13306
+ var _chatInstance2;
13307
+ return (_chatInstance2 = _chatInstance).sendMessage.apply(_chatInstance2, [
13308
+ message
13309
+ ].concat(_to_consumable_array(rest)));
13310
+ }
13311
+ var resolvedContext = typeof context === 'function' ? context() : context;
13312
+ var serializedContext;
13313
+ try {
13314
+ serializedContext = JSON.stringify(resolvedContext);
13315
+ } catch (unused) {
13316
+ var _chatInstance3;
13317
+ return (_chatInstance3 = _chatInstance).sendMessage.apply(_chatInstance3, [
13318
+ message
13319
+ ].concat(_to_consumable_array(rest)));
13320
+ }
13321
+ var contextTextPart = {
13322
+ type: 'text',
13323
+ text: '<context>'.concat(serializedContext).concat('</context>')
13324
+ };
13325
+ if ('parts' in message && message.parts) {
13326
+ var _chatInstance4;
13327
+ return (_chatInstance4 = _chatInstance).sendMessage.apply(_chatInstance4, [
13328
+ _object_spread_props(_object_spread({}, message), {
13329
+ parts: [
13330
+ contextTextPart
13331
+ ].concat(_to_consumable_array(message.parts)),
13332
+ text: undefined,
13333
+ files: undefined
13334
+ })
13335
+ ].concat(_to_consumable_array(rest)));
13336
+ }
13337
+ var textContent = 'text' in message && message.text ? message.text : '';
13338
+ return (_chatInstance1 = _chatInstance).sendMessage.apply(_chatInstance1, [
13339
+ {
13340
+ parts: [
13341
+ contextTextPart,
13342
+ {
13343
+ type: 'text',
13344
+ text: textContent
13345
+ }
13346
+ ],
13347
+ metadata: message.metadata,
13348
+ messageId: message.messageId,
13349
+ files: undefined,
13350
+ text: undefined
13351
+ }
13352
+ ].concat(_to_consumable_array(rest)));
13353
+ };
13119
13354
  return {
13120
13355
  indexUiState: instantSearchInstance.getUiState()[parent.getIndexId()],
13121
13356
  input: input,
@@ -13142,7 +13377,7 @@
13142
13377
  messages: _chatInstance.messages,
13143
13378
  regenerate: _chatInstance.regenerate,
13144
13379
  resumeStream: _chatInstance.resumeStream,
13145
- sendMessage: _chatInstance.sendMessage,
13380
+ sendMessage: sendMessageWithContext,
13146
13381
  status: _chatInstance.status,
13147
13382
  stop: _chatInstance.stop
13148
13383
  };
@@ -13165,13 +13400,13 @@
13165
13400
  return useConnector(connectChat, props, additionalWidgetProperties);
13166
13401
  }
13167
13402
 
13168
- var withUsage$l = createDocumentationMessageGenerator({
13403
+ var withUsage$m = createDocumentationMessageGenerator({
13169
13404
  name: 'clear-refinements',
13170
13405
  connector: true
13171
13406
  });
13172
13407
  var connectClearRefinements = function connectClearRefinements(renderFn) {
13173
13408
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13174
- checkRendering(renderFn, withUsage$l());
13409
+ checkRendering(renderFn, withUsage$m());
13175
13410
  return function(widgetParams) {
13176
13411
  var _ref = widgetParams || {}, _ref_includedAttributes = _ref.includedAttributes, includedAttributes = _ref_includedAttributes === void 0 ? [] : _ref_includedAttributes, _ref_excludedAttributes = _ref.excludedAttributes, excludedAttributes = _ref_excludedAttributes === void 0 ? [
13177
13412
  'query'
@@ -13179,7 +13414,7 @@
13179
13414
  return items;
13180
13415
  } : _ref_transformItems;
13181
13416
  if (widgetParams && widgetParams.includedAttributes && widgetParams.excludedAttributes) {
13182
- throw new Error(withUsage$l('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
13417
+ throw new Error(withUsage$m('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
13183
13418
  }
13184
13419
  var connectorState = {
13185
13420
  refine: noop,
@@ -13282,16 +13517,16 @@
13282
13517
  return useConnector(connectClearRefinements, props, additionalWidgetProperties);
13283
13518
  }
13284
13519
 
13285
- var withUsage$k = createDocumentationMessageGenerator({
13520
+ var withUsage$l = createDocumentationMessageGenerator({
13286
13521
  name: 'current-refinements',
13287
13522
  connector: true
13288
13523
  });
13289
13524
  var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
13290
13525
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13291
- checkRendering(renderFn, withUsage$k());
13526
+ checkRendering(renderFn, withUsage$l());
13292
13527
  return function(widgetParams) {
13293
13528
  if ((widgetParams || {}).includedAttributes && (widgetParams || {}).excludedAttributes) {
13294
- throw new Error(withUsage$k('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
13529
+ throw new Error(withUsage$l('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
13295
13530
  }
13296
13531
  var _ref = widgetParams || {}, includedAttributes = _ref.includedAttributes, _ref_excludedAttributes = _ref.excludedAttributes, excludedAttributes = _ref_excludedAttributes === void 0 ? [
13297
13532
  'query'
@@ -13461,38 +13696,19 @@
13461
13696
  return useConnector(connectCurrentRefinements, props, additionalWidgetProperties);
13462
13697
  }
13463
13698
 
13464
- function addAbsolutePosition(hits, page, hitsPerPage) {
13465
- return hits.map(function(hit, idx) {
13466
- return _object_spread_props(_object_spread({}, hit), {
13467
- __position: hitsPerPage * page + idx + 1
13468
- });
13469
- });
13470
- }
13471
-
13472
- function addQueryID(hits, queryID) {
13473
- if (!queryID) {
13474
- return hits;
13475
- }
13476
- return hits.map(function(hit) {
13477
- return _object_spread_props(_object_spread({}, hit), {
13478
- __queryID: queryID
13479
- });
13480
- });
13481
- }
13482
-
13483
- var withUsage$j = createDocumentationMessageGenerator({
13699
+ var withUsage$k = createDocumentationMessageGenerator({
13484
13700
  name: 'frequently-bought-together',
13485
13701
  connector: true
13486
13702
  });
13487
13703
  var connectFrequentlyBoughtTogether = function connectFrequentlyBoughtTogether(renderFn) {
13488
13704
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13489
- checkRendering(renderFn, withUsage$j());
13705
+ checkRendering(renderFn, withUsage$k());
13490
13706
  return function(widgetParams) {
13491
13707
  var _ref = widgetParams || {}, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
13492
13708
  return items;
13493
13709
  } : _ref_transformItems, objectIDs = _ref.objectIDs, limit = _ref.limit, threshold = _ref.threshold, fallbackParameters = _ref.fallbackParameters, queryParameters = _ref.queryParameters;
13494
13710
  if (!objectIDs || objectIDs.length === 0) {
13495
- throw new Error(withUsage$j('The `objectIDs` option is required.'));
13711
+ throw new Error(withUsage$k('The `objectIDs` option is required.'));
13496
13712
  }
13497
13713
  var sendEvent;
13498
13714
  return {
@@ -13630,7 +13846,7 @@
13630
13846
  return insideBoundingBoxStringToBoundingBox(value);
13631
13847
  }
13632
13848
 
13633
- var withUsage$i = createDocumentationMessageGenerator({
13849
+ var withUsage$j = createDocumentationMessageGenerator({
13634
13850
  name: 'geo-search',
13635
13851
  connector: true
13636
13852
  });
@@ -13654,7 +13870,7 @@
13654
13870
  * Currently, the feature is not compatible with multiple values in the _geoloc attribute.
13655
13871
  */ var connectGeoSearch = function connectGeoSearch(renderFn) {
13656
13872
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13657
- checkRendering(renderFn, withUsage$i());
13873
+ checkRendering(renderFn, withUsage$j());
13658
13874
  return function(widgetParams) {
13659
13875
  var _ref = widgetParams || {}, _ref_enableRefineOnMapMove = _ref.enableRefineOnMapMove, enableRefineOnMapMove = _ref_enableRefineOnMapMove === void 0 ? true : _ref_enableRefineOnMapMove, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
13660
13876
  return items;
@@ -13872,7 +14088,7 @@
13872
14088
  return sendEventForFacet;
13873
14089
  }
13874
14090
 
13875
- var withUsage$h = createDocumentationMessageGenerator({
14091
+ var withUsage$i = createDocumentationMessageGenerator({
13876
14092
  name: 'hierarchical-menu',
13877
14093
  connector: true
13878
14094
  });
@@ -13893,16 +14109,16 @@
13893
14109
  * @return {function(CustomHierarchicalMenuWidgetParams)} Re-usable widget factory for a custom **HierarchicalMenu** widget.
13894
14110
  */ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
13895
14111
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13896
- checkRendering(renderFn, withUsage$h());
14112
+ checkRendering(renderFn, withUsage$i());
13897
14113
  return function(widgetParams) {
13898
14114
  var _ref = widgetParams || {}, attributes = _ref.attributes, _ref_separator = _ref.separator, separator = _ref_separator === void 0 ? ' > ' : _ref_separator, _ref_rootPath = _ref.rootPath, rootPath = _ref_rootPath === void 0 ? null : _ref_rootPath, _ref_showParentLevel = _ref.showParentLevel, showParentLevel = _ref_showParentLevel === void 0 ? true : _ref_showParentLevel, _ref_limit = _ref.limit, limit = _ref_limit === void 0 ? 10 : _ref_limit, _ref_showMore = _ref.showMore, showMore = _ref_showMore === void 0 ? false : _ref_showMore, _ref_showMoreLimit = _ref.showMoreLimit, showMoreLimit = _ref_showMoreLimit === void 0 ? 20 : _ref_showMoreLimit, _ref_sortBy = _ref.sortBy, sortBy = _ref_sortBy === void 0 ? DEFAULT_SORT$2 : _ref_sortBy, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
13899
14115
  return items;
13900
14116
  } : _ref_transformItems;
13901
14117
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
13902
- throw new Error(withUsage$h('The `attributes` option expects an array of strings.'));
14118
+ throw new Error(withUsage$i('The `attributes` option expects an array of strings.'));
13903
14119
  }
13904
14120
  if (showMore === true && showMoreLimit <= limit) {
13905
- throw new Error(withUsage$h('The `showMoreLimit` option must be greater than `limit`.'));
14121
+ throw new Error(withUsage$i('The `showMoreLimit` option must be greater than `limit`.'));
13906
14122
  }
13907
14123
  // we need to provide a hierarchicalFacet name for the search state
13908
14124
  // so that we can always map $hierarchicalFacetName => real attributes
@@ -14094,13 +14310,13 @@
14094
14310
  return useConnector(connectHierarchicalMenu, props, additionalWidgetProperties);
14095
14311
  }
14096
14312
 
14097
- var withUsage$g = createDocumentationMessageGenerator({
14313
+ var withUsage$h = createDocumentationMessageGenerator({
14098
14314
  name: 'hits',
14099
14315
  connector: true
14100
14316
  });
14101
14317
  var connectHits = function connectHits(renderFn) {
14102
14318
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14103
- checkRendering(renderFn, withUsage$g());
14319
+ checkRendering(renderFn, withUsage$h());
14104
14320
  return function(widgetParams) {
14105
14321
  var _ref = widgetParams || {}, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
14106
14322
  return items;
@@ -14198,29 +14414,29 @@
14198
14414
  return useConnector(connectHits, props, additionalWidgetProperties);
14199
14415
  }
14200
14416
 
14201
- var withUsage$f = createDocumentationMessageGenerator({
14417
+ var withUsage$g = createDocumentationMessageGenerator({
14202
14418
  name: 'hits-per-page',
14203
14419
  connector: true
14204
14420
  });
14205
14421
  var connectHitsPerPage = function connectHitsPerPage(renderFn) {
14206
14422
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14207
- checkRendering(renderFn, withUsage$f());
14423
+ checkRendering(renderFn, withUsage$g());
14208
14424
  return function(widgetParams) {
14209
14425
  var _ref = widgetParams || {}, userItems = _ref.items, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
14210
14426
  return items;
14211
14427
  } : _ref_transformItems;
14212
14428
  if (!Array.isArray(userItems)) {
14213
- throw new Error(withUsage$f('The `items` option expects an array of objects.'));
14429
+ throw new Error(withUsage$g('The `items` option expects an array of objects.'));
14214
14430
  }
14215
14431
  var items = userItems;
14216
14432
  var defaultItems = items.filter(function(item) {
14217
14433
  return item.default === true;
14218
14434
  });
14219
14435
  if (defaultItems.length === 0) {
14220
- throw new Error(withUsage$f("A default value must be specified in `items`."));
14436
+ throw new Error(withUsage$g("A default value must be specified in `items`."));
14221
14437
  }
14222
14438
  if (defaultItems.length > 1) {
14223
- throw new Error(withUsage$f('More than one default value is specified in `items`.'));
14439
+ throw new Error(withUsage$g('More than one default value is specified in `items`.'));
14224
14440
  }
14225
14441
  var defaultItem = defaultItems[0];
14226
14442
  var normalizeItems = function normalizeItems(param) {
@@ -14339,7 +14555,7 @@
14339
14555
  });
14340
14556
  }
14341
14557
 
14342
- var withUsage$e = createDocumentationMessageGenerator({
14558
+ var withUsage$f = createDocumentationMessageGenerator({
14343
14559
  name: 'infinite-hits',
14344
14560
  connector: true
14345
14561
  });
@@ -14385,7 +14601,7 @@
14385
14601
  }
14386
14602
  var connectInfiniteHits = function connectInfiniteHits(renderFn) {
14387
14603
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14388
- checkRendering(renderFn, withUsage$e());
14604
+ checkRendering(renderFn, withUsage$f());
14389
14605
  return function(widgetParams) {
14390
14606
  var _ref = widgetParams || {}, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
14391
14607
  return items;
@@ -14591,7 +14807,7 @@
14591
14807
  return useConnector(connectInfiniteHits, props, additionalWidgetProperties);
14592
14808
  }
14593
14809
 
14594
- var withUsage$d = createDocumentationMessageGenerator({
14810
+ var withUsage$e = createDocumentationMessageGenerator({
14595
14811
  name: 'menu',
14596
14812
  connector: true
14597
14813
  });
@@ -14609,16 +14825,16 @@
14609
14825
  * **Requirement:** the attribute passed as `attribute` must be present in "attributes for faceting" on the Algolia dashboard or configured as attributesForFaceting via a set settings call to the Algolia API.
14610
14826
  */ var connectMenu = function connectMenu(renderFn) {
14611
14827
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14612
- checkRendering(renderFn, withUsage$d());
14828
+ checkRendering(renderFn, withUsage$e());
14613
14829
  return function(widgetParams) {
14614
14830
  var _ref = widgetParams || {}, attribute = _ref.attribute, _ref_limit = _ref.limit, limit = _ref_limit === void 0 ? 10 : _ref_limit, _ref_showMore = _ref.showMore, showMore = _ref_showMore === void 0 ? false : _ref_showMore, _ref_showMoreLimit = _ref.showMoreLimit, showMoreLimit = _ref_showMoreLimit === void 0 ? 20 : _ref_showMoreLimit, _ref_sortBy = _ref.sortBy, sortBy = _ref_sortBy === void 0 ? DEFAULT_SORT$1 : _ref_sortBy, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
14615
14831
  return items;
14616
14832
  } : _ref_transformItems;
14617
14833
  if (!attribute) {
14618
- throw new Error(withUsage$d('The `attribute` option is required.'));
14834
+ throw new Error(withUsage$e('The `attribute` option is required.'));
14619
14835
  }
14620
14836
  if (showMore === true && showMoreLimit <= limit) {
14621
- throw new Error(withUsage$d('The `showMoreLimit` option must be greater than `limit`.'));
14837
+ throw new Error(withUsage$e('The `showMoreLimit` option must be greater than `limit`.'));
14622
14838
  }
14623
14839
  var sendEvent;
14624
14840
  var _createURL;
@@ -14788,7 +15004,7 @@
14788
15004
  return typeof value === 'number' && isFinite(value);
14789
15005
  }
14790
15006
 
14791
- var withUsage$c = createDocumentationMessageGenerator({
15007
+ var withUsage$d = createDocumentationMessageGenerator({
14792
15008
  name: 'numeric-menu',
14793
15009
  connector: true
14794
15010
  });
@@ -14807,16 +15023,16 @@
14807
15023
  };
14808
15024
  var connectNumericMenu = function connectNumericMenu(renderFn) {
14809
15025
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14810
- checkRendering(renderFn, withUsage$c());
15026
+ checkRendering(renderFn, withUsage$d());
14811
15027
  return function(widgetParams) {
14812
15028
  var _ref = widgetParams || {}, _ref_attribute = _ref.attribute, attribute = _ref_attribute === void 0 ? '' : _ref_attribute, _ref_items = _ref.items, items = _ref_items === void 0 ? [] : _ref_items, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(item) {
14813
15029
  return item;
14814
15030
  } : _ref_transformItems;
14815
15031
  if (attribute === '') {
14816
- throw new Error(withUsage$c('The `attribute` option is required.'));
15032
+ throw new Error(withUsage$d('The `attribute` option is required.'));
14817
15033
  }
14818
15034
  if (!items || items.length === 0) {
14819
- throw new Error(withUsage$c('The `items` option expects an array of objects.'));
15035
+ throw new Error(withUsage$d('The `items` option expects an array of objects.'));
14820
15036
  }
14821
15037
  var prepareItems = function prepareItems(state) {
14822
15038
  return items.map(function(param) {
@@ -15131,7 +15347,7 @@
15131
15347
  return Paginator;
15132
15348
  }();
15133
15349
 
15134
- var withUsage$b = createDocumentationMessageGenerator({
15350
+ var withUsage$c = createDocumentationMessageGenerator({
15135
15351
  name: 'pagination',
15136
15352
  connector: true
15137
15353
  });
@@ -15143,7 +15359,7 @@
15143
15359
  * beyond the 1000th hits by default. You can find more information on the [Algolia documentation](https://www.algolia.com/doc/guides/searching/pagination/#pagination-limitations).
15144
15360
  */ var connectPagination = function connectPagination(renderFn) {
15145
15361
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15146
- checkRendering(renderFn, withUsage$b());
15362
+ checkRendering(renderFn, withUsage$c());
15147
15363
  return function(widgetParams) {
15148
15364
  var _ref = widgetParams || {}, totalPages = _ref.totalPages, _ref_padding = _ref.padding, padding = _ref_padding === void 0 ? 3 : _ref_padding;
15149
15365
  var pager = new Paginator({
@@ -15260,7 +15476,7 @@
15260
15476
  };
15261
15477
  }
15262
15478
 
15263
- var withUsage$a = createDocumentationMessageGenerator({
15479
+ var withUsage$b = createDocumentationMessageGenerator({
15264
15480
  name: 'query-rules',
15265
15481
  connector: true
15266
15482
  });
@@ -15316,7 +15532,7 @@
15316
15532
  }
15317
15533
  var connectQueryRules = function connectQueryRules(render) {
15318
15534
  var unmount = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15319
- checkRendering(render, withUsage$a());
15535
+ checkRendering(render, withUsage$b());
15320
15536
  return function(widgetParams) {
15321
15537
  var _ref = widgetParams || {}, _ref_trackedFilters = _ref.trackedFilters, trackedFilters = _ref_trackedFilters === void 0 ? {} : _ref_trackedFilters, _ref_transformRuleContexts = _ref.transformRuleContexts, transformRuleContexts = _ref_transformRuleContexts === void 0 ? function(rules) {
15322
15538
  return rules;
@@ -15325,7 +15541,7 @@
15325
15541
  } : _ref_transformItems;
15326
15542
  Object.keys(trackedFilters).forEach(function(facetName) {
15327
15543
  if (typeof trackedFilters[facetName] !== 'function') {
15328
- throw new Error(withUsage$a("'The \"".concat(facetName, '" filter value in the `trackedFilters` option expects a function.')));
15544
+ throw new Error(withUsage$b("'The \"".concat(facetName, '" filter value in the `trackedFilters` option expects a function.')));
15329
15545
  }
15330
15546
  });
15331
15547
  var hasTrackedFilters = Object.keys(trackedFilters).length > 0;
@@ -15401,7 +15617,7 @@
15401
15617
  return useConnector(connectQueryRules, props, additionalWidgetProperties);
15402
15618
  }
15403
15619
 
15404
- var withUsage$9 = createDocumentationMessageGenerator({
15620
+ var withUsage$a = createDocumentationMessageGenerator({
15405
15621
  name: 'range-input',
15406
15622
  connector: true
15407
15623
  }, {
@@ -15425,14 +15641,14 @@
15425
15641
  * information about the min and max bounds for the current result set.
15426
15642
  */ var connectRange = function connectRange(renderFn) {
15427
15643
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15428
- checkRendering(renderFn, withUsage$9());
15644
+ checkRendering(renderFn, withUsage$a());
15429
15645
  return function(widgetParams) {
15430
15646
  var _ref = widgetParams || {}, _ref_attribute = _ref.attribute, attribute = _ref_attribute === void 0 ? '' : _ref_attribute, minBound = _ref.min, maxBound = _ref.max, _ref_precision = _ref.precision, precision = _ref_precision === void 0 ? 0 : _ref_precision;
15431
15647
  if (!attribute) {
15432
- throw new Error(withUsage$9('The `attribute` option is required.'));
15648
+ throw new Error(withUsage$a('The `attribute` option is required.'));
15433
15649
  }
15434
15650
  if (isFiniteNumber(minBound) && isFiniteNumber(maxBound) && minBound > maxBound) {
15435
- throw new Error(withUsage$9("The `max` option can't be lower than `min`."));
15651
+ throw new Error(withUsage$a("The `max` option can't be lower than `min`."));
15436
15652
  }
15437
15653
  var formatToNumber = function formatToNumber(v) {
15438
15654
  return Number(Number(v).toFixed(precision));
@@ -15652,7 +15868,7 @@
15652
15868
  return useConnector(connectRange, props, additionalWidgetProperties);
15653
15869
  }
15654
15870
 
15655
- var withUsage$8 = createDocumentationMessageGenerator({
15871
+ var withUsage$9 = createDocumentationMessageGenerator({
15656
15872
  name: 'refinement-list',
15657
15873
  connector: true
15658
15874
  });
@@ -15674,19 +15890,19 @@
15674
15890
  * - a `searchForItems()` function to search within the items.
15675
15891
  */ var connectRefinementList = function connectRefinementList(renderFn) {
15676
15892
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15677
- checkRendering(renderFn, withUsage$8());
15893
+ checkRendering(renderFn, withUsage$9());
15678
15894
  return function(widgetParams) {
15679
15895
  var _ref = widgetParams || {}, attribute = _ref.attribute, _ref_operator = _ref.operator, operator = _ref_operator === void 0 ? 'or' : _ref_operator, _ref_limit = _ref.limit, limit = _ref_limit === void 0 ? 10 : _ref_limit, _ref_showMore = _ref.showMore, showMore = _ref_showMore === void 0 ? false : _ref_showMore, _ref_showMoreLimit = _ref.showMoreLimit, showMoreLimit = _ref_showMoreLimit === void 0 ? 20 : _ref_showMoreLimit, _ref_sortBy = _ref.sortBy, sortBy = _ref_sortBy === void 0 ? DEFAULT_SORT : _ref_sortBy, _ref_escapeFacetValues = _ref.escapeFacetValues, escapeFacetValues = _ref_escapeFacetValues === void 0 ? true : _ref_escapeFacetValues, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
15680
15896
  return items;
15681
15897
  } : _ref_transformItems;
15682
15898
  if (!attribute) {
15683
- throw new Error(withUsage$8('The `attribute` option is required.'));
15899
+ throw new Error(withUsage$9('The `attribute` option is required.'));
15684
15900
  }
15685
15901
  if (!/^(and|or)$/.test(operator)) {
15686
- throw new Error(withUsage$8('The `operator` must one of: `"and"`, `"or"` (got "'.concat(operator, '").')));
15902
+ throw new Error(withUsage$9('The `operator` must one of: `"and"`, `"or"` (got "'.concat(operator, '").')));
15687
15903
  }
15688
15904
  if (showMore === true && showMoreLimit <= limit) {
15689
- throw new Error(withUsage$8('`showMoreLimit` should be greater than `limit`.'));
15905
+ throw new Error(withUsage$9('`showMoreLimit` should be greater than `limit`.'));
15690
15906
  }
15691
15907
  var formatItems = function formatItems(_0) {
15692
15908
  var label = _0.name, value = _0.escapedValue, item = _object_without_properties(_0, [
@@ -15914,19 +16130,19 @@
15914
16130
  return useConnector(connectRefinementList, props, additionalWidgetProperties);
15915
16131
  }
15916
16132
 
15917
- var withUsage$7 = createDocumentationMessageGenerator({
16133
+ var withUsage$8 = createDocumentationMessageGenerator({
15918
16134
  name: 'related-products',
15919
16135
  connector: true
15920
16136
  });
15921
16137
  var connectRelatedProducts = function connectRelatedProducts(renderFn) {
15922
16138
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15923
- checkRendering(renderFn, withUsage$7());
16139
+ checkRendering(renderFn, withUsage$8());
15924
16140
  return function(widgetParams) {
15925
16141
  var _ref = widgetParams || {}, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, objectIDs = _ref.objectIDs, limit = _ref.limit, threshold = _ref.threshold, fallbackParameters = _ref.fallbackParameters, queryParameters = _ref.queryParameters, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
15926
16142
  return items;
15927
16143
  } : _ref_transformItems;
15928
16144
  if (!objectIDs || objectIDs.length === 0) {
15929
- throw new Error(withUsage$7('The `objectIDs` option is required.'));
16145
+ throw new Error(withUsage$8('The `objectIDs` option is required.'));
15930
16146
  }
15931
16147
  var sendEvent;
15932
16148
  return {
@@ -16002,7 +16218,7 @@
16002
16218
  return useConnector(connectRelatedProducts, props, additionalWidgetProperties);
16003
16219
  }
16004
16220
 
16005
- var withUsage$6 = createDocumentationMessageGenerator({
16221
+ var withUsage$7 = createDocumentationMessageGenerator({
16006
16222
  name: 'search-box',
16007
16223
  connector: true
16008
16224
  });
@@ -16016,7 +16232,7 @@
16016
16232
  * may be impacted by the `queryHook` widget parameter.
16017
16233
  */ var connectSearchBox = function connectSearchBox(renderFn) {
16018
16234
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16019
- checkRendering(renderFn, withUsage$6());
16235
+ checkRendering(renderFn, withUsage$7());
16020
16236
  return function(widgetParams) {
16021
16237
  var _ref = widgetParams || {}, _ref_queryHook = _ref.queryHook, queryHook = _ref_queryHook === void 0 ? defaultQueryHook : _ref_queryHook;
16022
16238
  var _refine;
@@ -16087,7 +16303,7 @@
16087
16303
  return useConnector(connectSearchBox, props, additionalWidgetProperties);
16088
16304
  }
16089
16305
 
16090
- var withUsage$5 = createDocumentationMessageGenerator({
16306
+ var withUsage$6 = createDocumentationMessageGenerator({
16091
16307
  name: 'sort-by',
16092
16308
  connector: true
16093
16309
  });
@@ -16107,14 +16323,14 @@
16107
16323
  }
16108
16324
  var connectSortBy = function connectSortBy(renderFn) {
16109
16325
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16110
- checkRendering(renderFn, withUsage$5());
16326
+ checkRendering(renderFn, withUsage$6());
16111
16327
  var connectorState = {};
16112
16328
  return function(widgetParams) {
16113
16329
  var _ref = widgetParams || {}, items = _ref.items, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(x) {
16114
16330
  return x;
16115
16331
  } : _ref_transformItems;
16116
16332
  if (!Array.isArray(items)) {
16117
- throw new Error(withUsage$5('The `items` option expects an array of objects.'));
16333
+ throw new Error(withUsage$6('The `items` option expects an array of objects.'));
16118
16334
  }
16119
16335
  var itemsLookup = {};
16120
16336
  items.forEach(function(item, index) {
@@ -16122,10 +16338,10 @@
16122
16338
  var hasStrategy = 'strategy' in item && item.strategy !== undefined;
16123
16339
  // Validate mutual exclusivity
16124
16340
  if (hasValue && hasStrategy) {
16125
- throw new Error(withUsage$5("Item at index ".concat(index, ' cannot have both "value" and "strategy" properties.')));
16341
+ throw new Error(withUsage$6("Item at index ".concat(index, ' cannot have both "value" and "strategy" properties.')));
16126
16342
  }
16127
16343
  if (!hasValue && !hasStrategy) {
16128
- throw new Error(withUsage$5("Item at index ".concat(index, ' must have either a "value" or "strategy" property.')));
16344
+ throw new Error(withUsage$6("Item at index ".concat(index, ' must have either a "value" or "strategy" property.')));
16129
16345
  }
16130
16346
  var itemValue = getItemValue(item);
16131
16347
  itemsLookup[itemValue] = item;
@@ -16140,7 +16356,7 @@
16140
16356
  return 'strategy' in item && item.strategy;
16141
16357
  });
16142
16358
  if (hasStrategyItems && !instantSearchInstance.compositionID) {
16143
- throw new Error(withUsage$5('Sorting strategies can only be used in composition mode. Please provide a "compositionID" to your InstantSearch instance.'));
16359
+ throw new Error(withUsage$6('Sorting strategies can only be used in composition mode. Please provide a "compositionID" to your InstantSearch instance.'));
16144
16360
  }
16145
16361
  var widgetRenderState = this.getWidgetRenderState(initOptions);
16146
16362
  var currentIndex = widgetRenderState.currentRefinement;
@@ -16253,13 +16469,13 @@
16253
16469
  return useConnector(connectSortBy, props, additionalWidgetProperties);
16254
16470
  }
16255
16471
 
16256
- var withUsage$4 = createDocumentationMessageGenerator({
16472
+ var withUsage$5 = createDocumentationMessageGenerator({
16257
16473
  name: 'stats',
16258
16474
  connector: true
16259
16475
  });
16260
16476
  var connectStats = function connectStats(renderFn) {
16261
16477
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16262
- checkRendering(renderFn, withUsage$4());
16478
+ checkRendering(renderFn, withUsage$5());
16263
16479
  return function(widgetParams) {
16264
16480
  return {
16265
16481
  $$type: 'ais.stats',
@@ -16318,7 +16534,7 @@
16318
16534
  return useConnector(connectStats, props, additionalWidgetProperties);
16319
16535
  }
16320
16536
 
16321
- var withUsage$3 = createDocumentationMessageGenerator({
16537
+ var withUsage$4 = createDocumentationMessageGenerator({
16322
16538
  name: 'toggle-refinement',
16323
16539
  connector: true
16324
16540
  });
@@ -16369,11 +16585,11 @@
16369
16585
  * - switch between two values.
16370
16586
  */ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
16371
16587
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16372
- checkRendering(renderFn, withUsage$3());
16588
+ checkRendering(renderFn, withUsage$4());
16373
16589
  return function(widgetParams) {
16374
16590
  var _ref = widgetParams || {}, attribute = _ref.attribute, tmp = _ref.on, userOn = tmp === void 0 ? true : tmp, userOff = _ref.off;
16375
16591
  if (!attribute) {
16376
- throw new Error(withUsage$3('The `attribute` option is required.'));
16592
+ throw new Error(withUsage$4('The `attribute` option is required.'));
16377
16593
  }
16378
16594
  var hasAnOffValue = userOff !== undefined;
16379
16595
  // even though facet values can be numbers and boolean,
@@ -16594,19 +16810,19 @@
16594
16810
  return useConnector(connectToggleRefinement, props, additionalWidgetProperties);
16595
16811
  }
16596
16812
 
16597
- var withUsage$2 = createDocumentationMessageGenerator({
16813
+ var withUsage$3 = createDocumentationMessageGenerator({
16598
16814
  name: 'trending-items',
16599
16815
  connector: true
16600
16816
  });
16601
16817
  var connectTrendingItems = function connectTrendingItems(renderFn) {
16602
16818
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16603
- checkRendering(renderFn, withUsage$2());
16819
+ checkRendering(renderFn, withUsage$3());
16604
16820
  return function(widgetParams) {
16605
16821
  var _ref = widgetParams || {}, facetName = _ref.facetName, facetValue = _ref.facetValue, limit = _ref.limit, threshold = _ref.threshold, fallbackParameters = _ref.fallbackParameters, queryParameters = _ref.queryParameters, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
16606
16822
  return items;
16607
16823
  } : _ref_transformItems;
16608
16824
  if (facetName && !facetValue || !facetName && facetValue) {
16609
- throw new Error(withUsage$2("When you provide facetName (received type ".concat(getObjectType(facetName), "), you must also provide facetValue (received type ").concat(getObjectType(facetValue), ").")));
16825
+ throw new Error(withUsage$3("When you provide facetName (received type ".concat(getObjectType(facetName), "), you must also provide facetValue (received type ").concat(getObjectType(facetValue), ").")));
16610
16826
  }
16611
16827
  var sendEvent;
16612
16828
  return {
@@ -16680,6 +16896,94 @@
16680
16896
  return useConnector(connectTrendingItems, props, additionalWidgetProperties);
16681
16897
  }
16682
16898
 
16899
+ var withUsage$2 = createDocumentationMessageGenerator({
16900
+ name: 'trending-facets',
16901
+ connector: true
16902
+ });
16903
+ var connectTrendingFacets = function connectTrendingFacets(renderFn) {
16904
+ var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16905
+ checkRendering(renderFn, withUsage$2());
16906
+ return function(widgetParams) {
16907
+ var _ref = widgetParams || {}, facetName = _ref.facetName, limit = _ref.limit, threshold = _ref.threshold, fallbackParameters = _ref.fallbackParameters, queryParameters = _ref.queryParameters, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
16908
+ return items;
16909
+ } : _ref_transformItems;
16910
+ if (!facetName) {
16911
+ throw new Error(withUsage$2('The `facetName` option is required.'));
16912
+ }
16913
+ return {
16914
+ dependsOn: 'recommend',
16915
+ $$type: 'ais.trendingFacets',
16916
+ init: function init(initOptions) {
16917
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
16918
+ instantSearchInstance: initOptions.instantSearchInstance
16919
+ }), true);
16920
+ },
16921
+ render: function render(renderOptions) {
16922
+ var renderState = this.getWidgetRenderState(renderOptions);
16923
+ renderFn(_object_spread_props(_object_spread({}, renderState), {
16924
+ instantSearchInstance: renderOptions.instantSearchInstance
16925
+ }), false);
16926
+ },
16927
+ getRenderState: function getRenderState(renderState) {
16928
+ return renderState;
16929
+ },
16930
+ getWidgetRenderState: function getWidgetRenderState(param) {
16931
+ var results = param.results;
16932
+ param.helper;
16933
+ param.instantSearchInstance;
16934
+ if (results === null || results === undefined) {
16935
+ return {
16936
+ items: [],
16937
+ widgetParams: widgetParams
16938
+ };
16939
+ }
16940
+ var items = (results.hits || []).map(function(hit) {
16941
+ return {
16942
+ facetName: hit.facetName,
16943
+ facetValue: hit.facetValue,
16944
+ _score: hit._score
16945
+ };
16946
+ });
16947
+ if (escapeHTML) {
16948
+ items = items.map(function(item) {
16949
+ return _object_spread_props(_object_spread({}, item), {
16950
+ facetValue: escape$1(item.facetValue)
16951
+ });
16952
+ });
16953
+ }
16954
+ items = transformItems(items, {
16955
+ results: results
16956
+ });
16957
+ return {
16958
+ items: items,
16959
+ widgetParams: widgetParams
16960
+ };
16961
+ },
16962
+ dispose: function dispose(param) {
16963
+ var recommendState = param.recommendState;
16964
+ unmountFn();
16965
+ return recommendState.removeParams(this.$$id);
16966
+ },
16967
+ getWidgetParameters: function getWidgetParameters(state) {
16968
+ // v4 TrendingFacetsQuery doesn't include queryParameters or
16969
+ // fallbackParameters, but the v5 API and the helper support them.
16970
+ return state.removeParams(this.$$id).addTrendingFacets({
16971
+ facetName: facetName,
16972
+ maxRecommendations: limit,
16973
+ threshold: threshold,
16974
+ fallbackParameters: fallbackParameters ? _object_spread({}, fallbackParameters, escapeHTML ? TAG_PLACEHOLDER : {}) : undefined,
16975
+ queryParameters: _object_spread({}, queryParameters, escapeHTML ? TAG_PLACEHOLDER : {}),
16976
+ $$id: this.$$id
16977
+ });
16978
+ }
16979
+ };
16980
+ };
16981
+ };
16982
+
16983
+ function useTrendingFacets(props, additionalWidgetProperties) {
16984
+ return useConnector(connectTrendingFacets, props, additionalWidgetProperties);
16985
+ }
16986
+
16683
16987
  var withUsage$1 = createDocumentationMessageGenerator({
16684
16988
  name: 'looking-similar',
16685
16989
  connector: true
@@ -17390,6 +17694,7 @@
17390
17694
  exports.useSortBy = useSortBy;
17391
17695
  exports.useStats = useStats;
17392
17696
  exports.useToggleRefinement = useToggleRefinement;
17697
+ exports.useTrendingFacets = useTrendingFacets;
17393
17698
  exports.useTrendingItems = useTrendingItems;
17394
17699
  exports.version = version$2;
17395
17700
  exports.wrapPromiseWithState = wrapPromiseWithState;