react-instantsearch 7.36.0 → 7.37.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 7.36.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch 7.37.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.36.0';
27
+ var version$2 = '7.37.0';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -10821,7 +10821,7 @@
10821
10821
  };
10822
10822
  }
10823
10823
 
10824
- var version = '4.102.0';
10824
+ var version = '4.103.0';
10825
10825
 
10826
10826
  var withUsage$r = createDocumentationMessageGenerator({
10827
10827
  name: 'instantsearch'
@@ -13123,33 +13123,74 @@
13123
13123
  }
13124
13124
  break;
13125
13125
  }
13126
- case 'tool-error':
13126
+ case 'tool-input-error':
13127
13127
  {
13128
+ var _chunk_input, _chunk_providerExecuted, _chunk_providerMetadata;
13128
13129
  if (!currentMessage) break;
13130
+ delete toolRawInputByCallId[chunk.toolCallId];
13131
+ delete toolRawOutputByCallId[chunk.toolCallId];
13129
13132
  var toolIndex3 = currentMessage.parts.findIndex(function(p) {
13130
13133
  return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
13131
13134
  });
13135
+ var existingPart3 = toolIndex3 >= 0 ? currentMessage.parts[toolIndex3] : null;
13136
+ var _ref5 = existingPart3 !== null && existingPart3 !== void 0 ? existingPart3 : {}, _ignoredOutput = _ref5.output, _ignoredRawOutput = _ref5.rawOutput, _ignoredPreliminary = _ref5.preliminary, carryOver = _object_without_properties(_ref5, [
13137
+ "output",
13138
+ "rawOutput",
13139
+ "preliminary"
13140
+ ]);
13141
+ var nextToolPart2 = _object_spread_props(_object_spread({}, carryOver), {
13142
+ type: "tool-".concat(chunk.toolName),
13143
+ toolCallId: chunk.toolCallId,
13144
+ state: 'output-error',
13145
+ input: undefined,
13146
+ rawInput: (_chunk_input = chunk.input) !== null && _chunk_input !== void 0 ? _chunk_input : carryOver.rawInput,
13147
+ errorText: chunk.errorText,
13148
+ providerExecuted: (_chunk_providerExecuted = chunk.providerExecuted) !== null && _chunk_providerExecuted !== void 0 ? _chunk_providerExecuted : carryOver.providerExecuted,
13149
+ callProviderMetadata: (_chunk_providerMetadata = chunk.providerMetadata) !== null && _chunk_providerMetadata !== void 0 ? _chunk_providerMetadata : carryOver.callProviderMetadata
13150
+ });
13132
13151
  if (toolIndex3 >= 0) {
13133
- var _chunk_input;
13134
- delete toolRawInputByCallId[chunk.toolCallId];
13135
- delete toolRawOutputByCallId[chunk.toolCallId];
13136
13152
  var updatedParts8 = _to_consumable_array(currentMessage.parts);
13137
- var existingPart3 = updatedParts8[toolIndex3];
13138
- var _ignoredRawOutput = existingPart3.rawOutput, _ignoredPreliminary = existingPart3.preliminary, rest1 = _object_without_properties(existingPart3, [
13139
- "rawOutput",
13140
- "preliminary"
13141
- ]);
13142
- updatedParts8[toolIndex3] = _object_spread_props(_object_spread({}, rest1), {
13143
- state: 'output-error',
13144
- errorText: chunk.errorText,
13145
- input: (_chunk_input = chunk.input) !== null && _chunk_input !== void 0 ? _chunk_input : existingPart3.input,
13146
- callProviderMetadata: chunk.callProviderMetadata
13147
- });
13153
+ updatedParts8[toolIndex3] = nextToolPart2;
13148
13154
  currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
13149
13155
  parts: updatedParts8
13150
13156
  });
13151
- _this.state.replaceMessage(currentMessageIndex, currentMessage);
13157
+ } else {
13158
+ currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
13159
+ parts: _to_consumable_array(currentMessage.parts).concat([
13160
+ nextToolPart2
13161
+ ])
13162
+ });
13152
13163
  }
