react-instantsearch 7.26.0 → 7.27.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.
Files changed (66) hide show
  1. package/dist/cjs/components/AutocompleteSearch.js +18 -11
  2. package/dist/cjs/components/Carousel.js +24 -17
  3. package/dist/cjs/components/index.js +5 -5
  4. package/dist/cjs/index.js +8 -88
  5. package/dist/cjs/lib/useStickToBottom.js +17 -11
  6. package/dist/cjs/types/PartialKeys.js +3 -0
  7. package/dist/cjs/types/Translatable.js +3 -0
  8. package/dist/cjs/types/index.js +6 -0
  9. package/dist/cjs/ui/Breadcrumb.js +31 -24
  10. package/dist/cjs/ui/ClearRefinements.js +19 -12
  11. package/dist/cjs/ui/CurrentRefinements.js +32 -26
  12. package/dist/cjs/ui/HierarchicalMenu.js +35 -28
  13. package/dist/cjs/ui/Highlight.js +20 -13
  14. package/dist/cjs/ui/HitsPerPage.js +21 -14
  15. package/dist/cjs/ui/InfiniteHits.js +38 -31
  16. package/dist/cjs/ui/InternalHighlight.js +14 -8
  17. package/dist/cjs/ui/Menu.js +32 -25
  18. package/dist/cjs/ui/Pagination.js +39 -32
  19. package/dist/cjs/ui/PoweredBy.js +23 -16
  20. package/dist/cjs/ui/RangeInput.js +34 -27
  21. package/dist/cjs/ui/RefinementList.js +40 -33
  22. package/dist/cjs/ui/ReverseHighlight.js +20 -13
  23. package/dist/cjs/ui/SearchBox.js +43 -36
  24. package/dist/cjs/ui/ShowMoreButton.js +13 -6
  25. package/dist/cjs/ui/Snippet.js +20 -13
  26. package/dist/cjs/ui/SortBy.js +21 -14
  27. package/dist/cjs/ui/Stats.js +18 -11
  28. package/dist/cjs/ui/ToggleRefinement.js +23 -16
  29. package/dist/cjs/ui/lib/capitalize.js +9 -2
  30. package/dist/cjs/ui/lib/index.js +6 -7
  31. package/dist/cjs/ui/lib/isModifierClick.js +9 -2
  32. package/dist/cjs/widgets/Autocomplete.js +247 -118
  33. package/dist/cjs/widgets/Breadcrumb.js +17 -10
  34. package/dist/cjs/widgets/Chat.js +69 -47
  35. package/dist/cjs/widgets/ClearRefinements.js +17 -10
  36. package/dist/cjs/widgets/CurrentRefinements.js +17 -10
  37. package/dist/cjs/widgets/FilterSuggestions.js +20 -13
  38. package/dist/cjs/widgets/FrequentlyBoughtTogether.js +23 -16
  39. package/dist/cjs/widgets/HierarchicalMenu.js +18 -11
  40. package/dist/cjs/widgets/Highlight.js +19 -12
  41. package/dist/cjs/widgets/Hits.js +24 -17
  42. package/dist/cjs/widgets/HitsPerPage.js +17 -10
  43. package/dist/cjs/widgets/InfiniteHits.js +17 -10
  44. package/dist/cjs/widgets/LookingSimilar.js +23 -16
  45. package/dist/cjs/widgets/Menu.js +18 -11
  46. package/dist/cjs/widgets/Pagination.js +18 -11
  47. package/dist/cjs/widgets/PoweredBy.js +16 -9
  48. package/dist/cjs/widgets/RangeInput.js +17 -10
  49. package/dist/cjs/widgets/RefinementList.js +23 -16
  50. package/dist/cjs/widgets/RelatedProducts.js +23 -16
  51. package/dist/cjs/widgets/ReverseHighlight.js +19 -12
  52. package/dist/cjs/widgets/SearchBox.js +20 -13
  53. package/dist/cjs/widgets/Snippet.js +19 -12
  54. package/dist/cjs/widgets/SortBy.js +17 -10
  55. package/dist/cjs/widgets/Stats.js +17 -10
  56. package/dist/cjs/widgets/ToggleRefinement.js +17 -10
  57. package/dist/cjs/widgets/TrendingItems.js +23 -16
  58. package/dist/cjs/widgets/chat/tools/SearchIndexTool.js +32 -25
  59. package/dist/cjs/widgets/index.js +29 -76
  60. package/dist/cjs/widgets/index.umd.js +58 -59
  61. package/dist/es/widgets/Autocomplete.d.ts +8 -4
  62. package/dist/es/widgets/Autocomplete.js +153 -31
  63. package/dist/es/widgets/Chat.js +17 -4
  64. package/dist/umd/ReactInstantSearch.js +1199 -1007
  65. package/dist/umd/ReactInstantSearch.min.js +3 -3
  66. package/package.json +5 -5
