react-instantsearch-core 7.29.0 → 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.29.0 | © 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.29.0';
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.93.0';
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) {
@@ -12806,7 +12806,7 @@
12806
12806
  return refinements;
12807
12807
  }
12808
12808
 
12809
- var withUsage$m = createDocumentationMessageGenerator({
12809
+ var withUsage$n = createDocumentationMessageGenerator({
12810
12810
  name: 'chat',
12811
12811
  connector: true
12812
12812
  });
@@ -12857,12 +12857,14 @@
12857
12857
  }
12858
12858
  var connectChat = function connectChat(renderFn) {
12859
12859
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
12860
- checkRendering(renderFn, withUsage$m());
12860
+ checkRendering(renderFn, withUsage$n());
12861
12861
  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, [
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, [
12863
12863
  "resume",
12864
12864
  "tools",
12865
- "type"
12865
+ "type",
12866
+ "context",
12867
+ "initialUserMessage"
12866
12868
  ]);
12867
12869
  var _chatInstance;
12868
12870
  var input = '';
@@ -12904,6 +12906,10 @@
12904
12906
  if (!_chatInstance.messages || _chatInstance.messages.length === 0) {
12905
12907
  return;
12906
12908
  }
12909
+ var status = _chatInstance.status;
12910
+ if (status === 'submitted' || status === 'streaming') {
12911
+ _chatInstance.stop();
12912
+ }
12907
12913
  setIsClearing(true);
12908
12914
  };
12909
12915
  var onClearTransitionEnd = function onClearTransitionEnd() {
@@ -12953,7 +12959,7 @@
12953
12959
  }
12954
12960
  if ('agentId' in options && options.agentId) {
12955
12961
  if (!appId || !apiKey) {
12956
- 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.'));
12957
12963
  }
12958
12964
  var baseApi = "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5");
12959
12965
  transport = new DefaultChatTransport({
@@ -12979,7 +12985,7 @@
12979
12985
  });
12980
12986
  }
