react-instantsearch-core 7.28.1 → 7.30.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.28.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch Core 7.30.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.28.1';
27
+ var version$2 = '7.30.0';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -5938,7 +5938,7 @@
5938
5938
  }
5939
5939
  }
5940
5940
 
5941
- var withUsage$s = createDocumentationMessageGenerator({
5941
+ var withUsage$t = createDocumentationMessageGenerator({
5942
5942
  name: 'configure',
5943
5943
  connector: true
5944
5944
  });
@@ -5954,7 +5954,7 @@
5954
5954
  var renderFn = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : noop, unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
5955
5955
  return function(widgetParams) {
5956
5956
  if (!widgetParams || !isPlainObject(widgetParams.searchParameters)) {
5957
- throw new Error(withUsage$s('The `searchParameters` option expects an object.'));
5957
+ throw new Error(withUsage$t('The `searchParameters` option expects an object.'));
5958
5958
  }
5959
5959
  var connectorState = {};
5960
5960
  function refine(helper) {
@@ -6535,13 +6535,13 @@
6535
6535
  }
6536
6536
  }
6537
6537
 
6538
- var withUsage$r = createDocumentationMessageGenerator({
6538
+ var withUsage$s = createDocumentationMessageGenerator({
6539
6539
  name: 'dynamic-widgets',
6540
6540
  connector: true
6541
6541
  });
6542
6542
  var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
6543
6543
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
6544
- checkRendering(renderFn, withUsage$r());
6544
+ checkRendering(renderFn, withUsage$s());
6545
6545
  return function(widgetParams) {
6546
6546
  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
6547
  '*'
@@ -6551,10 +6551,10 @@
6551
6551
  if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
6552
6552
  return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
6553
6553
  }))) {
6554
- throw new Error(withUsage$r('The `widgets` option expects an array of widgets.'));
6554
+ throw new Error(withUsage$s('The `widgets` option expects an array of widgets.'));
6555
6555
  }
6556
6556
  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))));
6557
+ throw new Error(withUsage$s("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
6558
6558
  }
6559
6559
  var localWidgets = new Map();
6560
6560
  return {
@@ -6656,7 +6656,7 @@
6656
6656
  results: results
6657
6657
  });
6658
6658
  if (!Array.isArray(attributesToRender)) {
6659
- throw new Error(withUsage$r('The `transformItems` option expects a function that returns an Array.'));
6659
+ throw new Error(withUsage$s('The `transformItems` option expects a function that returns an Array.'));
6660
6660
  }
6661
6661
  return {
6662
6662
  attributesToRender: attributesToRender,
@@ -6838,7 +6838,7 @@
6838
6838
  };
6839
6839
  }
6840
6840
 
