react-instantsearch-core 7.23.1 → 7.24.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.
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '7.23.1';
7
+ var _default = exports.default = '7.24.0';
@@ -1,2 +1,2 @@
1
- declare const _default: "7.23.1";
1
+ declare const _default: "7.24.0";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '7.23.1';
1
+ export default '7.24.0';
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.23.1';
10
+ var version = '7.24.0';
11
11
 
12
12
  function _arrayLikeToArray(r, a) {
13
13
  (null == a || a > r.length) && (a = r.length);
@@ -4772,7 +4772,7 @@
4772
4772
 
4773
4773
  var sortAndMergeRecommendations_1 = sortAndMergeRecommendations;
4774
4774
 
4775
- var version$1 = '3.27.0';
4775
+ var version$1 = '3.27.1';
4776
4776
 
4777
4777
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
4778
4778
 
@@ -10290,6 +10290,12 @@
10290
10290
  helper.searchWithoutTriggeringOnStateChange = function () {
10291
10291
  return mainHelper.search();
10292
10292
  };
10293
+
10294
+ // We use the same pattern for the `searchForFacetValues`.
10295
+ helper.searchForFacetValues = function (facetName, facetValue, maxFacetHits, userState) {
10296
+ var state = mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$1(resolveSearchParameters(_this3)))).setQueryParameters(userState);
10297
+ return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
10298
+ };
10293
10299
  var isolatedHelper = indexName ? helper : algoliasearchHelper_1({}, '__empty_index__', {});
10294
10300
  var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
10295
10301
  derivedHelper = derivingHelper.derive(function () {
@@ -12833,7 +12839,7 @@
12833
12839
  };
12834
12840
  }
12835
12841
 
12836
- var version$2 = '4.87.1';
12842
+ var version$2 = '4.88.0';
12837
12843
 
12838
12844
  function _typeof$l(o) {
12839
12845
  "@babel/helpers - typeof";
@@ -16068,6 +16074,12 @@
16068
16074
  return _createClass$5(Chat);
16069
16075
  }(AbstractChat);
16070
16076
 
16077
+ function flat$1(arr) {
16078
+ return arr.reduce(function (acc, array) {
16079
+ return acc.concat(array);
16080
+ }, []);
16081
+ }
16082
+
16071
16083
  function _typeof$s(o) {
16072
16084
  "@babel/helpers - typeof";
16073
16085
 
@@ -16122,12 +16134,56 @@
16122
16134
  }
16123
16135
  return ("string" === r ? String : Number)(t);
16124
16136
  }
16137
+ function _toConsumableArray$5(r) {
16138
+ return _arrayWithoutHoles$5(r) || _iterableToArray$5(r) || _unsupportedIterableToArray$c(r) || _nonIterableSpread$5();
16139
+ }
16140
+ function _nonIterableSpread$5() {
16141
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
16142
+ }
16143
+ function _iterableToArray$5(r) {
16144
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
16145
+ }
16146
+ function _arrayWithoutHoles$5(r) {
16147
+ if (Array.isArray(r)) return _arrayLikeToArray$c(r);
16148
+ }
16149
+ function _objectWithoutProperties$6(e, t) {
16150
+ if (null == e) return {};
16151
+ var o,
16152
+ r,
16153
+ i = _objectWithoutPropertiesLoose$7(e, t);
16154
+ if (Object.getOwnPropertySymbols) {
16155
+ var n = Object.getOwnPropertySymbols(e);
16156
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
16157
+ }
16158
+ return i;
16159
+ }
16160
+ function _objectWithoutPropertiesLoose$7(r, e) {
16161
+ if (null == r) return {};
16162
+ var t = {};
16163
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
16164
+ if (-1 !== e.indexOf(n)) continue;
16165
+ t[n] = r[n];
16166
+ }
16167
+ return t;
16168
+ }
16125
16169
  function _slicedToArray$8(r, e) {
16126
16170
  return _arrayWithHoles$8(r) || _iterableToArrayLimit$8(r, e) || _unsupportedIterableToArray$c(r, e) || _nonIterableRest$8();
16127
16171
  }
16128
16172
  function _nonIterableRest$8() {
16129
16173
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
16130
16174
  }