13164
+ _this.state.replaceMessage(currentMessageIndex, currentMessage);
13165
+ break;
13166
+ }
13167
+ case 'tool-output-error':
13168
+ {
13169
+ var _chunk_providerExecuted1, _chunk_providerMetadata1;
13170
+ if (!currentMessage) break;
13171
+ var toolIndex4 = currentMessage.parts.findIndex(function(p) {
13172
+ return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
13173
+ });
13174
+ if (toolIndex4 < 0) break;
13175
+ delete toolRawInputByCallId[chunk.toolCallId];
13176
+ delete toolRawOutputByCallId[chunk.toolCallId];
13177
+ var updatedParts9 = _to_consumable_array(currentMessage.parts);
13178
+ var existingPart4 = updatedParts9[toolIndex4];
13179
+ var _ignoredRawOutput1 = existingPart4.rawOutput, _ignoredPreliminary1 = existingPart4.preliminary, _ignoredOutput1 = existingPart4.output, rest1 = _object_without_properties(existingPart4, [
13180
+ "rawOutput",
13181
+ "preliminary",
13182
+ "output"
13183
+ ]);
13184
+ updatedParts9[toolIndex4] = _object_spread_props(_object_spread({}, rest1), {
13185
+ state: 'output-error',
13186
+ errorText: chunk.errorText,
13187
+ providerExecuted: (_chunk_providerExecuted1 = chunk.providerExecuted) !== null && _chunk_providerExecuted1 !== void 0 ? _chunk_providerExecuted1 : rest1.providerExecuted,
13188
+ callProviderMetadata: (_chunk_providerMetadata1 = chunk.providerMetadata) !== null && _chunk_providerMetadata1 !== void 0 ? _chunk_providerMetadata1 : rest1.callProviderMetadata
13189
+ });
13190
+ currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
13191
+ parts: updatedParts9
13192
+ });
13193
+ _this.state.replaceMessage(currentMessageIndex, currentMessage);
13153
13194
  break;
13154
13195
  }
13155
13196
  case 'source-url':
@@ -19194,8 +19235,9 @@
19194
19235
  function createAutocompletePropGetters(param) {
19195
19236
  var useEffect = param.useEffect, useId = param.useId, useMemo = param.useMemo, useRef = param.useRef, useState = param.useState;
19196
19237
  return function usePropGetters(param) {
19197
- var indices = param.indices, indicesConfig = param.indicesConfig, onRefine = param.onRefine, globalOnSelect = param.onSelect, onApply = param.onApply, onSubmit = param.onSubmit, placeholder = param.placeholder, _param_isDetached = param.isDetached, isDetached = _param_isDetached === void 0 ? false : _param_isDetached, _param_shouldHidePanel = param.shouldHidePanel, shouldHidePanel = _param_shouldHidePanel === void 0 ? false : _param_shouldHidePanel, _param_autoFocus = param.autoFocus, autoFocus = _param_autoFocus === void 0 ? false : _param_autoFocus;
19198
- var getElementId = createGetElementId(useId());
19238
+ var indices = param.indices, indicesConfig = param.indicesConfig, onRefine = param.onRefine, globalOnSelect = param.onSelect, onApply = param.onApply, onSubmit = param.onSubmit, placeholder = param.placeholder, _param_isDetached = param.isDetached, isDetached = _param_isDetached === void 0 ? false : _param_isDetached, _param_shouldHidePanel = param.shouldHidePanel, shouldHidePanel = _param_shouldHidePanel === void 0 ? false : _param_shouldHidePanel, _param_autoFocus = param.autoFocus, autoFocus = _param_autoFocus === void 0 ? false : _param_autoFocus, id = param.id;
19239
+ var internalId = useId();
19240
+ var getElementId = createGetElementId(id !== null && id !== void 0 ? id : internalId);
19199
19241
  var inputRef = useRef(null);
19200
19242
  var rootRef = useRef(null);
19201
19243
  var _useState = _sliced_to_array(useState(autoFocus), 2), isOpen = _useState[0], setIsOpen = _useState[1];
@@ -22270,11 +22312,14 @@
22270
22312
  Fragment: React.Fragment
22271
22313
  });
22272
22314
  var id = 0;
22273
- var useAutocompleteInstanceId = React.useId ? function() {
22274
- return React.useId().replace(/:/g, '');
22315
+ // Colons (`:r0:`) preserved so concatenations like `autocomplete:r0:input`
22316
+ // have a recognisable boundary; callers that need a colon-free variant for
22317
+ // InstantSearch's `indexId` strip them at the use site.
22318
+ var useAutocompleteId = React.useId ? function() {
22319
+ return React.useId();
22275
22320
  } : function() {
22276
22321
  return React.useState(function() {
22277
- return "a".concat(id++);
22322
+ return ":a".concat(id++, ":");
22278
22323
  })[0];
22279
22324
  };
22280
22325
  var usePropGetters = createAutocompletePropGetters({
@@ -22426,6 +22471,10 @@
22426
22471
  "translations",
22427
22472
  "transformItems"
22428
22473
  ]);
22474
+ var autoFocus = restProps.autoFocus, placeholder = restProps.placeholder, classNames = restProps.classNames;
22475
+ // Eager-mount only when `autoFocus` is set — otherwise wait for first focus
22476
+ // before registering the autocomplete subtree in the search graph.
22477
+ var _useState = _sliced_to_array(React.useState(autoFocus === true), 2), activated = _useState[0], setActivated = _useState[1];
22429
22478
  var translations = _object_spread({}, DEFAULT_TRANSLATIONS, userTranslations);
22430
22479
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
22431
22480
  var compositionID = useInstantSearchContext().compositionID;
@@ -22435,9 +22484,8 @@
22435
22484
  }, props.aiMode ? {
22436
22485
  opensChat: true
22437
22486
  } : {})).refine;