6841
- var withUsage$q = createDocumentationMessageGenerator({
6841
+ var withUsage$r = createDocumentationMessageGenerator({
6842
6842
  name: 'index-widget'
6843
6843
  });
6844
6844
  /**
@@ -6932,7 +6932,7 @@
6932
6932
  }
6933
6933
  var index = function index(widgetParams) {
6934
6934
  if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
6935
- throw new Error(withUsage$q('The `indexName` option is required.'));
6935
+ throw new Error(withUsage$r('The `indexName` option is required.'));
6936
6936
  }
6937
6937
  // When isolated=true, we use an empty string as the default indexName.
6938
6938
  // This is intentional: isolated indices do not require a real index name.
@@ -7022,7 +7022,7 @@
7022
7022
  addWidgets: function addWidgets(widgets) {
7023
7023
  var _this = this;
7024
7024
  if (!Array.isArray(widgets)) {
7025
- throw new Error(withUsage$q('The `addWidgets` method expects an array of widgets.'));
7025
+ throw new Error(withUsage$r('The `addWidgets` method expects an array of widgets.'));
7026
7026
  }
7027
7027
  var flatWidgets = widgets.reduce(function(acc, w) {
7028
7028
  return acc.concat(Array.isArray(w) ? w : [
@@ -7032,7 +7032,7 @@
7032
7032
  if (flatWidgets.some(function(widget) {
7033
7033
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
7034
7034
  })) {
7035
- throw new Error(withUsage$q('The widget definition expects a `render` and/or an `init` method.'));
7035
+ throw new Error(withUsage$r('The widget definition expects a `render` and/or an `init` method.'));
7036
7036
  }
7037
7037
  flatWidgets.forEach(function(widget) {
7038
7038
  widget.parent = _this;
@@ -7092,7 +7092,7 @@
7092
7092
  removeWidgets: function removeWidgets(widgets) {
7093
7093
  var _this = this;
7094
7094
  if (!Array.isArray(widgets)) {
7095
- throw new Error(withUsage$q('The `removeWidgets` method expects an array of widgets.'));
7095
+ throw new Error(withUsage$r('The `removeWidgets` method expects an array of widgets.'));
7096
7096
  }
7097
7097
  var flatWidgets = widgets.reduce(function(acc, w) {
7098
7098
  return acc.concat(Array.isArray(w) ? w : [
@@ -7102,7 +7102,7 @@
7102
7102
  if (flatWidgets.some(function(widget) {
7103
7103
  return typeof widget.dispose !== 'function';
7104
7104
  })) {
7105
- throw new Error(withUsage$q('The widget definition expects a `dispose` method.'));
7105
+ throw new Error(withUsage$r('The widget definition expects a `dispose` method.'));
7106
7106
  }
7107
7107
  localWidgets = localWidgets.filter(function(widget) {
7108
7108
  return flatWidgets.indexOf(widget) === -1;
@@ -9721,7 +9721,7 @@
9721
9721
  };
9722
9722
  }
9723
9723
 
9724
- var version = '4.92.1';
9724
+ var version = '4.94.0';
9725
9725
 
9726
9726
  function hydrateSearchClient(client, results) {
9727
9727
  if (!results) {
@@ -9856,7 +9856,7 @@
9856
9856
  });
9857
9857
  }
9858
9858
 
9859
- var withUsage$p = createDocumentationMessageGenerator({
9859
+ var withUsage$q = createDocumentationMessageGenerator({
9860
9860
  name: 'instantsearch'
9861
9861
  });
9862
9862
  function defaultCreateURL() {
@@ -9912,7 +9912,7 @@
9912
9912
  _this.setMaxListeners(100);
9913
9913
  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
9914
  if (searchClient === null) {
9915
- throw new Error(withUsage$p('The `searchClient` option is required.'));
9915
+ throw new Error(withUsage$q('The `searchClient` option is required.'));
9916
9916
  }
9917
9917
  if (typeof searchClient.search !== 'function') {
9918
9918
  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 +9921,7 @@
9921
9921
  searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
9922
9922
  }
9923
9923
  if (insightsClient && typeof insightsClient !== 'function') {
9924
- throw new Error(withUsage$p('The `insightsClient` option should be a function.'));
9924
+ throw new Error(withUsage$q('The `insightsClient` option should be a function.'));
9925
9925
  }
9926
9926
  _this.client = searchClient;
9927
9927
  _this.future = future;
@@ -10069,12 +10069,12 @@
10069
10069
  * @param widgets The array of widgets to add to InstantSearch.
10070
10070
  */ function addWidgets(widgets) {
10071
10071
  if (!Array.isArray(widgets)) {
10072
- throw new Error(withUsage$p('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
10072
+ throw new Error(withUsage$q('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
10073
10073
  }
10074
10074
  if (this.compositionID && widgets.some(function(w) {
10075
10075
  return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
10076
10076
  })) {
10077
- throw new Error(withUsage$p('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
10077
+ throw new Error(withUsage$q('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
10078
10078
  }
10079
10079
  this.mainIndex.addWidgets(widgets);
10080
10080
  return this;
@@ -10103,7 +10103,7 @@
10103
10103
  * The widgets must implement a `dispose()` method to clear their states.
10104
10104
  */ function removeWidgets(widgets) {
10105
10105
  if (!Array.isArray(widgets)) {
10106
- throw new Error(withUsage$p('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
10106
+ throw new Error(withUsage$q('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
10107
10107
  }
10108
10108
  this.mainIndex.removeWidgets(widgets);
10109
10109
  return this;
@@ -10117,7 +10117,7 @@
10117
10117
  */ function start() {
10118
10118
  var _this = this;
10119
10119
  if (this.started) {
10120
- throw new Error(withUsage$p('The `start` method has already been called once.'));
10120
+ throw new Error(withUsage$q('The `start` method has already been called once.'));
10121
10121
  }
10122
10122
  // This Helper is used for the queries, we don't care about its state. The
10123
10123
  // states are managed at the `index` level. We use this Helper to create
@@ -10319,7 +10319,7 @@
10319
10319
  var _this = this;
10320
10320
  var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
10321
10321
  if (!this.mainHelper) {
10322
- throw new Error(withUsage$p('The `start` method needs to be called before `setUiState`.'));
10322
+ throw new Error(withUsage$q('The `start` method needs to be called before `setUiState`.'));
10323
10323
  }
10324
10324
  // We refresh the index UI state to update the local UI state that the
10325
10325
  // main index passes to the function form of `setUiState`.
@@ -10356,7 +10356,7 @@
10356
10356
  value: function createURL() {
10357
10357
  var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
10358
10358
  if (!this.started) {
10359
- throw new Error(withUsage$p('The `start` method needs to be called before `createURL`.'));
10359
+ throw new Error(withUsage$q('The `start` method needs to be called before `createURL`.'));
10360
10360
  }
10361
10361
  return this._createURL(nextState);
10362
10362
  }
@@ -10365,7 +10365,7 @@
10365
10365
  key: "refresh",
10366
10366
  value: function refresh() {
10367
10367
  if (!this.mainHelper) {
10368
- throw new Error(withUsage$p('The `start` method needs to be called before `refresh`.'));
10368
+ throw new Error(withUsage$q('The `start` method needs to be called before `refresh`.'));
10369
10369
  }
10370
10370
  this.mainHelper.clearCache().search();
10371
10371
  }
@@ -11046,17 +11046,17 @@
11046
11046
  return bindEventForHits;
11047
11047
  }
11048
11048
 
11049
- var withUsage$o = createDocumentationMessageGenerator({
11049
+ var withUsage$p = createDocumentationMessageGenerator({
11050
11050
  name: 'autocomplete',
11051
11051
  connector: true
11052
11052
  });
11053
11053
  var connectAutocomplete = function connectAutocomplete(renderFn) {
11054
11054
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
11055
- checkRendering(renderFn, withUsage$o());
11055
+ checkRendering(renderFn, withUsage$p());
11056
11056
  return function(widgetParams) {
11057
11057
  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
11058
  return indices;
11059
- } : _ref_transformItems;
11059
+ } : _ref_transformItems, tmp = _ref.future, _ref1 = tmp === void 0 ? {} : tmp, _ref_undefinedEmptyQuery = _ref1.undefinedEmptyQuery, undefinedEmptyQuery = _ref_undefinedEmptyQuery === void 0 ? false : _ref_undefinedEmptyQuery;
11060
11060
  var connectorState = {};
11061
11061
  return {
11062
11062
  $$type: 'ais.autocomplete',
@@ -11111,7 +11111,7 @@
11111
11111
  };
11112
11112
  });
11113
11113
  return {
11114
- currentRefinement: state.query || '',
11114
+ currentRefinement: undefinedEmptyQuery ? state.query : state.query || '',
11115
11115
  indices: transformItems(indices).map(function(transformedIndex) {
11116
11116
  return _object_spread_props(_object_spread({}, transformedIndex), {
11117
11117
  sendEvent: sendEventMap[transformedIndex.indexId]
@@ -11123,8 +11123,8 @@
11123
11123
  },
11124
11124
  getWidgetUiState: function getWidgetUiState(uiState, param) {
11125
11125
  var searchParameters = param.searchParameters;
11126
- var query = searchParameters.query || '';
11127
- if (query === '' || uiState && uiState.query === query) {
11126
+ var query = undefinedEmptyQuery ? searchParameters.query : searchParameters.query || '';
11127
+ if (!query || query === '' || uiState && uiState.query === query) {
11128
11128
  return uiState;
11129
11129
  }
11130
11130
  return _object_spread_props(_object_spread({}, uiState), {
@@ -11134,7 +11134,7 @@
11134
11134
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, param) {
11135
11135
  var uiState = param.uiState;
11136
11136
  var parameters = {
11137
- query: uiState.query || ''
11137
+ query: undefinedEmptyQuery ? uiState.query : uiState.query || ''
11138
11138
  };
11139
11139
  if (!escapeHTML) {
11140
11140
  return searchParameters.setQueryParameters(parameters);
@@ -11160,20 +11160,20 @@
11160
11160
  return useConnector(connectAutocomplete, props, additionalWidgetProperties);
11161
11161
  }
11162
11162
 
11163
- var withUsage$n = createDocumentationMessageGenerator({
11163
+ var withUsage$o = createDocumentationMessageGenerator({
11164
11164
  name: 'breadcrumb',
11165
11165
  connector: true
11166
11166
  });
11167
11167
  var connectBreadcrumb = function connectBreadcrumb(renderFn) {
11168
11168
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
11169
- checkRendering(renderFn, withUsage$n());
11169
+ checkRendering(renderFn, withUsage$o());
11170
11170
  var connectorState = {};
11171
11171
  return function(widgetParams) {
11172
11172
  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
11173
  return items;
11174
11174
  } : _ref_transformItems;
11175
11175
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
11176
- throw new Error(withUsage$n('The `attributes` option expects an array of strings.'));
11176
+ throw new Error(withUsage$o('The `attributes` option expects an array of strings.'));
11177
11177
  }
11178
11178
  var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
11179
11179
  function getRefinedState(state, facetValue) {
@@ -12630,6 +12630,30 @@
12630
12630
  return DefaultChatTransport;
12631
12631
  }(HttpChatTransport);
12632
12632
 
12633
+ function sendChatMessageFeedback(param) {
12634
+ var agentId = param.agentId, vote = param.vote, messageId = param.messageId, appId = param.appId, apiKey = param.apiKey;
12635
+ return fetch("https://".concat(appId, ".algolia.net/agent-studio/1/feedback"), {
12636
+ method: 'POST',
12637
+ body: JSON.stringify({
12638
+ messageId: messageId,
12639
+ agentId: agentId,
12640
+ vote: vote
12641
+ }),
12642
+ headers: {
12643
+ 'x-algolia-application-id': appId,
12644
+ 'x-algolia-api-key': apiKey,
12645
+ 'content-type': 'application/json'
12646
+ }
12647
+ }).then(function(response) {
12648
+ if (response.status >= 300) {
12649
+ return response.json().then(function(data) {
12650
+ throw new Error("Feedback request failed with status ".concat(response.status, ": ").concat(data.message));
12651
+ });
12652
+ }
12653
+ return response.json();
12654
+ });
12655
+ }
12656
+
12633
12657
  /**
12634
12658
  * Clears the refinements of a SearchParameters object based on rules provided.
12635
12659
  * The included attributes list is applied before the excluded attributes list. If the list
@@ -12782,7 +12806,7 @@
12782
12806
  return refinements;
12783
12807
  }
12784
12808
 
12785
- var withUsage$m = createDocumentationMessageGenerator({
12809
+ var withUsage$n = createDocumentationMessageGenerator({
12786
12810
  name: 'chat',
12787
12811
  connector: true
12788
12812
  });
@@ -12833,12 +12857,14 @@
12833
12857
  }
12834
12858
  var connectChat = function connectChat(renderFn) {
12835
12859
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
12836
- checkRendering(renderFn, withUsage$m());
12860
+ checkRendering(renderFn, withUsage$n());
12837
12861
  return function(widgetParams) {
12838
- 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, [
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, context = _ref.context, initialUserMessage = _ref.initialUserMessage, options = _object_without_properties(_ref, [
12839
12863
  "resume",
12840
12864
  "tools",
12841
- "type"
12865
+ "type",
12866
+ "context",
12867
+ "initialUserMessage"
12842
12868
  ]);
12843
12869
  var _chatInstance;
12844
12870
  var input = '';
@@ -12849,7 +12875,11 @@
12849
12875
  var setOpen;
12850
12876
  var focusInput;
12851
12877
  var setIsClearing;
12878
+ var setFeedbackState;
12852
12879
  var agentId = 'agentId' in options ? options.agentId : undefined;
12880
+ var feedbackState = {};
12881
+ var _sendChatMessageFeedback;
12882
+ var feedbackAbortController;
12853
12883
  // Extract suggestions from the last assistant message's data-suggestions part
12854
12884
  var getSuggestionsFromMessages = function getSuggestionsFromMessages(messages) {
12855
12885
  // Find the last assistant message (iterate from end)
@@ -12876,11 +12906,16 @@
12876
12906
  if (!_chatInstance.messages || _chatInstance.messages.length === 0) {
12877
12907
  return;
12878
12908
  }
12909
+ var status = _chatInstance.status;
12910
+ if (status === 'submitted' || status === 'streaming') {
12911
+ _chatInstance.stop();
12912
+ }
12879
12913
  setIsClearing(true);
12880
12914
  };
12881
12915
  var onClearTransitionEnd = function onClearTransitionEnd() {
12882
12916
  setMessages([]);
12883
12917
  _chatInstance.clearError();
12918
+ feedbackState = {};
12884
12919
  setIsClearing(false);
12885
12920
  };
12886
12921
  var makeChatInstance = function makeChatInstance(instantSearchInstance) {
@@ -12924,7 +12959,7 @@
12924
12959
  }
12925
12960
  if ('agentId' in options && options.agentId) {
12926
12961
  if (!appId || !apiKey) {
12927
- throw new Error(withUsage$m('Could not extract Algolia credentials from the search client.'));
12962
+ throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
12928
12963
  }
12929
12964
  var baseApi = "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5");
12930
12965
  transport = new DefaultChatTransport({
@@ -12950,7 +12985,7 @@
12950
12985
  });
12951
12986
  }
12952
12987
  if (!transport) {
12953
- throw new Error(withUsage$m('You need to provide either an `agentId` or a `transport`.'));
12988
+ throw new Error(withUsage$n('You need to provide either an `agentId` or a `transport`.'));
12954
12989
  }
12955
12990
  if ('chat' in options) {
12956
12991
  return options.chat;
@@ -13015,12 +13050,44 @@
13015
13050
  isClearing = value;
13016
13051
  render();
13017
13052
  };
13053
+ setFeedbackState = function setFeedbackState(messageId, state) {
13054
+ feedbackState = _object_spread_props(_object_spread({}, feedbackState), _define_property({}, messageId, state));
13055
+ render();
13056
+ };
13057
+ var feedback = 'feedback' in options ? options.feedback : undefined;
13058
+ if (agentId && feedback) {
13059
+ var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
13060
+ if (!appId || !apiKey) {
13061
+ throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
13062
+ }
13063
+ feedbackAbortController = new AbortController();
13064
+ _sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
13065
+ if (feedbackState[messageId] !== undefined) {
13066
+ return;
13067
+ }
13068
+ setFeedbackState(messageId, 'sending');
13069
+ sendChatMessageFeedback({
13070
+ agentId: agentId,
13071
+ vote: vote,
13072
+ messageId: messageId,
13073
+ appId: appId,
13074
+ apiKey: apiKey
13075
+ }).finally(function() {
13076
+ setFeedbackState(messageId, vote);
13077
+ });
13078
+ };
13079
+ }
13018
13080
  _chatInstance['~registerErrorCallback'](render);
13019
13081
  _chatInstance['~registerMessagesCallback'](render);
13020
13082
  _chatInstance['~registerStatusCallback'](render);
13021
13083
  if (resume) {
13022
13084
  _chatInstance.resumeStream();
13023
13085
  }
13086
+ if (initialUserMessage && !resume && _chatInstance.messages.length === 0) {
13087
+ _chatInstance.sendMessage({
13088
+ text: initialUserMessage
13089
+ });
13090
+ }
13024
13091
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
13025
13092
  instantSearchInstance: instantSearchInstance
13026
13093
  }), true);
@@ -13056,10 +13123,65 @@
13056
13123
  var _param = _sliced_to_array(param, 2), key = _param[0], tool = _param[1];
13057
13124
  var toolWithAddToolResult = _object_spread_props(_object_spread({}, tool), {
13058
13125
  addToolResult: _chatInstance.addToolResult,
13059
- applyFilters: applyFilters
13126
+ applyFilters: applyFilters,
13127
+ sendEvent: sendEvent
13060
13128
  });
13061
13129
  toolsWithAddToolResult[key] = toolWithAddToolResult;
13062
13130
  });
13131
+ var sendMessageWithContext = function sendMessageWithContext(message) {
13132
+ for(var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
13133
+ rest[_key - 1] = arguments[_key];
13134
+ }
13135
+ var _chatInstance1;
13136
+ if (!context || !message) {
13137
+ var _chatInstance2;
13138
+ return (_chatInstance2 = _chatInstance).sendMessage.apply(_chatInstance2, [
13139
+ message
13140
+ ].concat(_to_consumable_array(rest)));
13141
+ }
13142
+ var resolvedContext = typeof context === 'function' ? context() : context;
13143
+ var serializedContext;
13144
+ try {
13145
+ serializedContext = JSON.stringify(resolvedContext);
13146
+ } catch (unused) {
13147
+ var _chatInstance3;
13148
+ return (_chatInstance3 = _chatInstance).sendMessage.apply(_chatInstance3, [
13149
+ message
13150
+ ].concat(_to_consumable_array(rest)));
13151
+ }
13152
+ var contextTextPart = {
13153
+ type: 'text',
13154
+ text: '<context>'.concat(serializedContext).concat('</context>')
13155
+ };
13156
+ if ('parts' in message && message.parts) {
13157
+ var _chatInstance4;
13158
+ return (_chatInstance4 = _chatInstance).sendMessage.apply(_chatInstance4, [
13159
+ _object_spread_props(_object_spread({}, message), {
13160
+ parts: [
13161
+ contextTextPart
13162
+ ].concat(_to_consumable_array(message.parts)),
13163
+ text: undefined,
13164
+ files: undefined
13165
+ })
13166
+ ].concat(_to_consumable_array(rest)));
13167
+ }
13168
+ var textContent = 'text' in message && message.text ? message.text : '';
13169
+ return (_chatInstance1 = _chatInstance).sendMessage.apply(_chatInstance1, [
13170
+ {
13171
+ parts: [
13172
+ contextTextPart,
13173
+ {
13174
+ type: 'text',
13175
+ text: textContent
13176
+ }
13177
+ ],
13178
+ metadata: message.metadata,
13179
+ messageId: message.messageId,
13180
+ files: undefined,
13181
+ text: undefined
13182
+ }
13183
+ ].concat(_to_consumable_array(rest)));
13184
+ };
13063
13185
  return {
13064
13186
  indexUiState: instantSearchInstance.getUiState()[parent.getIndexId()],
13065
13187
  input: input,
@@ -13075,6 +13197,8 @@
13075
13197
  clearMessages: clearMessages,
13076
13198
  onClearTransitionEnd: onClearTransitionEnd,
13077
13199
  tools: toolsWithAddToolResult,
13200
+ sendChatMessageFeedback: _sendChatMessageFeedback,
13201
+ feedbackState: feedbackState,
13078
13202
  widgetParams: widgetParams,
13079
13203
  // Chat instance render state
13080
13204
  addToolResult: _chatInstance.addToolResult,
@@ -13084,12 +13208,13 @@
13084
13208
  messages: _chatInstance.messages,
13085
13209
  regenerate: _chatInstance.regenerate,
13086
13210
  resumeStream: _chatInstance.resumeStream,
13087
- sendMessage: _chatInstance.sendMessage,
13211
+ sendMessage: sendMessageWithContext,
13088
13212
  status: _chatInstance.status,
13089
13213
  stop: _chatInstance.stop
13090
13214
  };
13091
13215
  },
13092
13216
  dispose: function dispose() {
13217
+ feedbackAbortController === null || feedbackAbortController === void 0 ? void 0 : feedbackAbortController.abort();
13093
13218
  unmountFn();
13094
13219
  },
13095
13220
  shouldRender: function shouldRender() {
@@ -13106,13 +13231,13 @@
13106
13231
  return useConnector(connectChat, props, additionalWidgetProperties);
13107
13232
  }
13108
13233
 
13109
- var withUsage$l = createDocumentationMessageGenerator({
13234
+ var withUsage$m = createDocumentationMessageGenerator({
13110
13235
  name: 'clear-refinements',
13111
13236
  connector: true
13112
13237
  });
13113
13238
  var connectClearRefinements = function connectClearRefinements(renderFn) {
13114
13239
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13115
- checkRendering(renderFn, withUsage$l());
13240
+ checkRendering(renderFn, withUsage$m());
13116
13241
  return function(widgetParams) {
13117
13242
  var _ref = widgetParams || {}, _ref_includedAttributes = _ref.includedAttributes, includedAttributes = _ref_includedAttributes === void 0 ? [] : _ref_includedAttributes, _ref_excludedAttributes = _ref.excludedAttributes, excludedAttributes = _ref_excludedAttributes === void 0 ? [
13118
13243
  'query'
@@ -13120,7 +13245,7 @@
13120
13245
  return items;
13121
13246
  } : _ref_transformItems;
13122
13247
  if (widgetParams && widgetParams.includedAttributes && widgetParams.excludedAttributes) {
13123
- throw new Error(withUsage$l('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
13248
+ throw new Error(withUsage$m('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
13124
13249
  }
13125
13250
  var connectorState = {
13126
13251
  refine: noop,
@@ -13223,16 +13348,16 @@
13223
13348
  return useConnector(connectClearRefinements, props, additionalWidgetProperties);
13224
13349
  }
13225
13350
 
13226
- var withUsage$k = createDocumentationMessageGenerator({
13351
+ var withUsage$l = createDocumentationMessageGenerator({
13227
13352
  name: 'current-refinements',
13228
13353
  connector: true
13229
13354
  });
13230
13355
  var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
13231
13356
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13232
- checkRendering(renderFn, withUsage$k());
13357
+ checkRendering(renderFn, withUsage$l());
13233
13358
  return function(widgetParams) {
13234
13359
  if ((widgetParams || {}).includedAttributes && (widgetParams || {}).excludedAttributes) {
13235
- throw new Error(withUsage$k('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
13360
+ throw new Error(withUsage$l('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
13236
13361
  }
13237
13362
  var _ref = widgetParams || {}, includedAttributes = _ref.includedAttributes, _ref_excludedAttributes = _ref.excludedAttributes, excludedAttributes = _ref_excludedAttributes === void 0 ? [
13238
13363
  'query'
@@ -13421,19 +13546,19 @@
13421
13546
  });
13422
13547
  }
13423
13548
 
13424
- var withUsage$j = createDocumentationMessageGenerator({
13549
+ var withUsage$k = createDocumentationMessageGenerator({
13425
13550
  name: 'frequently-bought-together',
13426
13551
  connector: true
13427
13552
  });
13428
13553
  var connectFrequentlyBoughtTogether = function connectFrequentlyBoughtTogether(renderFn) {
13429
13554
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13430
- checkRendering(renderFn, withUsage$j());
13555
+ checkRendering(renderFn, withUsage$k());
13431
13556
  return function(widgetParams) {
13432
13557
  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) {
13433
13558
  return items;
13434
13559
  } : _ref_transformItems, objectIDs = _ref.objectIDs, limit = _ref.limit, threshold = _ref.threshold, fallbackParameters = _ref.fallbackParameters, queryParameters = _ref.queryParameters;
13435
13560
  if (!objectIDs || objectIDs.length === 0) {
13436
- throw new Error(withUsage$j('The `objectIDs` option is required.'));
13561
+ throw new Error(withUsage$k('The `objectIDs` option is required.'));
13437
13562
  }
13438
13563
  var sendEvent;
13439
13564
  return {
@@ -13571,7 +13696,7 @@
13571
13696
  return insideBoundingBoxStringToBoundingBox(value);
13572
13697
  }
13573
13698
 
13574
- var withUsage$i = createDocumentationMessageGenerator({
13699
+ var withUsage$j = createDocumentationMessageGenerator({
13575
13700
  name: 'geo-search',
13576
13701
  connector: true
13577
13702
  });
@@ -13595,7 +13720,7 @@
13595
13720
  * Currently, the feature is not compatible with multiple values in the _geoloc attribute.
13596
13721
  */ var connectGeoSearch = function connectGeoSearch(renderFn) {
13597
13722
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13598
- checkRendering(renderFn, withUsage$i());
13723
+ checkRendering(renderFn, withUsage$j());
13599
13724
  return function(widgetParams) {
13600
13725
  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) {
13601
13726
  return items;
@@ -13813,7 +13938,7 @@
13813
13938
  return sendEventForFacet;
13814
13939
  }
13815
13940
 
13816
- var withUsage$h = createDocumentationMessageGenerator({
13941
+ var withUsage$i = createDocumentationMessageGenerator({
13817
13942
  name: 'hierarchical-menu',
13818
13943
  connector: true
13819
13944
  });
@@ -13834,16 +13959,16 @@
13834
13959
  * @return {function(CustomHierarchicalMenuWidgetParams)} Re-usable widget factory for a custom **HierarchicalMenu** widget.
13835
13960
  */ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
13836
13961
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13837
- checkRendering(renderFn, withUsage$h());
13962
+ checkRendering(renderFn, withUsage$i());
13838
13963
  return function(widgetParams) {
13839
13964
  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) {
13840
13965
  return items;
13841
13966
  } : _ref_transformItems;
13842
13967
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
13843
- throw new Error(withUsage$h('The `attributes` option expects an array of strings.'));
13968
+ throw new Error(withUsage$i('The `attributes` option expects an array of strings.'));
13844
13969
  }
13845
13970
  if (showMore === true && showMoreLimit <= limit) {
13846
- throw new Error(withUsage$h('The `showMoreLimit` option must be greater than `limit`.'));
13971
+ throw new Error(withUsage$i('The `showMoreLimit` option must be greater than `limit`.'));
13847
13972
  }
13848
13973
  // we need to provide a hierarchicalFacet name for the search state
13849
13974
  // so that we can always map $hierarchicalFacetName => real attributes
@@ -14035,13 +14160,13 @@
14035
14160
  return useConnector(connectHierarchicalMenu, props, additionalWidgetProperties);
14036
14161
  }
14037
14162
 
14038
- var withUsage$g = createDocumentationMessageGenerator({
14163
+ var withUsage$h = createDocumentationMessageGenerator({
14039
14164
  name: 'hits',
14040
14165
  connector: true
14041
14166
  });
14042
14167
  var connectHits = function connectHits(renderFn) {
14043
14168
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14044
- checkRendering(renderFn, withUsage$g());
14169
+ checkRendering(renderFn, withUsage$h());
14045
14170
  return function(widgetParams) {
14046
14171
  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) {
14047
14172
  return items;
@@ -14139,29 +14264,29 @@
14139
14264
  return useConnector(connectHits, props, additionalWidgetProperties);
14140
14265
  }
14141
14266
 
14142
- var withUsage$f = createDocumentationMessageGenerator({
14267
+ var withUsage$g = createDocumentationMessageGenerator({
14143
14268
  name: 'hits-per-page',
14144
14269
  connector: true
14145
14270
  });
14146
14271
  var connectHitsPerPage = function connectHitsPerPage(renderFn) {
14147
14272
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14148
- checkRendering(renderFn, withUsage$f());
14273
+ checkRendering(renderFn, withUsage$g());
14149
14274
  return function(widgetParams) {
14150
14275
  var _ref = widgetParams || {}, userItems = _ref.items, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
14151
14276
  return items;
14152
14277
  } : _ref_transformItems;
14153
14278
  if (!Array.isArray(userItems)) {
14154
- throw new Error(withUsage$f('The `items` option expects an array of objects.'));
14279
+ throw new Error(withUsage$g('The `items` option expects an array of objects.'));
14155
14280
  }
14156
14281
  var items = userItems;
14157
14282
  var defaultItems = items.filter(function(item) {
14158
14283
  return item.default === true;
14159
14284
  });
14160
14285
  if (defaultItems.length === 0) {
14161
- throw new Error(withUsage$f("A default value must be specified in `items`."));
14286
+ throw new Error(withUsage$g("A default value must be specified in `items`."));
14162
14287
  }
14163
14288
  if (defaultItems.length > 1) {
14164
- throw new Error(withUsage$f('More than one default value is specified in `items`.'));
14289
+ throw new Error(withUsage$g('More than one default value is specified in `items`.'));
14165
14290
  }
14166
14291
  var defaultItem = defaultItems[0];
14167
14292
  var normalizeItems = function normalizeItems(param) {
@@ -14280,7 +14405,7 @@
14280
14405
  });
14281
14406
  }
14282
14407
 
14283
- var withUsage$e = createDocumentationMessageGenerator({
14408
+ var withUsage$f = createDocumentationMessageGenerator({
14284
14409
  name: 'infinite-hits',
14285
14410
  connector: true
14286
14411
  });
@@ -14326,7 +14451,7 @@
14326
14451
  }
14327
14452
  var connectInfiniteHits = function connectInfiniteHits(renderFn) {
14328
14453
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14329
- checkRendering(renderFn, withUsage$e());
14454
+ checkRendering(renderFn, withUsage$f());
14330
14455
  return function(widgetParams) {
14331
14456
  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) {
14332
14457
  return items;
@@ -14532,7 +14657,7 @@
14532
14657
  return useConnector(connectInfiniteHits, props, additionalWidgetProperties);
14533
14658
  }
14534
14659
 
14535
- var withUsage$d = createDocumentationMessageGenerator({
14660
+ var withUsage$e = createDocumentationMessageGenerator({
14536
14661
  name: 'menu',
14537
14662
  connector: true
14538
14663
  });
@@ -14550,16 +14675,16 @@
14550
14675
  * **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.
14551
14676
  */ var connectMenu = function connectMenu(renderFn) {
14552
14677
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14553
- checkRendering(renderFn, withUsage$d());
14678
+ checkRendering(renderFn, withUsage$e());
14554
14679
  return function(widgetParams) {
14555
14680
  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) {
14556
14681
  return items;
14557
14682
  } : _ref_transformItems;
14558
14683
  if (!attribute) {
14559
- throw new Error(withUsage$d('The `attribute` option is required.'));
14684
+ throw new Error(withUsage$e('The `attribute` option is required.'));
14560
14685
  }
14561
14686
  if (showMore === true && showMoreLimit <= limit) {
14562
- throw new Error(withUsage$d('The `showMoreLimit` option must be greater than `limit`.'));
14687
+ throw new Error(withUsage$e('The `showMoreLimit` option must be greater than `limit`.'));
14563
14688
  }
14564
14689
  var sendEvent;
14565
14690
  var _createURL;
@@ -14729,7 +14854,7 @@
14729
14854
  return typeof value === 'number' && isFinite(value);
14730
14855
  }
14731
14856
 
14732
- var withUsage$c = createDocumentationMessageGenerator({
14857
+ var withUsage$d = createDocumentationMessageGenerator({
14733
14858
  name: 'numeric-menu',
14734
14859
  connector: true
14735
14860
  });
@@ -14748,16 +14873,16 @@
14748
14873
  };
14749
14874
  var connectNumericMenu = function connectNumericMenu(renderFn) {
14750
14875
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14751
- checkRendering(renderFn, withUsage$c());
14876
+ checkRendering(renderFn, withUsage$d());
14752
14877
  return function(widgetParams) {
14753
14878
  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) {
14754
14879
  return item;
14755
14880
  } : _ref_transformItems;
14756
14881
  if (attribute === '') {
14757
- throw new Error(withUsage$c('The `attribute` option is required.'));
14882
+ throw new Error(withUsage$d('The `attribute` option is required.'));
14758
14883
  }
14759
14884
  if (!items || items.length === 0) {
14760
- throw new Error(withUsage$c('The `items` option expects an array of objects.'));
14885
+ throw new Error(withUsage$d('The `items` option expects an array of objects.'));
14761
14886
  }
14762
14887
  var prepareItems = function prepareItems(state) {
14763
14888
  return items.map(function(param) {
@@ -15072,7 +15197,7 @@
15072
15197
  return Paginator;
15073
15198
  }();
15074
15199
 
15075
- var withUsage$b = createDocumentationMessageGenerator({
15200
+ var withUsage$c = createDocumentationMessageGenerator({
15076
15201
  name: 'pagination',
15077
15202
  connector: true
15078
15203
  });
@@ -15084,7 +15209,7 @@
15084
15209
  * 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).
15085
15210
  */ var connectPagination = function connectPagination(renderFn) {
15086
15211
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15087
- checkRendering(renderFn, withUsage$b());
15212
+ checkRendering(renderFn, withUsage$c());
15088
15213
  return function(widgetParams) {
15089
15214
  var _ref = widgetParams || {}, totalPages = _ref.totalPages, _ref_padding = _ref.padding, padding = _ref_padding === void 0 ? 3 : _ref_padding;
15090
15215
  var pager = new Paginator({
@@ -15201,7 +15326,7 @@
15201
15326
  };
15202
15327
  }
15203
15328
 
15204
- var withUsage$a = createDocumentationMessageGenerator({
15329
+ var withUsage$b = createDocumentationMessageGenerator({
15205
15330
  name: 'query-rules',
15206
15331
  connector: true
15207
15332
  });
@@ -15257,7 +15382,7 @@
15257
15382
  }
15258
15383
  var connectQueryRules = function connectQueryRules(render) {
15259
15384
  var unmount = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15260
- checkRendering(render, withUsage$a());
15385
+ checkRendering(render, withUsage$b());
15261
15386
  return function(widgetParams) {
15262
15387
  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) {
15263
15388
  return rules;
@@ -15266,7 +15391,7 @@
15266
15391
  } : _ref_transformItems;
15267
15392
  Object.keys(trackedFilters).forEach(function(facetName) {
15268
15393
  if (typeof trackedFilters[facetName] !== 'function') {
15269
- throw new Error(withUsage$a("'The \"".concat(facetName, '" filter value in the `trackedFilters` option expects a function.')));
15394
+ throw new Error(withUsage$b("'The \"".concat(facetName, '" filter value in the `trackedFilters` option expects a function.')));
15270
15395
  }
15271
15396
  });
15272
15397
  var hasTrackedFilters = Object.keys(trackedFilters).length > 0;
@@ -15342,7 +15467,7 @@
15342
15467
  return useConnector(connectQueryRules, props, additionalWidgetProperties);
15343
15468
  }
15344
15469
 
15345
- var withUsage$9 = createDocumentationMessageGenerator({
15470
+ var withUsage$a = createDocumentationMessageGenerator({
15346
15471
  name: 'range-input',
15347
15472
  connector: true
15348
15473
  }, {
@@ -15366,14 +15491,14 @@
15366
15491
  * information about the min and max bounds for the current result set.
15367
15492
  */ var connectRange = function connectRange(renderFn) {
15368
15493
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15369
- checkRendering(renderFn, withUsage$9());
15494
+ checkRendering(renderFn, withUsage$a());
15370
15495
  return function(widgetParams) {
15371
15496
  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;
15372
15497
  if (!attribute) {
15373
- throw new Error(withUsage$9('The `attribute` option is required.'));
15498
+ throw new Error(withUsage$a('The `attribute` option is required.'));
15374
15499
  }
15375
15500
  if (isFiniteNumber(minBound) && isFiniteNumber(maxBound) && minBound > maxBound) {
15376
- throw new Error(withUsage$9("The `max` option can't be lower than `min`."));
15501
+ throw new Error(withUsage$a("The `max` option can't be lower than `min`."));
15377
15502
  }
15378
15503
  var formatToNumber = function formatToNumber(v) {
15379
15504
  return Number(Number(v).toFixed(precision));
@@ -15593,7 +15718,7 @@
15593
15718
  return useConnector(connectRange, props, additionalWidgetProperties);
15594
15719
  }
15595
15720
 
15596
- var withUsage$8 = createDocumentationMessageGenerator({
15721
+ var withUsage$9 = createDocumentationMessageGenerator({
15597
15722
  name: 'refinement-list',
15598
15723
  connector: true
15599
15724
  });
@@ -15615,19 +15740,19 @@
15615
15740
  * - a `searchForItems()` function to search within the items.
15616
15741
  */ var connectRefinementList = function connectRefinementList(renderFn) {
15617
15742
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15618
- checkRendering(renderFn, withUsage$8());
15743
+ checkRendering(renderFn, withUsage$9());
15619
15744
  return function(widgetParams) {
15620
15745
  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) {
15621
15746
  return items;
15622
15747
  } : _ref_transformItems;
15623
15748
  if (!attribute) {
15624
- throw new Error(withUsage$8('The `attribute` option is required.'));
15749
+ throw new Error(withUsage$9('The `attribute` option is required.'));
15625
15750
  }
15626
15751
  if (!/^(and|or)$/.test(operator)) {
15627
- throw new Error(withUsage$8('The `operator` must one of: `"and"`, `"or"` (got "'.concat(operator, '").')));
15752
+ throw new Error(withUsage$9('The `operator` must one of: `"and"`, `"or"` (got "'.concat(operator, '").')));
15628
15753
  }
15629
15754
  if (showMore === true && showMoreLimit <= limit) {
15630
- throw new Error(withUsage$8('`showMoreLimit` should be greater than `limit`.'));
15755
+ throw new Error(withUsage$9('`showMoreLimit` should be greater than `limit`.'));
15631
15756
  }
15632
15757
  var formatItems = function formatItems(_0) {
15633
15758
  var label = _0.name, value = _0.escapedValue, item = _object_without_properties(_0, [
@@ -15855,19 +15980,19 @@
15855
15980
  return useConnector(connectRefinementList, props, additionalWidgetProperties);
15856
15981
  }
15857
15982
 
15858
- var withUsage$7 = createDocumentationMessageGenerator({
15983
+ var withUsage$8 = createDocumentationMessageGenerator({
15859
15984
  name: 'related-products',
15860
15985
  connector: true
15861
15986
  });
15862
15987
  var connectRelatedProducts = function connectRelatedProducts(renderFn) {
15863
15988
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15864
- checkRendering(renderFn, withUsage$7());
15989
+ checkRendering(renderFn, withUsage$8());
15865
15990
  return function(widgetParams) {
15866
15991
  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) {
15867
15992
  return items;
15868
15993
  } : _ref_transformItems;
15869
15994
  if (!objectIDs || objectIDs.length === 0) {
15870
- throw new Error(withUsage$7('The `objectIDs` option is required.'));
15995
+ throw new Error(withUsage$8('The `objectIDs` option is required.'));
15871
15996
  }
15872
15997
  var sendEvent;
15873
15998
  return {
@@ -15943,7 +16068,7 @@
15943
16068
  return useConnector(connectRelatedProducts, props, additionalWidgetProperties);
15944
16069
  }
15945
16070
 
15946
- var withUsage$6 = createDocumentationMessageGenerator({
16071
+ var withUsage$7 = createDocumentationMessageGenerator({
15947
16072
  name: 'search-box',
15948
16073
  connector: true
15949
16074
  });
@@ -15957,7 +16082,7 @@
15957
16082
  * may be impacted by the `queryHook` widget parameter.
15958
16083
  */ var connectSearchBox = function connectSearchBox(renderFn) {
15959
16084
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15960
- checkRendering(renderFn, withUsage$6());
16085
+ checkRendering(renderFn, withUsage$7());
15961
16086
  return function(widgetParams) {
15962
16087
  var _ref = widgetParams || {}, _ref_queryHook = _ref.queryHook, queryHook = _ref_queryHook === void 0 ? defaultQueryHook : _ref_queryHook;
15963
16088
  var _refine;
@@ -16028,7 +16153,7 @@
16028
16153
  return useConnector(connectSearchBox, props, additionalWidgetProperties);
16029
16154
  }
16030
16155
 
16031
- var withUsage$5 = createDocumentationMessageGenerator({
16156
+ var withUsage$6 = createDocumentationMessageGenerator({
16032
16157
  name: 'sort-by',
16033
16158
  connector: true
16034
16159
  });
@@ -16048,14 +16173,14 @@
16048
16173
  }
16049
16174
  var connectSortBy = function connectSortBy(renderFn) {
16050
16175
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16051
- checkRendering(renderFn, withUsage$5());
16176
+ checkRendering(renderFn, withUsage$6());
16052
16177
  var connectorState = {};
16053
16178
  return function(widgetParams) {
16054
16179
  var _ref = widgetParams || {}, items = _ref.items, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(x) {
16055
16180
  return x;
16056
16181
  } : _ref_transformItems;
16057
16182
  if (!Array.isArray(items)) {
16058
- throw new Error(withUsage$5('The `items` option expects an array of objects.'));
16183
+ throw new Error(withUsage$6('The `items` option expects an array of objects.'));
16059
16184
  }
16060
16185
  var itemsLookup = {};
16061
16186
  items.forEach(function(item, index) {
@@ -16063,10 +16188,10 @@
16063
16188
  var hasStrategy = 'strategy' in item && item.strategy !== undefined;
16064
16189
  // Validate mutual exclusivity
16065
16190
  if (hasValue && hasStrategy) {
16066
- throw new Error(withUsage$5("Item at index ".concat(index, ' cannot have both "value" and "strategy" properties.')));
16191
+ throw new Error(withUsage$6("Item at index ".concat(index, ' cannot have both "value" and "strategy" properties.')));
16067
16192
  }
16068
16193
  if (!hasValue && !hasStrategy) {
16069
- throw new Error(withUsage$5("Item at index ".concat(index, ' must have either a "value" or "strategy" property.')));
16194
+ throw new Error(withUsage$6("Item at index ".concat(index, ' must have either a "value" or "strategy" property.')));
16070
16195
  }
16071
16196
  var itemValue = getItemValue(item);
16072
16197
  itemsLookup[itemValue] = item;
@@ -16081,7 +16206,7 @@
16081
16206
  return 'strategy' in item && item.strategy;
16082
16207
  });
16083
16208
  if (hasStrategyItems && !instantSearchInstance.compositionID) {
16084
- throw new Error(withUsage$5('Sorting strategies can only be used in composition mode. Please provide a "compositionID" to your InstantSearch instance.'));
16209
+ throw new Error(withUsage$6('Sorting strategies can only be used in composition mode. Please provide a "compositionID" to your InstantSearch instance.'));
16085
16210
  }
16086
16211
  var widgetRenderState = this.getWidgetRenderState(initOptions);
16087
16212
  var currentIndex = widgetRenderState.currentRefinement;
@@ -16194,13 +16319,13 @@
16194
16319
  return useConnector(connectSortBy, props, additionalWidgetProperties);
16195
16320
  }
16196
16321
 
16197
- var withUsage$4 = createDocumentationMessageGenerator({
16322
+ var withUsage$5 = createDocumentationMessageGenerator({
16198
16323
  name: 'stats',
16199
16324
  connector: true
16200
16325
  });
16201
16326
  var connectStats = function connectStats(renderFn) {
16202
16327
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16203
- checkRendering(renderFn, withUsage$4());
16328
+ checkRendering(renderFn, withUsage$5());
16204
16329
  return function(widgetParams) {
16205
16330
  return {
16206
16331
  $$type: 'ais.stats',
@@ -16259,7 +16384,7 @@
16259
16384
  return useConnector(connectStats, props, additionalWidgetProperties);
16260
16385
  }
16261
16386
 
16262
- var withUsage$3 = createDocumentationMessageGenerator({
16387
+ var withUsage$4 = createDocumentationMessageGenerator({
16263
16388
  name: 'toggle-refinement',
16264
16389
  connector: true
16265
16390
  });
@@ -16310,11 +16435,11 @@
16310
16435
  * - switch between two values.
16311
16436
  */ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
16312
16437
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16313
- checkRendering(renderFn, withUsage$3());
16438
+ checkRendering(renderFn, withUsage$4());
16314
16439
  return function(widgetParams) {
16315
16440
  var _ref = widgetParams || {}, attribute = _ref.attribute, tmp = _ref.on, userOn = tmp === void 0 ? true : tmp, userOff = _ref.off;
16316
16441
  if (!attribute) {
16317
- throw new Error(withUsage$3('The `attribute` option is required.'));
16442
+ throw new Error(withUsage$4('The `attribute` option is required.'));
16318
16443
  }
16319
16444
  var hasAnOffValue = userOff !== undefined;
16320
16445
  // even though facet values can be numbers and boolean,
@@ -16535,19 +16660,19 @@
16535
16660
  return useConnector(connectToggleRefinement, props, additionalWidgetProperties);
16536
16661
  }
16537
16662
 
16538
- var withUsage$2 = createDocumentationMessageGenerator({
16663
+ var withUsage$3 = createDocumentationMessageGenerator({
16539
16664
  name: 'trending-items',
16540
16665
  connector: true
16541
16666
  });
16542
16667
  var connectTrendingItems = function connectTrendingItems(renderFn) {
16543
16668
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16544
- checkRendering(renderFn, withUsage$2());
16669
+ checkRendering(renderFn, withUsage$3());
16545
16670
  return function(widgetParams) {
16546
16671
  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) {
16547
16672
  return items;
16548
16673
  } : _ref_transformItems;
16549
16674
  if (facetName && !facetValue || !facetName && facetValue) {
16550
- throw new Error(withUsage$2("When you provide facetName (received type ".concat(getObjectType(facetName), "), you must also provide facetValue (received type ").concat(getObjectType(facetValue), ").")));
16675
+ throw new Error(withUsage$3("When you provide facetName (received type ".concat(getObjectType(facetName), "), you must also provide facetValue (received type ").concat(getObjectType(facetValue), ").")));
16551
16676
  }
16552
16677
  var sendEvent;
16553
16678
  return {
@@ -16621,6 +16746,94 @@
16621
16746
  return useConnector(connectTrendingItems, props, additionalWidgetProperties);
16622
16747
  }
16623
16748
 
16749
+ var withUsage$2 = createDocumentationMessageGenerator({
16750
+ name: 'trending-facets',
16751
+ connector: true
16752
+ });
16753
+ var connectTrendingFacets = function connectTrendingFacets(renderFn) {
16754
+ var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16755
+ checkRendering(renderFn, withUsage$2());
16756
+ return function(widgetParams) {
16757
+ 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) {
16758
+ return items;
16759
+ } : _ref_transformItems;
16760
+ if (!facetName) {
16761
+ throw new Error(withUsage$2('The `facetName` option is required.'));
16762
+ }
16763
+ return {
16764
+ dependsOn: 'recommend',
16765
+ $$type: 'ais.trendingFacets',
16766
+ init: function init(initOptions) {
16767
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
16768
+ instantSearchInstance: initOptions.instantSearchInstance
16769
+ }), true);
16770
+ },
16771
+ render: function render(renderOptions) {
16772
+ var renderState = this.getWidgetRenderState(renderOptions);
16773
+ renderFn(_object_spread_props(_object_spread({}, renderState), {
16774
+ instantSearchInstance: renderOptions.instantSearchInstance
16775
+ }), false);
16776
+ },
16777
+ getRenderState: function getRenderState(renderState) {
16778
+ return renderState;
16779
+ },
16780
+ getWidgetRenderState: function getWidgetRenderState(param) {
16781
+ var results = param.results;
16782
+ param.helper;
16783
+ param.instantSearchInstance;
16784
+ if (results === null || results === undefined) {
16785
+ return {
16786
+ items: [],
16787
+ widgetParams: widgetParams
16788
+ };
16789
+ }
16790
+ var items = (results.hits || []).map(function(hit) {
16791
+ return {
16792
+ facetName: hit.facetName,
16793
+ facetValue: hit.facetValue,
16794
+ _score: hit._score
16795
+ };
16796
+ });
16797
+ if (escapeHTML) {
16798
+ items = items.map(function(item) {
16799
+ return _object_spread_props(_object_spread({}, item), {
16800
+ facetValue: escape$1(item.facetValue)
16801
+ });
16802
+ });
16803
+ }
16804
+ items = transformItems(items, {
16805
+ results: results
16806
+ });
16807
+ return {
16808
+ items: items,
16809
+ widgetParams: widgetParams
16810
+ };
16811
+ },
16812
+ dispose: function dispose(param) {
16813
+ var recommendState = param.recommendState;
16814
+ unmountFn();
16815
+ return recommendState.removeParams(this.$$id);
16816
+ },
16817
+ getWidgetParameters: function getWidgetParameters(state) {
16818
+ // v4 TrendingFacetsQuery doesn't include queryParameters or
16819
+ // fallbackParameters, but the v5 API and the helper support them.
16820
+ return state.removeParams(this.$$id).addTrendingFacets({
16821
+ facetName: facetName,
16822
+ maxRecommendations: limit,
16823
+ threshold: threshold,
16824
+ fallbackParameters: fallbackParameters ? _object_spread({}, fallbackParameters, escapeHTML ? TAG_PLACEHOLDER : {}) : undefined,
16825
+ queryParameters: _object_spread({}, queryParameters, escapeHTML ? TAG_PLACEHOLDER : {}),
16826
+ $$id: this.$$id
16827
+ });
16828
+ }
16829
+ };
16830
+ };
16831
+ };
16832
+
16833
+ function useTrendingFacets(props, additionalWidgetProperties) {
16834
+ return useConnector(connectTrendingFacets, props, additionalWidgetProperties);
16835
+ }
16836
+
16624
16837
  var withUsage$1 = createDocumentationMessageGenerator({
16625
16838
  name: 'looking-similar',
16626
16839
  connector: true
@@ -17331,6 +17544,7 @@
17331
17544
  exports.useSortBy = useSortBy;
17332
17545
  exports.useStats = useStats;
17333
17546
  exports.useToggleRefinement = useToggleRefinement;
17547
+ exports.useTrendingFacets = useTrendingFacets;
17334
17548
  exports.useTrendingItems = useTrendingItems;
17335
17549
  exports.version = version$2;
17336
17550
  exports.wrapPromiseWithState = wrapPromiseWithState;