@@ -4,10 +4,12 @@ import { _ } from '@swc/helpers/cjs/_object_without_properties.cjs';
4
4
  import { _ as _$5 } from '@swc/helpers/cjs/_sliced_to_array.cjs';
5
5
  import { _ as _$2 } from '@swc/helpers/cjs/_to_consumable_array.cjs';
6
6
  import { _ as _$3 } from '@swc/helpers/cjs/_type_of.cjs';
7
- import { createAutocompleteComponent, createAutocompletePanelComponent, createAutocompleteIndexComponent, createAutocompleteSuggestionComponent, createAutocompleteRecentSearchComponent, createAutocompleteDetachedContainerComponent, createAutocompleteDetachedOverlayComponent, createAutocompleteDetachedFormContainerComponent, createAutocompleteDetachedSearchButtonComponent, createAutocompletePropGetters, createAutocompleteStorage, cx } from 'instantsearch-ui-components';
8
- import React, { createElement, Fragment, useEffect, useId, useMemo, useRef, useState } from 'react';
7
+ import { createAutocompleteComponent, createAutocompletePanelComponent, createAutocompleteIndexComponent, createAutocompleteSuggestionComponent, createAutocompletePromptSuggestionComponent, createAutocompleteRecentSearchComponent, createAutocompleteDetachedContainerComponent, createAutocompleteDetachedOverlayComponent, createAutocompleteDetachedFormContainerComponent, createAutocompleteDetachedSearchButtonComponent, createAutocompletePropGetters, createAutocompleteStorage, cx, getPromptSuggestionHits, isPromptSuggestion } from 'instantsearch-ui-components';
8
+ import 'instantsearch.js/es/lib/utils/index.js';
9
+ import React, { createElement, Fragment, useEffect, useMemo, useRef, useState } from 'react';
9
10
  import { useInstantSearch, useSearchBox, Index, Configure, useAutocomplete } from 'react-instantsearch-core';
10
11
  import { AutocompleteSearch } from '../components/AutocompleteSearch.js';
12
+ import { Highlight } from './Highlight.js';
11
13
  import { ReverseHighlight } from './ReverseHighlight.js';
12
14
 