22438
- // In feeds-mode, indexId disambiguates multiple Autocomplete instances
22439
- // sharing the same compositionID. Mirrors the fallback at line 111 for React <18.
22440
- var instanceKey = useAutocompleteInstanceId();
22487
+ var domId = useAutocompleteId();
22488
+ var instanceKey = domId.replace(/:/g, '');
22441
22489
  if (isFeedsMode && indices !== undefined) {
22442
22490
  throw new Error('EXPERIMENTAL_Autocomplete: `feeds` and `indices` are mutually exclusive.');
22443
22491
  }
@@ -22607,7 +22655,84 @@
22607
22655
  "indices",
22608
22656
  "feeds"
22609
22657
  ]);
22658
+ var instance = useInstantSearchContext();
22659
+ var detached = useDetachedMode(detachedMediaQuery);
22660
+ var isDetached = detached.isDetached, setIsModalOpen = detached.setIsModalOpen;
22661
+ // Lazy activation only: when `activated` flips from false to true, the
22662
+ // newly-mounted isolated `<Index>` schedules the parent's search even
22663
+ // though the parent's state hasn't changed. Cancel it so only the
22664
+ // autocomplete's own search fires on activation. Skip when `autoFocus`
22665
+ // mounts the inner eagerly — the parent's legitimate initial search
22666
+ // shares the same defer slot and must not be cancelled.
22667
+ var initialActivatedRef = React.useRef(activated);
22668
+ React.useLayoutEffect(function() {
22669
+ if (activated && !initialActivatedRef.current) {
22670
+ initialActivatedRef.current = true;
22671
+ instance.scheduleSearch.cancel();
22672
+ }
22673
+ }, [
22674
+ activated,
22675
+ instance
22676
+ ]);
22677
+ if (!activated) {
22678
+ var _indexUiState_query, _indexUiState_query1;
22679
+ restProps.indices; restProps.feeds; restProps.autoFocus; restProps.placeholder; restProps.classNames; restProps.aiMode; restProps.panelComponent; restProps.getSearchPageURL; restProps.onSelect; var shellRootProps = _object_without_properties(restProps, [
22680
+ "indices",
22681
+ "feeds",
22682
+ "autoFocus",
22683
+ "placeholder",
22684
+ "classNames",
22685
+ "aiMode",
22686
+ "panelComponent",
22687
+ "getSearchPageURL",
22688
+ "onSelect"
22689
+ ]);
22690
+ var activateWithQueryMirror = function activateWithQueryMirror() {
22691
+ // Routing only fills the parent index's UI state, not the
22692
+ // autocomplete's isolated one, so without this, the autocomplete
22693
+ // would activate with an empty query and fire a useless search.
22694
+ // We copy the parent's query into the autocomplete's slot of
22695
+ // `_initialUiState` right before flipping `activated`: that's the
22696
+ // moment the isolated `<Index>` is about to mount and read it.
22697
+ // Doing this later would mean firing a second search to correct
22698
+ // the first.
22699
+ if (indexUiState.query) {
22700
+ var isoIndexId = "ais-autocomplete-".concat(instanceKey);
22701
+ var initial = instance._initialUiState;
22702
+ initial[isoIndexId] = _object_spread_props(_object_spread({}, initial[isoIndexId]), {
22703
+ query: indexUiState.query
22704
+ });
22705
+ }
22706
+ setActivated(true);
22707
+ };
22708
+ return /*#__PURE__*/ React.createElement(Autocomplete, _object_spread_props(_object_spread({}, shellRootProps), {
22709
+ classNames: classNames
22710
+ }), isDetached ? /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
22711
+ query: (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '',
22712
+ placeholder: placeholder,
22713
+ classNames: classNames,
22714
+ translations: translations,
22715
+ onClick: function onClick() {
22716
+ setIsModalOpen(true);
22717
+ activateWithQueryMirror();
22718
+ }
22719
+ }) : /*#__PURE__*/ React.createElement(AutocompleteSearch, {
22720
+ inputProps: {
22721
+ id: "autocomplete".concat(domId, "input"),
22722
+ role: 'combobox',
22723
+ placeholder: placeholder,
22724
+ onFocus: activateWithQueryMirror
22725
+ },
22726
+ clearQuery: function clearQuery() {},
22727
+ query: (_indexUiState_query1 = indexUiState.query) !== null && _indexUiState_query1 !== void 0 ? _indexUiState_query1 : '',
22728
+ isSearchStalled: false,
22729
+ classNames: classNames
22730
+ }));
22731
+ }
22610
22732
  var innerAutocomplete = /*#__PURE__*/ React.createElement(InnerAutocomplete, _object_spread_props(_object_spread({}, forwardedProps), {
22733
+ autoFocus: true,
22734
+ domId: domId,
22735
+ detached: detached,
22611
22736
  indicesConfig: indicesConfig,
22612
22737
  refineSearchBox: refine,
22613
22738
  isSearchStalled: isSearchStalled,
@@ -22616,7 +22741,6 @@
22616
22741
  showRecent: showRecent,
22617
22742
  recentSearchConfig: recentSearchConfig,
22618
22743
  showQuerySuggestions: normalizedShowQuerySuggestions,
22619
- detachedMediaQuery: detachedMediaQuery,
22620
22744
  translations: translations,
22621
22745
  showPromptSuggestions: normalizedShowPromptSuggestions,
22622
22746
  transformItems: effectiveTransformItems,
@@ -22635,16 +22759,18 @@
22635
22759
  }), innerAutocomplete);