12981
12987
  if (!transport) {
12982
- 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`.'));
12983
12989
  }
12984
12990
  if ('chat' in options) {
12985
12991
  return options.chat;
@@ -13052,7 +13058,7 @@
13052
13058
  if (agentId && feedback) {
13053
13059
  var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
13054
13060
  if (!appId || !apiKey) {
13055
- throw new Error(withUsage$m('Could not extract Algolia credentials from the search client.'));
13061
+ throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
13056
13062
  }
13057
13063
  feedbackAbortController = new AbortController();
13058
13064
  _sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
@@ -13077,6 +13083,11 @@
13077
13083
  if (resume) {
13078
13084
  _chatInstance.resumeStream();
13079
13085
  }
13086
+ if (initialUserMessage && !resume && _chatInstance.messages.length === 0) {
13087
+ _chatInstance.sendMessage({
13088
+ text: initialUserMessage
13089
+ });
13090
+ }
13080
13091
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
13081
13092
  instantSearchInstance: instantSearchInstance
13082
13093
  }), true);
@@ -13112,10 +13123,65 @@
13112
13123
  var _param = _sliced_to_array(param, 2), key = _param[0], tool = _param[1];
13113
13124
  var toolWithAddToolResult = _object_spread_props(_object_spread({}, tool), {
13114
13125
  addToolResult: _chatInstance.addToolResult,
13115
- applyFilters: applyFilters
13126
+ applyFilters: applyFilters,
13127
+ sendEvent: sendEvent
13116
13128
  });
13117
13129
  toolsWithAddToolResult[key] = toolWithAddToolResult;
13118
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
+ };
13119
13185
  return {
13120
13186
  indexUiState: instantSearchInstance.getUiState()[parent.getIndexId()],
13121
13187
  input: input,
@@ -13142,7 +13208,7 @@
13142
13208
  messages: _chatInstance.messages,
13143
13209
  regenerate: _chatInstance.regenerate,
13144
13210
  resumeStream: _chatInstance.resumeStream,
13145
- sendMessage: _chatInstance.sendMessage,
13211
+ sendMessage: sendMessageWithContext,
13146
13212
  status: _chatInstance.status,
13147
13213
  stop: _chatInstance.stop
13148
13214
  };
@@ -13165,13 +13231,13 @@
13165
13231
  return useConnector(connectChat, props, additionalWidgetProperties);
13166
13232
  }
13167
13233
 
13168
- var withUsage$l = createDocumentationMessageGenerator({
13234
+ var withUsage$m = createDocumentationMessageGenerator({
13169
13235
  name: 'clear-refinements',
13170
13236
  connector: true
13171
13237
  });
13172
13238
  var connectClearRefinements = function connectClearRefinements(renderFn) {
13173
13239
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13174
- checkRendering(renderFn, withUsage$l());
13240
+ checkRendering(renderFn, withUsage$m());
13175
13241
  return function(widgetParams) {
13176
13242
  var _ref = widgetParams || {}, _ref_includedAttributes = _ref.includedAttributes, includedAttributes = _ref_includedAttributes === void 0 ? [] : _ref_includedAttributes, _ref_excludedAttributes = _ref.excludedAttributes, excludedAttributes = _ref_excludedAttributes === void 0 ? [
13177
13243
  'query'
@@ -13179,7 +13245,7 @@
13179
13245
  return items;
13180
13246
  } : _ref_transformItems;
13181
13247
  if (widgetParams && widgetParams.includedAttributes && widgetParams.excludedAttributes) {
13182
- 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.'));
13183
13249
  }
13184
13250
  var connectorState = {
13185
13251
  refine: noop,
@@ -13282,16 +13348,16 @@
13282
13348
  return useConnector(connectClearRefinements, props, additionalWidgetProperties);
13283
13349
  }
13284
13350
 
13285
- var withUsage$k = createDocumentationMessageGenerator({
13351
+ var withUsage$l = createDocumentationMessageGenerator({
13286
13352
  name: 'current-refinements',
13287
13353
  connector: true
13288
13354
  });
13289
13355
  var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
13290
13356
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13291
- checkRendering(renderFn, withUsage$k());
13357
+ checkRendering(renderFn, withUsage$l());
13292
13358
  return function(widgetParams) {
13293
13359
  if ((widgetParams || {}).includedAttributes && (widgetParams || {}).excludedAttributes) {
13294
- 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.'));
13295
13361
  }
13296
13362
  var _ref = widgetParams || {}, includedAttributes = _ref.includedAttributes, _ref_excludedAttributes = _ref.excludedAttributes, excludedAttributes = _ref_excludedAttributes === void 0 ? [
13297
13363
  'query'
@@ -13480,19 +13546,19 @@
13480
13546
  });
13481
13547
  }
13482
13548
 
13483
- var withUsage$j = createDocumentationMessageGenerator({
13549
+ var withUsage$k = createDocumentationMessageGenerator({
13484
13550
  name: 'frequently-bought-together',
13485
13551
  connector: true
13486
13552
  });
13487
13553
  var connectFrequentlyBoughtTogether = function connectFrequentlyBoughtTogether(renderFn) {
13488
13554
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13489
- checkRendering(renderFn, withUsage$j());
13555
+ checkRendering(renderFn, withUsage$k());
13490
13556
  return function(widgetParams) {
13491
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) {
13492
13558
  return items;
13493
13559
  } : _ref_transformItems, objectIDs = _ref.objectIDs, limit = _ref.limit, threshold = _ref.threshold, fallbackParameters = _ref.fallbackParameters, queryParameters = _ref.queryParameters;
13494
13560
  if (!objectIDs || objectIDs.length === 0) {
13495
- throw new Error(withUsage$j('The `objectIDs` option is required.'));
13561
+ throw new Error(withUsage$k('The `objectIDs` option is required.'));
13496
13562
  }
13497
13563
  var sendEvent;
13498
13564
  return {
@@ -13630,7 +13696,7 @@
13630
13696
  return insideBoundingBoxStringToBoundingBox(value);
13631
13697
  }
13632
13698
 
13633
- var withUsage$i = createDocumentationMessageGenerator({
13699
+ var withUsage$j = createDocumentationMessageGenerator({
13634
13700
  name: 'geo-search',
13635
13701
  connector: true
13636
13702
  });
@@ -13654,7 +13720,7 @@
13654
13720
  * Currently, the feature is not compatible with multiple values in the _geoloc attribute.
13655
13721
  */ var connectGeoSearch = function connectGeoSearch(renderFn) {
13656
13722
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13657
- checkRendering(renderFn, withUsage$i());
13723
+ checkRendering(renderFn, withUsage$j());
13658
13724
  return function(widgetParams) {
13659
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) {
13660
13726
  return items;
@@ -13872,7 +13938,7 @@
13872
13938
  return sendEventForFacet;
13873
13939
  }
13874
13940
 
13875
- var withUsage$h = createDocumentationMessageGenerator({
13941
+ var withUsage$i = createDocumentationMessageGenerator({
13876
13942
  name: 'hierarchical-menu',
13877
13943
  connector: true
13878
13944
  });
@@ -13893,16 +13959,16 @@
13893
13959
  * @return {function(CustomHierarchicalMenuWidgetParams)} Re-usable widget factory for a custom **HierarchicalMenu** widget.
13894
13960
  */ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
13895
13961
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13896
- checkRendering(renderFn, withUsage$h());
13962
+ checkRendering(renderFn, withUsage$i());
13897
13963
  return function(widgetParams) {
13898
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) {
13899
13965
  return items;
13900
13966
  } : _ref_transformItems;
13901
13967
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
13902
- 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.'));
13903
13969
  }
13904
13970
  if (showMore === true && showMoreLimit <= limit) {
13905
- 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`.'));
13906
13972
  }