13
15
  var Autocomplete = createAutocompleteComponent({
@@ -26,6 +28,10 @@ var AutocompleteSuggestion = createAutocompleteSuggestionComponent({
26
28
  createElement: createElement,
27
29
  Fragment: Fragment
28
30
  });
31
+ var AutocompletePromptSuggestion = createAutocompletePromptSuggestionComponent({
32
+ createElement: createElement,
33
+ Fragment: Fragment
34
+ });
29
35
  var AutocompleteRecentSearch = createAutocompleteRecentSearchComponent({
30
36
  createElement: createElement,
31
37
  Fragment: Fragment
@@ -46,9 +52,14 @@ var AutocompleteDetachedSearchButton = createAutocompleteDetachedSearchButtonCom
46
52
  createElement: createElement,
47
53
  Fragment: Fragment
48
54
  });
55
+ var id = 0;
49
56
  var usePropGetters = createAutocompletePropGetters({
50
57
  useEffect: useEffect,
51
- useId: useId,
58
+ useId: React.useId || function() {
59
+ return React.useState(function() {
60
+ return (id++).toString();
61
+ });
62
+ },
52
63
  useMemo: useMemo,
53
64
  useRef: useRef,
54
65
  useState: useState
@@ -178,9 +189,10 @@ function getMediaQueryList(mediaQuery) {
178
189
  };
179
190
  }
180
191
  function EXPERIMENTAL_Autocomplete(_0) {
181
- var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showSuggestions = _0.showSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, props = _(_0, [
192
+ var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, props = _(_0, [
182
193
  "indices",
183
- "showSuggestions",
194
+ "showQuerySuggestions",
195
+ "showPromptSuggestions",
184
196
  "showRecent",
185
197
  "searchParameters",
186
198
  "detachedMediaQuery",
@@ -198,12 +210,12 @@ function EXPERIMENTAL_Autocomplete(_0) {
198
210
  hitsPerPage: 5
199
211
  }, userSearchParameters);
200
212
  var indicesConfig = _$2(indices);
201
- if (showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName) {
202
- var _showSuggestions_classNames, _showSuggestions_classNames1, _showSuggestions_classNames2, _showSuggestions_classNames3;
213
+ if (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName) {
214
+ var _showQuerySuggestions_classNames, _showQuerySuggestions_classNames1, _showQuerySuggestions_classNames2, _showQuerySuggestions_classNames3;
203
215
  indicesConfig.unshift({
204
- indexName: showSuggestions.indexName,
205
- headerComponent: showSuggestions.headerComponent,
206
- itemComponent: showSuggestions.itemComponent || function(param) {
216
+ indexName: showQuerySuggestions.indexName,
217
+ headerComponent: showQuerySuggestions.headerComponent,
218
+ itemComponent: showQuerySuggestions.itemComponent || function(param) {
207
219
  var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
208
220
  return /*#__PURE__*/ React.createElement(AutocompleteSuggestion, {
209
221
  item: item,
@@ -214,15 +226,48 @@ function EXPERIMENTAL_Autocomplete(_0) {
214
226
  }));
215
227
  },
216
228
  classNames: {
217
- root: cx('ais-AutocompleteSuggestions', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions_classNames = showSuggestions.classNames) === null || _showSuggestions_classNames === void 0 ? void 0 : _showSuggestions_classNames.root),
218
- list: cx('ais-AutocompleteSuggestionsList', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions_classNames1 = showSuggestions.classNames) === null || _showSuggestions_classNames1 === void 0 ? void 0 : _showSuggestions_classNames1.list),
219
- header: cx('ais-AutocompleteSuggestionsHeader', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions_classNames2 = showSuggestions.classNames) === null || _showSuggestions_classNames2 === void 0 ? void 0 : _showSuggestions_classNames2.header),
220
- item: cx('ais-AutocompleteSuggestionsItem', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions_classNames3 = showSuggestions.classNames) === null || _showSuggestions_classNames3 === void 0 ? void 0 : _showSuggestions_classNames3.item)
229
+ root: cx('ais-AutocompleteSuggestions', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames === void 0 ? void 0 : _showQuerySuggestions_classNames.root),
230
+ list: cx('ais-AutocompleteSuggestionsList', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames1 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames1 === void 0 ? void 0 : _showQuerySuggestions_classNames1.list),
231
+ header: cx('ais-AutocompleteSuggestionsHeader', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames2 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames2 === void 0 ? void 0 : _showQuerySuggestions_classNames2.header),
232
+ item: cx('ais-AutocompleteSuggestionsItem', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames3 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames3 === void 0 ? void 0 : _showQuerySuggestions_classNames3.item)
221
233
  },
234
+ searchParameters: _$1({
235
+ hitsPerPage: 3
236
+ }, showQuerySuggestions.searchParameters),
222
237
  getQuery: function getQuery(item) {
223
238
  return item.query;
224
239
  },
225
- getURL: showSuggestions.getURL
240
+ getURL: showQuerySuggestions.getURL
241
+ });
242
+ }
243
+ if (showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName) {
244
+ var _showPromptSuggestions_classNames, _showPromptSuggestions_classNames1, _showPromptSuggestions_classNames2, _showPromptSuggestions_classNames3;
245
+ indicesConfig.push({
246
+ indexName: showPromptSuggestions.indexName,
247
+ headerComponent: showPromptSuggestions.headerComponent,
248
+ itemComponent: showPromptSuggestions.itemComponent || function(param) {
249
+ var item = param.item, onSelect = param.onSelect;
250
+ return /*#__PURE__*/ React.createElement(AutocompletePromptSuggestion, {
251
+ item: item,
252
+ onSelect: onSelect
253
+ }, /*#__PURE__*/ React.createElement(ConditionalHighlight, {
254
+ item: item,
255
+ attribute: "prompt"
256
+ }));
257
+ },
258
+ classNames: {
259
+ root: cx('ais-AutocompletePromptSuggestions', (_showPromptSuggestions_classNames = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames === void 0 ? void 0 : _showPromptSuggestions_classNames.root),
260
+ list: cx('ais-AutocompletePromptSuggestionsList', (_showPromptSuggestions_classNames1 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames1 === void 0 ? void 0 : _showPromptSuggestions_classNames1.list),
261
+ header: cx('ais-AutocompletePromptSuggestionsHeader', (_showPromptSuggestions_classNames2 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames2 === void 0 ? void 0 : _showPromptSuggestions_classNames2.header),
262
+ item: cx('ais-AutocompletePromptSuggestionsItem', (_showPromptSuggestions_classNames3 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames3 === void 0 ? void 0 : _showPromptSuggestions_classNames3.item)
263
+ },
264
+ searchParameters: _$1({
265
+ hitsPerPage: 3
266
+ }, showPromptSuggestions.searchParameters),
267
+ getQuery: function getQuery(item) {
268
+ return item.prompt;
269
+ },
270
+ getURL: showPromptSuggestions.getURL
226
271
  });
227
272
  }
228
273
  var recentSearchConfig = showRecent ? {
@@ -255,13 +300,15 @@ function EXPERIMENTAL_Autocomplete(_0) {
255
300
  isSearchPage: isSearchPage,
256
301
  showRecent: showRecent,
257
302
  recentSearchConfig: recentSearchConfig,
258
- showSuggestions: showSuggestions,
303
+ showQuerySuggestions: showQuerySuggestions,
259
304
  detachedMediaQuery: detachedMediaQuery,
260
- translations: translations
305
+ translations: translations,
306
+ showPromptSuggestions: showPromptSuggestions,
307
+ chatRenderState: indexRenderState.chat
261
308
  }))));
262
309
  }
263
310
  function InnerAutocomplete(_0) {
264
- 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, showSuggestions = _0.showSuggestions, transformItems = _0.transformItems, placeholder = _0.placeholder, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, props = _(_0, [
311
+ 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, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, props = _(_0, [
265
312
  "indicesConfig",
266
313
  "refineSearchBox",
267
314
  "isSearchStalled",
@@ -272,13 +319,17 @@ function InnerAutocomplete(_0) {
272
319
  "panelComponent",
273
320
  "showRecent",
274
321
  "recentSearchConfig",
275
- "showSuggestions",
322
+ "showQuerySuggestions",
323
+ "showPromptSuggestions",
324
+ "chatRenderState",
276
325
  "transformItems",
277
326
  "placeholder",
278
327
  "detachedMediaQuery",
279
328
  "translations",
280
329
  "classNames"
281
330
  ]);
331
+ var _ref;
332
+ var _showPromptSuggestions_searchParameters;
282
333
  var _useAutocomplete = useAutocomplete({
283
334
  transformItems: transformItems
284
335
  }), indices = _useAutocomplete.indices, refineAutocomplete = _useAutocomplete.refine, currentRefinement = _useAutocomplete.currentRefinement;
@@ -289,10 +340,57 @@ function InnerAutocomplete(_0) {
289
340
  query: currentRefinement,
290
341
  indices: indices,
291
342
  indicesConfig: indicesConfig,
292
- suggestionsIndexName: showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName
343
+ suggestionsIndexName: showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName
293
344
  }), storage = _useStorage.storage, storageHits = _useStorage.storageHits, indicesForPropGetters = _useStorage.indicesForPropGetters, indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters;
345
+ var promptSuggestionsIndexName = showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName;
346
+ var promptSuggestionsLimit = (_ref = showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_searchParameters = showPromptSuggestions.searchParameters) === null || _showPromptSuggestions_searchParameters === void 0 ? void 0 : _showPromptSuggestions_searchParameters.hitsPerPage) !== null && _ref !== void 0 ? _ref : 3;
347
+ var indicesForPanel = useMemo(function() {
348
+ return indices.map(function(index) {
349
+ var dedupedHits = index.indexName === (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName) && showRecent ? index.hits.filter(function(suggestionHit) {
350
+ return !storageHits.find(function(storageHit) {
351
+ return storageHit.query === suggestionHit.query;
352
+ });
353
+ }) : index.hits;
354
+ if (index.indexName !== promptSuggestionsIndexName) {
355
+ return _$4(_$1({}, index), {
356
+ hits: dedupedHits
357
+ });
358
+ }
359
+ return _$4(_$1({}, index), {
360
+ hits: getPromptSuggestionHits({
361
+ hits: dedupedHits,
362
+ limit: promptSuggestionsLimit
363
+ })
364
+ });
365
+ });
366
+ }, [
367
+ indices,
368
+ promptSuggestionsIndexName,
369
+ promptSuggestionsLimit,
370
+ showRecent,
371
+ showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName,
372
+ storageHits
373
+ ]);
374
+ var indicesForPropGettersWithPromptSuggestions = useMemo(function() {
375
+ return indicesForPropGetters.map(function(index) {
376
+ if (index.indexName !== promptSuggestionsIndexName) {
377
+ return index;
378
+ }
379
+ return _$4(_$1({}, index), {
380
+ hits: getPromptSuggestionHits({
381
+ hits: index.hits,
382
+ limit: promptSuggestionsLimit
383
+ })
384
+ });
385
+ });
386
+ }, [
387
+ indicesForPropGetters,
388
+ promptSuggestionsIndexName,
389
+ promptSuggestionsLimit
390
+ ]);
391
+ useRef(false);
294
392
  var _usePropGetters = usePropGetters({
295
- indices: indicesForPropGetters,
393
+ indices: indicesForPropGettersWithPromptSuggestions,
296
394
  indicesConfig: indicesConfigForPropGetters,
297
395
  onRefine: function onRefine(query) {
298
396
  refineAutocomplete(query);
@@ -303,7 +401,19 @@ function InnerAutocomplete(_0) {
303
401
  refineAutocomplete(query);
304
402
  },
305
403
  onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function(param) {
306
- var query = param.query, setQuery = param.setQuery, url = param.url;
404
+ var item = param.item, query = param.query, setQuery = param.setQuery, url = param.url;
405
+ if (isPromptSuggestion(item)) {
406
+ var chatRenderStateWithFocus = chatRenderState;
407
+ if (chatRenderStateWithFocus) {
408
+ var _chatRenderStateWithFocus_setOpen, _chatRenderStateWithFocus_focusInput, _chatRenderStateWithFocus_sendMessage;
409
+ (_chatRenderStateWithFocus_setOpen = chatRenderStateWithFocus.setOpen) === null || _chatRenderStateWithFocus_setOpen === void 0 ? void 0 : _chatRenderStateWithFocus_setOpen.call(chatRenderStateWithFocus, true);
410
+ (_chatRenderStateWithFocus_focusInput = chatRenderStateWithFocus.focusInput) === null || _chatRenderStateWithFocus_focusInput === void 0 ? void 0 : _chatRenderStateWithFocus_focusInput.call(chatRenderStateWithFocus);
411
+ (_chatRenderStateWithFocus_sendMessage = chatRenderStateWithFocus.sendMessage) === null || _chatRenderStateWithFocus_sendMessage === void 0 ? void 0 : _chatRenderStateWithFocus_sendMessage.call(chatRenderStateWithFocus, {
412
+ text: item.prompt
413
+ });
414
+ return;
415
+ }
416
+ }
307
417
  if (url) {
308
418
  window.location.href = url;
309
419
  return;
@@ -376,14 +486,14 @@ function InnerAutocomplete(_0) {
376
486
  key: "recentSearches"
377
487
  });
378
488
  }
379
- indices.forEach(function(param) {
489
+ indicesForPanel.forEach(function(param) {
380
490
  var indexId = param.indexId, indexName = param.indexName, hits = param.hits;
381
- var elementId = indexName === (showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName) ? 'suggestions' : indexName;
382
- var filteredHits = elementId === 'suggestions' && showRecent ? hits.filter(function(suggestionHit) {
383
- return !storageHits.find(function(storageHit) {
384
- return storageHit.query === suggestionHit.query;
385
- });
386
- }) : hits;
491
+ var elementId = indexName;
492
+ if (indexName === (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName)) {
493
+ elementId = 'suggestions';
494
+ } else if (indexName === (showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName)) {
495
+ elementId = 'promptSuggestions';
496
+ }
387
497
  var currentIndexConfig = indicesConfig.find(function(config) {
388
498
  return config.indexName === indexName;
389
499
  });
@@ -396,7 +506,7 @@ function InnerAutocomplete(_0) {
396
506
  HeaderComponent: currentIndexConfig.headerComponent,
397
507
  // @ts-expect-error - there seems to be problems with React.ComponentType and this, but it's actually correct
398
508
  ItemComponent: currentIndexConfig.itemComponent,
399
- items: filteredHits.map(function(item) {
509
+ items: hits.map(function(item) {
400
510
  return _$4(_$1({}, item), {
401
511
  __indexName: indexId
402
512
  });
@@ -420,7 +530,7 @@ function InnerAutocomplete(_0) {
420
530
  });
421
531
  var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, getPanelProps(), PanelComponent ? /*#__PURE__*/ React.createElement(PanelComponent, {
422
532
  elements: elements,
423
- indices: indices
533
+ indices: indicesForPanel
424
534
  }) : Object.keys(elements).map(function(elementId) {
425
535
  return elements[elementId];
426
536
  }));
@@ -477,5 +587,17 @@ function ConditionalReverseHighlight(param) {
477
587
  hit: item
478
588
  });
479
589
  }
590
+ function ConditionalHighlight(param) {
591
+ var item = param.item, _param_attribute = param.attribute, attribute = _param_attribute === void 0 ? 'query' : _param_attribute;
592
+ var _item__highlightResult;
593
+ if (!((_item__highlightResult = item._highlightResult) === null || _item__highlightResult === void 0 ? void 0 : _item__highlightResult[attribute]) || // @ts-expect-error - we should not have matchLevel as arrays here
594
+ item._highlightResult[attribute].matchLevel === 'none') {
595
+ return /*#__PURE__*/ React.createElement(React.Fragment, null, item[attribute]);
596
+ }
597
+ return /*#__PURE__*/ React.createElement(Highlight, {
598
+ attribute: attribute,
599
+ hit: item
600
+ });
601
+ }
480
602
 
481
603
  export { EXPERIMENTAL_Autocomplete };
@@ -6,7 +6,7 @@ import { _ as _$2 } from '@swc/helpers/cjs/_sliced_to_array.cjs';
6
6
  import { createChatComponent } from 'instantsearch-ui-components';
7
7
  import { SearchIndexToolType, RecommendToolType, MemorizeToolType, MemorySearchToolType, PonderToolType } from 'instantsearch.js/es/lib/chat/index.js';
8
8
  export { MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
9
- import React, { createElement, Fragment } from 'react';
9
+ import React, { createElement, Fragment, useState, useRef, useMemo, useEffect } from 'react';
10
10
  import { useInstantSearch, useChat } from 'react-instantsearch-core';
11
11
  import { useStickToBottom } from '../lib/useStickToBottom.js';
12
12
  import { createCarouselTool } from './chat/tools/SearchIndexTool.js';
@@ -52,13 +52,13 @@ function Chat(_0) {
52
52
  ]);
53
53
  var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
54
54
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
55
- var _React_useState = _$2(React.useState(false), 2), maximized = _React_useState[0], setMaximized = _React_useState[1];
56
- var promptRef = React.useRef(null);
55
+ var _useState = _$2(useState(false), 2), maximized = _useState[0], setMaximized = _useState[1];
56
+ var promptRef = useRef(null);
57
57
  var _useStickToBottom = useStickToBottom({
58
58
  initial: 'smooth',
59
59
  resize: 'smooth'
60
60
  }), scrollRef = _useStickToBottom.scrollRef, contentRef = _useStickToBottom.contentRef, scrollToBottom = _useStickToBottom.scrollToBottom, isAtBottom = _useStickToBottom.isAtBottom;
61
- var tools = React.useMemo(function() {
61
+ var tools = useMemo(function() {
62
62
  var defaults = createDefaultTools(itemComponent, getSearchPageURL);
63
63
  return _$3({}, defaults, userTools);
64
64
  }, [
@@ -70,6 +70,19 @@ function Chat(_0) {
70
70
  tools: tools
71
71
  }));
72
72
  var messages = chatState.messages, sendMessage = chatState.sendMessage, status = chatState.status, regenerate = chatState.regenerate, stop = chatState.stop; chatState.error; var input = chatState.input, setInput = chatState.setInput, open = chatState.open, setOpen = chatState.setOpen, isClearing = chatState.isClearing, clearMessages = chatState.clearMessages, onClearTransitionEnd = chatState.onClearTransitionEnd, toolsFromConnector = chatState.tools, suggestions = chatState.suggestions;
73
+ var wasOpenRef = useRef(false);
74
+ useEffect(function() {
75
+ var shouldFocusPrompt = !wasOpenRef.current && open;
76
+ if (shouldFocusPrompt) {
77
+ window.requestAnimationFrame(function() {
78
+ var _promptRef_current;
79
+ (_promptRef_current = promptRef.current) === null || _promptRef_current === void 0 ? void 0 : _promptRef_current.focus();
80
+ });
81
+ }
82
+ wasOpenRef.current = open;
83
+ }, [
84
+ open
85
+ ]);
73
86
  return /*#__PURE__*/ React.createElement(ChatUiComponent, {
74
87
  title: title,
75
88
  open: open,