16175
+ function _unsupportedIterableToArray$c(r, a) {
16176
+ if (r) {
16177
+ if ("string" == typeof r) return _arrayLikeToArray$c(r, a);
16178
+ var t = {}.toString.call(r).slice(8, -1);
16179
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$c(r, a) : void 0;
16180
+ }
16181
+ }
16182
+ function _arrayLikeToArray$c(r, a) {
16183
+ (null == a || a > r.length) && (a = r.length);
16184
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
16185
+ return n;
16186
+ }
16131
16187
  function _iterableToArrayLimit$8(r, l) {
16132
16188
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
16133
16189
  if (null != t) {
@@ -16158,66 +16214,72 @@
16158
16214
  function _arrayWithHoles$8(r) {
16159
16215
  if (Array.isArray(r)) return r;
16160
16216
  }
16161
- function _toConsumableArray$5(r) {
16162
- return _arrayWithoutHoles$5(r) || _iterableToArray$5(r) || _unsupportedIterableToArray$c(r) || _nonIterableSpread$5();
16163
- }
16164
- function _nonIterableSpread$5() {
16165
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
16166
- }
16167
- function _unsupportedIterableToArray$c(r, a) {
16168
- if (r) {
16169
- if ("string" == typeof r) return _arrayLikeToArray$c(r, a);
16170
- var t = {}.toString.call(r).slice(8, -1);
16171
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$c(r, a) : void 0;
16172
- }
16173
- }
16174
- function _iterableToArray$5(r) {
16175
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
16176
- }
16177
- function _arrayWithoutHoles$5(r) {
16178
- if (Array.isArray(r)) return _arrayLikeToArray$c(r);
16179
- }
16180
- function _arrayLikeToArray$c(r, a) {
16181
- (null == a || a > r.length) && (a = r.length);
16182
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
16183
- return n;
16184
- }
16185
- function _objectWithoutProperties$6(e, t) {
16186
- if (null == e) return {};
16187
- var o,
16188
- r,
16189
- i = _objectWithoutPropertiesLoose$7(e, t);
16190
- if (Object.getOwnPropertySymbols) {
16191
- var n = Object.getOwnPropertySymbols(e);
16192
- for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
16193
- }
16194
- return i;
16195
- }
16196
- function _objectWithoutPropertiesLoose$7(r, e) {
16197
- if (null == r) return {};
16198
- var t = {};
16199
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
16200
- if (-1 !== e.indexOf(n)) continue;
16201
- t[n] = r[n];
16202
- }
16203
- return t;
16204
- }
16205
16217
  var withUsage$6 = createDocumentationMessageGenerator({
16206
16218
  name: 'chat',
16207
16219
  connector: true
16208
16220
  });
16221
+ function getAttributesToClear(_ref) {
16222
+ var results = _ref.results,
16223
+ helper = _ref.helper;
16224
+ return uniq(getRefinements(results, helper.state, true).map(function (refinement) {
16225
+ return refinement.attribute;
16226
+ }));
16227
+ }
16228
+ function updateStateFromSearchToolInput(params, helper) {
16229
+ // clear all filters first
16230
+ var attributesToClear = getAttributesToClear({
16231
+ results: helper.lastResults,
16232
+ helper: helper
16233
+ });
16234
+ helper.setState(clearRefinements({
16235
+ helper: helper,
16236
+ attributesToClear: attributesToClear
16237
+ }));
16238
+ if (params.facetFilters) {
16239
+ var attributes = flat$1(params.facetFilters).map(function (filter) {
16240
+ var _filter$split = filter.split(':'),
16241
+ _filter$split2 = _slicedToArray$8(_filter$split, 2),
16242
+ attribute = _filter$split2[0],
16243
+ value = _filter$split2[1];
16244
+ return {
16245
+ attribute: attribute,
16246
+ value: value
16247
+ };
16248
+ });
16249
+ attributes.forEach(function (_ref2) {
16250
+ var attribute = _ref2.attribute,
16251
+ value = _ref2.value;
16252
+ if (!helper.state.isConjunctiveFacet(attribute) && !helper.state.isHierarchicalFacet(attribute) && !helper.state.isDisjunctiveFacet(attribute)) {
16253
+ var s = helper.state.addDisjunctiveFacet(attribute);
16254
+ helper.setState(s);
16255
+ helper.toggleFacetRefinement(attribute, value);
16256
+ } else {
16257
+ var _helper$state$hierarc;
16258
+ var attr = ((_helper$state$hierarc = helper.state.hierarchicalFacets.find(function (facet) {
16259
+ return facet.name === attribute;
16260
+ })) === null || _helper$state$hierarc === void 0 ? void 0 : _helper$state$hierarc.name) || attribute;
16261
+ helper.toggleFacetRefinement(attr, value);
16262
+ }
16263
+ });
16264
+ }
16265
+ if (params.query) {
16266
+ helper.setQuery(params.query);
16267
+ }
16268
+ helper.search();
16269
+ return helper.state;
16270
+ }
16209
16271
  var connectChat = (function connectChat(renderFn) {
16210
16272
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
16211
16273
  checkRendering(renderFn, withUsage$6());
16212
16274
  return function (widgetParams) {
16213
- var _ref = widgetParams || {},
16214
- _ref$resume = _ref.resume,
16215
- resume = _ref$resume === void 0 ? false : _ref$resume,
16216
- _ref$tools = _ref.tools,
16217
- tools = _ref$tools === void 0 ? {} : _ref$tools,
16218
- _ref$type = _ref.type,
16219
- type = _ref$type === void 0 ? 'chat' : _ref$type,
16220
- options = _objectWithoutProperties$6(_ref, _excluded$a);
16275
+ var _ref3 = widgetParams || {},
16276
+ _ref3$resume = _ref3.resume,
16277
+ resume = _ref3$resume === void 0 ? false : _ref3$resume,
16278
+ _ref3$tools = _ref3.tools,
16279
+ tools = _ref3$tools === void 0 ? {} : _ref3$tools,
16280
+ _ref3$type = _ref3.type,
16281
+ type = _ref3$type === void 0 ? 'chat' : _ref3$type,
16282
+ options = _objectWithoutProperties$6(_ref3, _excluded$a);
16221
16283
  var _chatInstance;
16222
16284
  var input = '';
16223
16285
  var open = false;
@@ -16318,10 +16380,10 @@
16318
16380
  'x-algolia-api-Key': apiKey,
16319
16381
  'x-algolia-agent': getAlgoliaAgent(instantSearchInstance.client)
16320
16382
  },
16321
- prepareSendMessagesRequest: function prepareSendMessagesRequest(_ref2) {
16322
- var messages = _ref2.messages,
16323
- trigger = _ref2.trigger,
16324
- rest = _objectWithoutProperties$6(_ref2, _excluded2$2);
16383
+ prepareSendMessagesRequest: function prepareSendMessagesRequest(_ref4) {
16384
+ var messages = _ref4.messages,
16385
+ trigger = _ref4.trigger,
16386
+ rest = _objectWithoutProperties$6(_ref4, _excluded2$2);
16325
16387
  return {
16326
16388
  // Bypass cache when regenerating to ensure fresh responses
16327
16389
  api: trigger === 'regenerate-message' ? "".concat(baseApi, "&cache=false") : baseApi,
@@ -16341,8 +16403,8 @@
16341
16403
  return new Chat(_objectSpread$m(_objectSpread$m({}, options), {}, {
16342
16404
  transport: transport,
16343
16405
  sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
16344
- onToolCall: function onToolCall(_ref3) {
16345
- var toolCall = _ref3.toolCall;
16406
+ onToolCall: function onToolCall(_ref5) {
16407
+ var toolCall = _ref5.toolCall;
16346
16408
  var tool = tools[toolCall.toolName];
16347
16409
  if (!tool) {
16348
16410
  return _chatInstance.addToolResult({
@@ -16352,8 +16414,8 @@
16352
16414
  });
16353
16415
  }
16354
16416
  if (tool.onToolCall) {
16355
- var addToolResult = function addToolResult(_ref4) {
16356
- var output = _ref4.output;
16417
+ var addToolResult = function addToolResult(_ref6) {
16418
+ var output = _ref6.output;
16357
16419
  return _chatInstance.addToolResult({
16358
16420
  output: output,
16359
16421
  tool: toolCall.toolName,
@@ -16413,7 +16475,8 @@
16413
16475
  },
16414
16476
  getWidgetRenderState: function getWidgetRenderState(renderOptions) {
16415
16477
  var instantSearchInstance = renderOptions.instantSearchInstance,
16416
- parent = renderOptions.parent;
16478
+ parent = renderOptions.parent,
16479
+ helper = renderOptions.helper;
16417
16480
  if (!_chatInstance) {
16418
16481
  this.init(_objectSpread$m(_objectSpread$m({}, renderOptions), {}, {
16419
16482
  uiState: {},
@@ -16427,13 +16490,17 @@
16427
16490
  widgetType: this.$$type
16428
16491
  });
16429
16492
  }
16493
+ function applyFilters(params) {
16494
+ return updateStateFromSearchToolInput(params, helper);
16495
+ }
16430
16496
  var toolsWithAddToolResult = {};
16431
- Object.entries(tools).forEach(function (_ref5) {
16432
- var _ref6 = _slicedToArray$8(_ref5, 2),
16433
- key = _ref6[0],
16434
- tool = _ref6[1];
16497
+ Object.entries(tools).forEach(function (_ref7) {
16498
+ var _ref8 = _slicedToArray$8(_ref7, 2),
16499
+ key = _ref8[0],
16500
+ tool = _ref8[1];
16435
16501
  var toolWithAddToolResult = _objectSpread$m(_objectSpread$m({}, tool), {}, {
16436
- addToolResult: _chatInstance.addToolResult
16502
+ addToolResult: _chatInstance.addToolResult,
16503
+ applyFilters: applyFilters
16437
16504
  });
16438
16505
  toolsWithAddToolResult[key] = toolWithAddToolResult;
16439
16506
  });
@@ -16618,7 +16685,7 @@
16618
16685
  scopedResults = _ref2.scopedResults,
16619
16686
  results = _ref2.results;
16620
16687
  connectorState.attributesToClear = scopedResults.reduce(function (attributesToClear, scopedResult) {
16621
- return attributesToClear.concat(getAttributesToClear({
16688
+ return attributesToClear.concat(getAttributesToClear$1({
16622
16689
  scopedResult: scopedResult,
16623
16690
  includedAttributes: includedAttributes,
16624
16691
  excludedAttributes: excludedAttributes,
@@ -16660,7 +16727,7 @@
16660
16727
  };
16661
16728
  };
16662
16729
  };
16663
- function getAttributesToClear(_ref5) {
16730
+ function getAttributesToClear$1(_ref5) {
16664
16731
  var scopedResult = _ref5.scopedResult,
16665
16732
  includedAttributes = _ref5.includedAttributes,
16666
16733
  excludedAttributes = _ref5.excludedAttributes,