13907
13973
  // we need to provide a hierarchicalFacet name for the search state
13908
13974
  // so that we can always map $hierarchicalFacetName => real attributes
@@ -14094,13 +14160,13 @@
14094
14160
  return useConnector(connectHierarchicalMenu, props, additionalWidgetProperties);
14095
14161
  }
14096
14162
 
14097
- var withUsage$g = createDocumentationMessageGenerator({
14163
+ var withUsage$h = createDocumentationMessageGenerator({
14098
14164
  name: 'hits',
14099
14165
  connector: true
14100
14166
  });
14101
14167
  var connectHits = function connectHits(renderFn) {
14102
14168
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14103
- checkRendering(renderFn, withUsage$g());
14169
+ checkRendering(renderFn, withUsage$h());
14104
14170
  return function(widgetParams) {
14105
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) {
14106
14172
  return items;
@@ -14198,29 +14264,29 @@
14198
14264
  return useConnector(connectHits, props, additionalWidgetProperties);
14199
14265
  }
14200
14266
 
14201
- var withUsage$f = createDocumentationMessageGenerator({
14267
+ var withUsage$g = createDocumentationMessageGenerator({
14202
14268
  name: 'hits-per-page',
14203
14269
  connector: true
14204
14270
  });
14205
14271
  var connectHitsPerPage = function connectHitsPerPage(renderFn) {
14206
14272
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14207
- checkRendering(renderFn, withUsage$f());
14273
+ checkRendering(renderFn, withUsage$g());
14208
14274
  return function(widgetParams) {
14209
14275
  var _ref = widgetParams || {}, userItems = _ref.items, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
14210
14276
  return items;
14211
14277
  } : _ref_transformItems;
14212
14278
  if (!Array.isArray(userItems)) {
14213
- 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.'));
14214
14280
  }
14215
14281
  var items = userItems;
14216
14282
  var defaultItems = items.filter(function(item) {
14217
14283
  return item.default === true;
14218
14284
  });
14219
14285
  if (defaultItems.length === 0) {
14220
- 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`."));
14221
14287
  }
14222
14288
  if (defaultItems.length > 1) {
14223
- 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`.'));
14224
14290
  }
14225
14291
  var defaultItem = defaultItems[0];
14226
14292
  var normalizeItems = function normalizeItems(param) {
@@ -14339,7 +14405,7 @@
14339
14405
  });
14340
14406
  }
14341
14407
 
14342
- var withUsage$e = createDocumentationMessageGenerator({
14408
+ var withUsage$f = createDocumentationMessageGenerator({
14343
14409
  name: 'infinite-hits',
14344
14410
  connector: true
14345
14411
  });
@@ -14385,7 +14451,7 @@
14385
14451
  }
14386
14452
  var connectInfiniteHits = function connectInfiniteHits(renderFn) {
14387
14453
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14388
- checkRendering(renderFn, withUsage$e());
14454
+ checkRendering(renderFn, withUsage$f());
14389
14455
  return function(widgetParams) {
14390
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) {
14391
14457
  return items;
@@ -14591,7 +14657,7 @@
14591
14657
  return useConnector(connectInfiniteHits, props, additionalWidgetProperties);
14592
14658
  }
14593
14659
 
14594
- var withUsage$d = createDocumentationMessageGenerator({
14660
+ var withUsage$e = createDocumentationMessageGenerator({
14595
14661
  name: 'menu',
14596
14662
  connector: true
14597
14663
  });
@@ -14609,16 +14675,16 @@
14609
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.
14610
14676
  */ var connectMenu = function connectMenu(renderFn) {
14611
14677
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14612
- checkRendering(renderFn, withUsage$d());
14678
+ checkRendering(renderFn, withUsage$e());
14613
14679
  return function(widgetParams) {
14614
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) {
14615
14681
  return items;
14616
14682
  } : _ref_transformItems;
14617
14683
  if (!attribute) {
14618
- throw new Error(withUsage$d('The `attribute` option is required.'));
14684
+ throw new Error(withUsage$e('The `attribute` option is required.'));
14619
14685
  }
14620
14686
  if (showMore === true && showMoreLimit <= limit) {
14621
- 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`.'));
14622
14688
  }
14623
14689
  var sendEvent;
14624
14690
  var _createURL;
@@ -14788,7 +14854,7 @@
14788
14854
  return typeof value === 'number' && isFinite(value);
14789
14855
  }
14790
14856
 
14791
- var withUsage$c = createDocumentationMessageGenerator({
14857
+ var withUsage$d = createDocumentationMessageGenerator({
14792
14858
  name: 'numeric-menu',
14793
14859
  connector: true
14794
14860
  });
@@ -14807,16 +14873,16 @@
14807
14873
  };
14808
14874
  var connectNumericMenu = function connectNumericMenu(renderFn) {
14809
14875
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14810
- checkRendering(renderFn, withUsage$c());
14876
+ checkRendering(renderFn, withUsage$d());
14811
14877
  return function(widgetParams) {
14812
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) {
14813
14879
  return item;
14814
14880
  } : _ref_transformItems;
14815
14881
  if (attribute === '') {
14816
- throw new Error(withUsage$c('The `attribute` option is required.'));
14882
+ throw new Error(withUsage$d('The `attribute` option is required.'));
14817
14883
  }
14818
14884
  if (!items || items.length === 0) {
14819
- 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.'));
14820
14886
  }
14821
14887
  var prepareItems = function prepareItems(state) {
14822
14888
  return items.map(function(param) {
@@ -15131,7 +15197,7 @@
15131
15197
  return Paginator;
15132
15198
  }();
15133
15199
 
15134
- var withUsage$b = createDocumentationMessageGenerator({
15200
+ var withUsage$c = createDocumentationMessageGenerator({
15135
15201
  name: 'pagination',
15136
15202
  connector: true
15137
15203
  });
@@ -15143,7 +15209,7 @@
15143
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).
15144
15210
  */ var connectPagination = function connectPagination(renderFn) {
15145
15211
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15146
- checkRendering(renderFn, withUsage$b());
15212
+ checkRendering(renderFn, withUsage$c());
15147
15213
  return function(widgetParams) {
15148
15214
  var _ref = widgetParams || {}, totalPages = _ref.totalPages, _ref_padding = _ref.padding, padding = _ref_padding === void 0 ? 3 : _ref_padding;
15149
15215
  var pager = new Paginator({
@@ -15260,7 +15326,7 @@
15260
15326
  };
15261
15327
  }
15262
15328
 
15263
- var withUsage$a = createDocumentationMessageGenerator({
15329
+ var withUsage$b = createDocumentationMessageGenerator({
15264
15330
  name: 'query-rules',
15265
15331
  connector: true
15266
15332
  });
@@ -15316,7 +15382,7 @@
15316
15382
  }
15317
15383
  var connectQueryRules = function connectQueryRules(render) {
15318
15384
  var unmount = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15319
- checkRendering(render, withUsage$a());
15385
+ checkRendering(render, withUsage$b());
15320
15386
  return function(widgetParams) {
15321
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) {
15322
15388
  return rules;
@@ -15325,7 +15391,7 @@
15325
15391
  } : _ref_transformItems;
15326
15392
  Object.keys(trackedFilters).forEach(function(facetName) {
15327
15393
  if (typeof trackedFilters[facetName] !== 'function') {
15328
- 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.')));
15329
15395
  }
15330
15396
  });
15331
15397
  var hasTrackedFilters = Object.keys(trackedFilters).length > 0;
@@ -15401,7 +15467,7 @@
15401
15467
  return useConnector(connectQueryRules, props, additionalWidgetProperties);
15402
15468
  }
15403
15469
 
15404
- var withUsage$9 = createDocumentationMessageGenerator({
15470
+ var withUsage$a = createDocumentationMessageGenerator({
15405
15471
  name: 'range-input',
15406
15472
  connector: true
15407
15473
  }, {
@@ -15425,14 +15491,14 @@
15425
15491
  * information about the min and max bounds for the current result set.
15426
15492
  */ var connectRange = function connectRange(renderFn) {
15427
15493
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15428
- checkRendering(renderFn, withUsage$9());
15494
+ checkRendering(renderFn, withUsage$a());
15429
15495
  return function(widgetParams) {
15430
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;
15431
15497
  if (!attribute) {
15432
- throw new Error(withUsage$9('The `attribute` option is required.'));
15498
+ throw new Error(withUsage$a('The `attribute` option is required.'));
15433
15499
  }
15434
15500
  if (isFiniteNumber(minBound) && isFiniteNumber(maxBound) && minBound > maxBound) {
15435
- 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`."));
15436
15502
  }
15437
15503
  var formatToNumber = function formatToNumber(v) {
15438
15504
  return Number(Number(v).toFixed(precision));
@@ -15652,7 +15718,7 @@
15652
15718
  return useConnector(connectRange, props, additionalWidgetProperties);
15653
15719
  }
15654
15720
 
15655
- var withUsage$8 = createDocumentationMessageGenerator({
15721
+ var withUsage$9 = createDocumentationMessageGenerator({
15656
15722
  name: 'refinement-list',
15657
15723
  connector: true
15658
15724
  });
@@ -15674,19 +15740,19 @@
15674
15740
  * - a `searchForItems()` function to search within the items.
15675
15741
  */ var connectRefinementList = function connectRefinementList(renderFn) {
15676
15742
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15677
- checkRendering(renderFn, withUsage$8());
15743
+ checkRendering(renderFn, withUsage$9());
15678
15744
  return function(widgetParams) {
15679
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) {
15680
15746
  return items;
15681
15747
  } : _ref_transformItems;
15682
15748
  if (!attribute) {
15683
- throw new Error(withUsage$8('The `attribute` option is required.'));
15749
+ throw new Error(withUsage$9('The `attribute` option is required.'));
15684
15750
  }
15685
15751
  if (!/^(and|or)$/.test(operator)) {
15686
- 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, '").')));
15687
15753
  }
15688
15754
  if (showMore === true && showMoreLimit <= limit) {
15689
- throw new Error(withUsage$8('`showMoreLimit` should be greater than `limit`.'));
15755
+ throw new Error(withUsage$9('`showMoreLimit` should be greater than `limit`.'));
15690
15756
  }
15691
15757
  var formatItems = function formatItems(_0) {
15692
15758
  var label = _0.name, value = _0.escapedValue, item = _object_without_properties(_0, [
@@ -15914,19 +15980,19 @@
15914
15980
  return useConnector(connectRefinementList, props, additionalWidgetProperties);
15915
15981
  }
15916
15982
 
15917
- var withUsage$7 = createDocumentationMessageGenerator({
15983
+ var withUsage$8 = createDocumentationMessageGenerator({
15918
15984
  name: 'related-products',
15919
15985
  connector: true
15920
15986
  });
15921
15987
  var connectRelatedProducts = function connectRelatedProducts(renderFn) {
15922
15988
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
15923
- checkRendering(renderFn, withUsage$7());
15989
+ checkRendering(renderFn, withUsage$8());
15924
15990
  return function(widgetParams) {
15925
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) {
15926
15992
  return items;
15927
15993
  } : _ref_transformItems;
15928
15994
  if (!objectIDs || objectIDs.length === 0) {
15929
- throw new Error(withUsage$7('The `objectIDs` option is required.'));
15995
+ throw new Error(withUsage$8('The `objectIDs` option is required.'));
15930
15996
  }
15931
15997
  var sendEvent;
15932
15998
  return {
@@ -16002,7 +16068,7 @@
16002
16068
  return useConnector(connectRelatedProducts, props, additionalWidgetProperties);
16003
16069
  }
16004
16070
 
16005
- var withUsage$6 = createDocumentationMessageGenerator({
16071
+ var withUsage$7 = createDocumentationMessageGenerator({
16006
16072
  name: 'search-box',
16007
16073
  connector: true
16008
16074
  });
@@ -16016,7 +16082,7 @@
16016
16082
  * may be impacted by the `queryHook` widget parameter.
16017
16083
  */ var connectSearchBox = function connectSearchBox(renderFn) {
16018
16084
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16019
- checkRendering(renderFn, withUsage$6());
16085
+ checkRendering(renderFn, withUsage$7());
16020
16086
  return function(widgetParams) {
16021
16087
  var _ref = widgetParams || {}, _ref_queryHook = _ref.queryHook, queryHook = _ref_queryHook === void 0 ? defaultQueryHook : _ref_queryHook;
16022
16088
  var _refine;
@@ -16087,7 +16153,7 @@
16087
16153
  return useConnector(connectSearchBox, props, additionalWidgetProperties);
16088
16154
  }
16089
16155
 
16090
- var withUsage$5 = createDocumentationMessageGenerator({
16156
+ var withUsage$6 = createDocumentationMessageGenerator({
16091
16157
  name: 'sort-by',
16092
16158
  connector: true
16093
16159
  });
@@ -16107,14 +16173,14 @@
16107
16173
  }
16108
16174
  var connectSortBy = function connectSortBy(renderFn) {
16109
16175
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16110
- checkRendering(renderFn, withUsage$5());
16176
+ checkRendering(renderFn, withUsage$6());
16111
16177
  var connectorState = {};
16112
16178
  return function(widgetParams) {
16113
16179
  var _ref = widgetParams || {}, items = _ref.items, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(x) {
16114
16180
  return x;
16115
16181
  } : _ref_transformItems;
16116
16182
  if (!Array.isArray(items)) {
16117
- 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.'));
16118
16184
  }
16119
16185
  var itemsLookup = {};
16120
16186
  items.forEach(function(item, index) {
@@ -16122,10 +16188,10 @@
16122
16188
  var hasStrategy = 'strategy' in item && item.strategy !== undefined;
16123
16189
  // Validate mutual exclusivity
16124
16190
  if (hasValue && hasStrategy) {
16125
- 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.')));
16126
16192
  }
16127
16193
  if (!hasValue && !hasStrategy) {
16128
- 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.')));
16129
16195
  }
16130
16196
  var itemValue = getItemValue(item);
16131
16197
  itemsLookup[itemValue] = item;
@@ -16140,7 +16206,7 @@
16140
16206
  return 'strategy' in item && item.strategy;
16141
16207
  });
16142
16208
  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.'));
16209
+ throw new Error(withUsage$6('Sorting strategies can only be used in composition mode. Please provide a "compositionID" to your InstantSearch instance.'));
16144
16210
  }
16145
16211
  var widgetRenderState = this.getWidgetRenderState(initOptions);
16146
16212
  var currentIndex = widgetRenderState.currentRefinement;
@@ -16253,13 +16319,13 @@
16253
16319
  return useConnector(connectSortBy, props, additionalWidgetProperties);
16254
16320
  }
16255
16321
 
16256
- var withUsage$4 = createDocumentationMessageGenerator({
16322
+ var withUsage$5 = createDocumentationMessageGenerator({
16257
16323
  name: 'stats',
16258
16324
  connector: true
16259
16325
  });
16260
16326
  var connectStats = function connectStats(renderFn) {
16261
16327
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16262
- checkRendering(renderFn, withUsage$4());
16328
+ checkRendering(renderFn, withUsage$5());
16263
16329
  return function(widgetParams) {
16264
16330
  return {
16265
16331
  $$type: 'ais.stats',
@@ -16318,7 +16384,7 @@
16318
16384
  return useConnector(connectStats, props, additionalWidgetProperties);
16319
16385
  }
16320
16386
 
16321
- var withUsage$3 = createDocumentationMessageGenerator({
16387
+ var withUsage$4 = createDocumentationMessageGenerator({
16322
16388
  name: 'toggle-refinement',
16323
16389
  connector: true
16324
16390
  });
@@ -16369,11 +16435,11 @@
16369
16435
  * - switch between two values.
16370
16436
  */ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
16371
16437
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16372
- checkRendering(renderFn, withUsage$3());
16438
+ checkRendering(renderFn, withUsage$4());
16373
16439
  return function(widgetParams) {
16374
16440
  var _ref = widgetParams || {}, attribute = _ref.attribute, tmp = _ref.on, userOn = tmp === void 0 ? true : tmp, userOff = _ref.off;
16375
16441
  if (!attribute) {
16376
- throw new Error(withUsage$3('The `attribute` option is required.'));
16442
+ throw new Error(withUsage$4('The `attribute` option is required.'));
16377
16443
  }
16378
16444
  var hasAnOffValue = userOff !== undefined;
16379
16445
  // even though facet values can be numbers and boolean,
@@ -16594,19 +16660,19 @@
16594
16660
  return useConnector(connectToggleRefinement, props, additionalWidgetProperties);
16595
16661
  }
16596
16662
 
16597
- var withUsage$2 = createDocumentationMessageGenerator({
16663
+ var withUsage$3 = createDocumentationMessageGenerator({
16598
16664
  name: 'trending-items',
16599
16665
  connector: true
16600
16666
  });
16601
16667
  var connectTrendingItems = function connectTrendingItems(renderFn) {
16602
16668
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
16603
- checkRendering(renderFn, withUsage$2());
16669
+ checkRendering(renderFn, withUsage$3());
16604
16670
  return function(widgetParams) {
16605
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) {
16606
16672
  return items;
16607
16673
  } : _ref_transformItems;
16608
16674
  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), ").")));
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), ").")));
16610
16676
  }
16611
16677
  var sendEvent;
16612
16678
  return {
@@ -16680,6 +16746,94 @@
16680
16746
  return useConnector(connectTrendingItems, props, additionalWidgetProperties);
16681
16747
  }
16682
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
+
16683
16837
  var withUsage$1 = createDocumentationMessageGenerator({
16684
16838
  name: 'looking-similar',
16685
16839
  connector: true
@@ -17390,6 +17544,7 @@
17390
17544
  exports.useSortBy = useSortBy;
17391
17545
  exports.useStats = useStats;
17392
17546
  exports.useToggleRefinement = useToggleRefinement;
17547
+ exports.useTrendingFacets = useTrendingFacets;
17393
17548
  exports.useTrendingItems = useTrendingItems;
17394
17549
  exports.version = version$2;
17395
17550
  exports.wrapPromiseWithState = wrapPromiseWithState;