22636
22760
  }
22637
22761
  return /*#__PURE__*/ React.createElement(Index, {
22638
- EXPERIMENTAL_isolated: true
22762
+ EXPERIMENTAL_isolated: true,
22763
+ indexId: "ais-autocomplete-".concat(instanceKey)
22639
22764
  }, /*#__PURE__*/ React.createElement(Configure, searchParameters), indicesConfig.map(function(index) {
22640
22765
  return /*#__PURE__*/ React.createElement(Index, {
22641
22766
  key: index.indexName,
22642
- indexName: index.indexName
22767
+ indexName: index.indexName,
22768
+ indexId: "ais-autocomplete-".concat(instanceKey, "-").concat(index.indexName)
22643
22769
  }, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
22644
22770
  }), innerAutocomplete);
22645
22771
  }
22646
22772
  function InnerAutocomplete(_0) {
22647
- var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, props = _object_without_properties(_0, [
22773
+ var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, domId = _0.domId, detached = _0.detached, props = _object_without_properties(_0, [
22648
22774
  "indicesConfig",
22649
22775
  "refineSearchBox",
22650
22776
  "isSearchStalled",
@@ -22661,10 +22787,11 @@
22661
22787
  "transformItems",
22662
22788
  "placeholder",
22663
22789
  "autoFocus",
22664
- "detachedMediaQuery",
22665
22790
  "translations",
22666
22791
  "classNames",
22667
- "aiMode"
22792
+ "aiMode",
22793
+ "domId",
22794
+ "detached"
22668
22795
  ]);
22669
22796
  var _indexUiState_query, _ref;
22670
22797
  var _showPromptSuggestions_searchParameters;
@@ -22675,7 +22802,7 @@
22675
22802
  }
22676
22803
  }), indices = _useAutocomplete.indices, refineAutocomplete = _useAutocomplete.refine, currentRefinement = _useAutocomplete.currentRefinement;
22677
22804
  var resolvedQuery = currentRefinement !== undefined ? currentRefinement : (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '';
22678
- var _useDetachedMode = useDetachedMode(detachedMediaQuery), isDetached = _useDetachedMode.isDetached, isModalDetached = _useDetachedMode.isModalDetached, isModalOpen = _useDetachedMode.isModalOpen, setIsModalOpen = _useDetachedMode.setIsModalOpen;
22805
+ var isDetached = detached.isDetached, isModalDetached = detached.isModalDetached, isModalOpen = detached.isModalOpen, setIsModalOpen = detached.setIsModalOpen;
22679
22806
  var previousIsDetachedRef = React.useRef(isDetached);
22680
22807
  var _useStorage = useStorage({
22681
22808
  showRecent: showRecent,
@@ -22741,6 +22868,7 @@
22741
22868
  });
22742
22869
  var shouldHideEmptyPanel = allIndicesEmpty && recentEmpty && !hasNoResultsTemplate && !PanelComponent;
22743
22870
  var _usePropGetters = usePropGetters({
22871
+ id: domId,
22744
22872
  indices: indicesForPropGettersWithPromptSuggestions,
22745
22873
  indicesConfig: indicesConfigForPropGetters,
22746
22874
  onRefine: function onRefine(query) {
@@ -22865,7 +22993,7 @@
22865
22993
  NoResultsComponent: currentIndexConfig.noResultsComponent,
22866
22994
  items: hits.map(function(item) {
22867
22995
  return _object_spread_props(_object_spread({}, item), {
22868
- __indexName: indexId
22996
+ __indexName: indexName
22869
22997
  });
22870
22998
  }),
22871
22999
  getItemProps: getItemProps,