react-instantsearch 7.35.1 → 7.36.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.
@@ -65,6 +65,13 @@ var AutocompleteDetachedSearchButton = (0, _instantsearchuicomponents.createAuto
65
65
  Fragment: _react.Fragment
66
66
  });
67
67
  var id = 0;
68
+ var useAutocompleteInstanceId = _react.default.useId ? function() {
69
+ return _react.default.useId().replace(/:/g, '');
70
+ } : function() {
71
+ return _react.default.useState(function() {
72
+ return "a".concat(id++);
73
+ })[0];
74
+ };
68
75
  var usePropGetters = (0, _instantsearchuicomponents.createAutocompletePropGetters)({
69
76
  useEffect: _react.useEffect,
70
77
  useId: _react.default.useId || function() {
@@ -200,91 +207,182 @@ function getMediaQueryList(mediaQuery) {
200
207
  setIsModalOpen: setIsModalOpen
201
208
  };
202
209
  }
203
- function EXPERIMENTAL_Autocomplete(_0) {
204
- 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, aiMode = _0.aiMode, props = _object_without_properties._(_0, [
205
- "indices",
210
+ function EXPERIMENTAL_Autocomplete(props) {
211
+ var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
212
+ var indices = 'indices' in props ? props.indices : undefined;
213
+ var feeds = 'feeds' in props ? props.feeds : undefined;
214
+ var isFeedsMode = feeds !== undefined;
215
+ var showQuerySuggestions = props.showQuerySuggestions, showPromptSuggestions = props.showPromptSuggestions, showRecent = props.showRecent, userSearchParameters = props.searchParameters, detachedMediaQuery = props.detachedMediaQuery, tmp = props.translations, userTranslations = tmp === void 0 ? {} : tmp, transformItems = props.transformItems, restProps = _object_without_properties._(props, [
206
216
  "showQuerySuggestions",
207
217
  "showPromptSuggestions",
208
218
  "showRecent",
209
219
  "searchParameters",
210
220
  "detachedMediaQuery",
211
221
  "translations",
212
- "aiMode"
222
+ "transformItems"
213
223
  ]);
214
- var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
215
224
  var translations = _object_spread._({}, DEFAULT_TRANSLATIONS, userTranslations);
216
225
  var _useInstantSearch = (0, _reactinstantsearchcore.useInstantSearch)(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
226
+ var compositionID = (0, _reactinstantsearchcore.useInstantSearchContext)().compositionID;
217
227
  var refine = (0, _reactinstantsearchcore.useSearchBox)({}, _object_spread._({
218
228
  $$type: 'ais.autocomplete',
219
229
  $$widgetType: 'ais.autocomplete'
220
- }, aiMode ? {
230
+ }, props.aiMode ? {
221
231
  opensChat: true
222
232
  } : {})).refine;
233
+ // In feeds-mode, indexId disambiguates multiple Autocomplete instances
234
+ // sharing the same compositionID. Mirrors the fallback at line 111 for React <18.
235
+ var instanceKey = useAutocompleteInstanceId();
236
+ if (isFeedsMode && indices !== undefined) {
237
+ throw new Error('EXPERIMENTAL_Autocomplete: `feeds` and `indices` are mutually exclusive.');
238
+ }
239
+ if (isFeedsMode && !compositionID) {
240
+ throw new Error('EXPERIMENTAL_Autocomplete in feeds-mode requires a composition-based <InstantSearch> (compositionID must be set).');
241
+ }
223
242
  var isSearchStalled = status === 'stalled';
224
243
  var searchParameters = _object_spread._({
225
244
  hitsPerPage: 5
226
245
  }, userSearchParameters);
227
- var indicesConfig = _to_consumable_array._(indices);
228
- if (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName) {
229
- var _showQuerySuggestions_classNames, _showQuerySuggestions_classNames1, _showQuerySuggestions_classNames2, _showQuerySuggestions_classNames3;
230
- indicesConfig.unshift({
231
- indexName: showQuerySuggestions.indexName,
232
- headerComponent: showQuerySuggestions.headerComponent,
233
- itemComponent: showQuerySuggestions.itemComponent || function(param) {
234
- var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
235
- return /*#__PURE__*/ _react.default.createElement(AutocompleteSuggestion, {
236
- item: item,
237
- onSelect: onSelect,
238
- onApply: onApply
239
- }, /*#__PURE__*/ _react.default.createElement(ConditionalReverseHighlight, {
240
- item: item
241
- }));
242
- },
243
- classNames: {
244
- root: (0, _instantsearchuicomponents.cx)('ais-AutocompleteSuggestions', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames === void 0 ? void 0 : _showQuerySuggestions_classNames.root),
245
- list: (0, _instantsearchuicomponents.cx)('ais-AutocompleteSuggestionsList', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames1 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames1 === void 0 ? void 0 : _showQuerySuggestions_classNames1.list),
246
- header: (0, _instantsearchuicomponents.cx)('ais-AutocompleteSuggestionsHeader', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames2 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames2 === void 0 ? void 0 : _showQuerySuggestions_classNames2.header),
247
- item: (0, _instantsearchuicomponents.cx)('ais-AutocompleteSuggestionsItem', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames3 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames3 === void 0 ? void 0 : _showQuerySuggestions_classNames3.item)
248
- },
249
- searchParameters: _object_spread._({
246
+ // In feeds-mode `indexName` carries the feedID so downstream matching
247
+ // (section building, dedupe in createAutocompleteStorage) treats feeds
248
+ // like indices without any changes to InnerAutocomplete.
249
+ var querySuggestionsKey = isFeedsMode ? showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.feedID : showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName;
250
+ var promptSuggestionsKey = isFeedsMode ? showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.feedID : showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName;
251
+ var indicesConfig = (0, _react.useMemo)(function() {
252
+ var config = isFeedsMode ? feeds.map(function(feed) {
253
+ return {
254
+ indexName: feed.feedID,
255
+ headerComponent: feed.headerComponent,
256
+ itemComponent: feed.itemComponent,
257
+ noResultsComponent: feed.noResultsComponent,
258
+ getURL: feed.getURL,
259
+ getQuery: feed.getQuery,
260
+ classNames: feed.classNames
261
+ };
262
+ }) : _to_consumable_array._(indices !== null && indices !== void 0 ? indices : []);
263
+ if (querySuggestionsKey) {
264
+ var _showQuerySuggestions_classNames, _showQuerySuggestions_classNames1, _showQuerySuggestions_classNames2, _showQuerySuggestions_classNames3;
265
+ var querySuggestionsSearchParameters = isFeedsMode ? undefined : _object_spread._({
250
266
  hitsPerPage: 3
251
- }, showQuerySuggestions.searchParameters),
252
- getQuery: function getQuery(item) {
253
- return item.query;
254
- },
255
- getURL: showQuerySuggestions.getURL
256
- });
257
- }
258
- if (showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName) {
259
- var _showPromptSuggestions_classNames, _showPromptSuggestions_classNames1, _showPromptSuggestions_classNames2, _showPromptSuggestions_classNames3;
260
- indicesConfig.push({
261
- indexName: showPromptSuggestions.indexName,
262
- headerComponent: showPromptSuggestions.headerComponent,
263
- itemComponent: showPromptSuggestions.itemComponent || function(param) {
264
- var item = param.item, onSelect = param.onSelect;
265
- return /*#__PURE__*/ _react.default.createElement(AutocompletePromptSuggestion, {
266
- item: item,
267
- onSelect: onSelect
268
- }, /*#__PURE__*/ _react.default.createElement(ConditionalHighlight, {
269
- item: item,
270
- attribute: "prompt"
271
- }));
272
- },
273
- classNames: {
274
- root: (0, _instantsearchuicomponents.cx)('ais-AutocompletePromptSuggestions', (_showPromptSuggestions_classNames = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames === void 0 ? void 0 : _showPromptSuggestions_classNames.root),
275
- list: (0, _instantsearchuicomponents.cx)('ais-AutocompletePromptSuggestionsList', (_showPromptSuggestions_classNames1 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames1 === void 0 ? void 0 : _showPromptSuggestions_classNames1.list),
276
- header: (0, _instantsearchuicomponents.cx)('ais-AutocompletePromptSuggestionsHeader', (_showPromptSuggestions_classNames2 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames2 === void 0 ? void 0 : _showPromptSuggestions_classNames2.header),
277
- item: (0, _instantsearchuicomponents.cx)('ais-AutocompletePromptSuggestionsItem', (_showPromptSuggestions_classNames3 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames3 === void 0 ? void 0 : _showPromptSuggestions_classNames3.item)
278
- },
279
- searchParameters: _object_spread._({
267
+ }, showQuerySuggestions.searchParameters);
268
+ config.unshift({
269
+ indexName: querySuggestionsKey,
270
+ headerComponent: showQuerySuggestions.headerComponent,
271
+ itemComponent: showQuerySuggestions.itemComponent || function(param) {
272
+ var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
273
+ return /*#__PURE__*/ _react.default.createElement(AutocompleteSuggestion, {
274
+ item: item,
275
+ onSelect: onSelect,
276
+ onApply: onApply
277
+ }, /*#__PURE__*/ _react.default.createElement(ConditionalReverseHighlight, {
278
+ item: item
279
+ }));
280
+ },
281
+ classNames: {
282
+ root: (0, _instantsearchuicomponents.cx)('ais-AutocompleteSuggestions', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames === void 0 ? void 0 : _showQuerySuggestions_classNames.root),
283
+ list: (0, _instantsearchuicomponents.cx)('ais-AutocompleteSuggestionsList', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames1 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames1 === void 0 ? void 0 : _showQuerySuggestions_classNames1.list),
284
+ header: (0, _instantsearchuicomponents.cx)('ais-AutocompleteSuggestionsHeader', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames2 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames2 === void 0 ? void 0 : _showQuerySuggestions_classNames2.header),
285
+ item: (0, _instantsearchuicomponents.cx)('ais-AutocompleteSuggestionsItem', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames3 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames3 === void 0 ? void 0 : _showQuerySuggestions_classNames3.item)
286
+ },
287
+ searchParameters: querySuggestionsSearchParameters,
288
+ getQuery: function getQuery(item) {
289
+ return item.query;
290
+ },
291
+ getURL: showQuerySuggestions.getURL
292
+ });
293
+ }
294
+ if (promptSuggestionsKey) {
295
+ var _showPromptSuggestions_classNames, _showPromptSuggestions_classNames1, _showPromptSuggestions_classNames2, _showPromptSuggestions_classNames3;
296
+ var promptSuggestionsSearchParameters = isFeedsMode ? undefined : _object_spread._({
280
297
  hitsPerPage: 3
281
- }, showPromptSuggestions.searchParameters),
282
- getQuery: function getQuery(item) {
283
- return item.prompt;
284
- },
285
- getURL: showPromptSuggestions.getURL
286
- });
287
- }
298
+ }, showPromptSuggestions.searchParameters);
299
+ config.push({
300
+ indexName: promptSuggestionsKey,
301
+ headerComponent: showPromptSuggestions.headerComponent,
302
+ itemComponent: showPromptSuggestions.itemComponent || function(param) {
303
+ var item = param.item, onSelect = param.onSelect;
304
+ return /*#__PURE__*/ _react.default.createElement(AutocompletePromptSuggestion, {
305
+ item: item,
306
+ onSelect: onSelect
307
+ }, /*#__PURE__*/ _react.default.createElement(ConditionalHighlight, {
308
+ item: item,
309
+ attribute: "prompt"
310
+ }));
311
+ },
312
+ classNames: {
313
+ root: (0, _instantsearchuicomponents.cx)('ais-AutocompletePromptSuggestions', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames === void 0 ? void 0 : _showPromptSuggestions_classNames.root),
314
+ list: (0, _instantsearchuicomponents.cx)('ais-AutocompletePromptSuggestionsList', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames1 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames1 === void 0 ? void 0 : _showPromptSuggestions_classNames1.list),
315
+ header: (0, _instantsearchuicomponents.cx)('ais-AutocompletePromptSuggestionsHeader', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames2 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames2 === void 0 ? void 0 : _showPromptSuggestions_classNames2.header),
316
+ item: (0, _instantsearchuicomponents.cx)('ais-AutocompletePromptSuggestionsItem', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames3 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames3 === void 0 ? void 0 : _showPromptSuggestions_classNames3.item)
317
+ },
318
+ searchParameters: promptSuggestionsSearchParameters,
319
+ getQuery: function getQuery(item) {
320
+ return item.prompt;
321
+ },
322
+ getURL: showPromptSuggestions.getURL
323
+ });
324
+ }
325
+ return config;
326
+ }, [
327
+ feeds,
328
+ indices,
329
+ isFeedsMode,
330
+ promptSuggestionsKey,
331
+ querySuggestionsKey,
332
+ showPromptSuggestions,
333
+ showQuerySuggestions
334
+ ]);
335
+ // Normalize `show*` for InnerAutocomplete: always surface `indexName`
336
+ // (in feeds-mode it carries the feedID). Keeps downstream dedupe in
337
+ // createAutocompleteStorage (suggestionsIndexName === index.indexName) working.
338
+ var normalizedShowQuerySuggestions = (0, _react.useMemo)(function() {
339
+ if (!showQuerySuggestions) {
340
+ return undefined;
341
+ }
342
+ if (isFeedsMode) {
343
+ return _object_spread_props._(_object_spread._({}, showQuerySuggestions), {
344
+ indexName: querySuggestionsKey
345
+ });
346
+ }
347
+ return showQuerySuggestions;
348
+ }, [
349
+ isFeedsMode,
350
+ querySuggestionsKey,
351
+ showQuerySuggestions
352
+ ]);
353
+ var normalizedShowPromptSuggestions = (0, _react.useMemo)(function() {
354
+ if (!showPromptSuggestions) {
355
+ return undefined;
356
+ }
357
+ if (isFeedsMode) {
358
+ return _object_spread_props._(_object_spread._({}, showPromptSuggestions), {
359
+ indexName: promptSuggestionsKey
360
+ });
361
+ }
362
+ return showPromptSuggestions;
363
+ }, [
364
+ isFeedsMode,
365
+ promptSuggestionsKey,
366
+ showPromptSuggestions
367
+ ]);
368
+ // In feeds-mode, remap `indexName := indexId` so downstream storage (which
369
+ // matches on indexName) sees feedIDs instead of the composition index name
370
+ // that connectAutocomplete sets from the helper results.
371
+ // Must be memoized: useConnector's useStableValue runs dequal on each render
372
+ // and treats a new function identity as a change, re-registering the widget.
373
+ var effectiveTransformItems = (0, _react.useMemo)(function() {
374
+ return isFeedsMode ? function(items) {
375
+ var remapped = items.map(function(item) {
376
+ return _object_spread_props._(_object_spread._({}, item), {
377
+ indexName: item.indexId
378
+ });
379
+ });
380
+ return transformItems ? transformItems(remapped) : remapped;
381
+ } : transformItems;
382
+ }, [
383
+ isFeedsMode,
384
+ transformItems
385
+ ]);
288
386
  var recentSearchConfig = showRecent ? {
289
387
  headerComponent: (typeof showRecent === "undefined" ? "undefined" : _type_of._(showRecent)) === 'object' ? showRecent.headerComponent : undefined,
290
388
  itemComponent: (typeof showRecent === "undefined" ? "undefined" : _type_of._(showRecent)) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
@@ -300,15 +398,11 @@ function EXPERIMENTAL_Autocomplete(_0) {
300
398
  }, [
301
399
  indexRenderState
302
400
  ]);
303
- return /*#__PURE__*/ _react.default.createElement(_react.Fragment, null, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Index, {
304
- EXPERIMENTAL_isolated: true
305
- }, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Configure, searchParameters), indicesConfig.map(function(index) {
306
- return /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Index, {
307
- key: index.indexName,
308
- indexName: index.indexName
309
- }, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Configure, index.searchParameters));
310
- }), /*#__PURE__*/ _react.default.createElement(InnerAutocomplete, _object_spread_props._(_object_spread._({}, props), {
311
- aiMode: aiMode,
401
+ restProps.indices; restProps.feeds; var forwardedProps = _object_without_properties._(restProps, [
402
+ "indices",
403
+ "feeds"
404
+ ]);
405
+ var innerAutocomplete = /*#__PURE__*/ _react.default.createElement(InnerAutocomplete, _object_spread_props._(_object_spread._({}, forwardedProps), {
312
406
  indicesConfig: indicesConfig,
313
407
  refineSearchBox: refine,
314
408
  isSearchStalled: isSearchStalled,
@@ -316,12 +410,33 @@ function EXPERIMENTAL_Autocomplete(_0) {
316
410
  isSearchPage: isSearchPage,
317
411
  showRecent: showRecent,
318
412
  recentSearchConfig: recentSearchConfig,
319
- showQuerySuggestions: showQuerySuggestions,
413
+ showQuerySuggestions: normalizedShowQuerySuggestions,
320
414
  detachedMediaQuery: detachedMediaQuery,
321
415
  translations: translations,
322
- showPromptSuggestions: showPromptSuggestions,
416
+ showPromptSuggestions: normalizedShowPromptSuggestions,
417
+ transformItems: effectiveTransformItems,
323
418
  chatRenderState: indexRenderState.chat
324
- }))));
419
+ }));
420
+ if (isFeedsMode) {
421
+ return /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Index, {
422
+ EXPERIMENTAL_isolated: true,
423
+ indexName: compositionID,
424
+ indexId: "ais-autocomplete-".concat(instanceKey)
425
+ }, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Configure, searchParameters), /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Feeds, {
426
+ isolated: false,
427
+ renderFeed: function renderFeed() {
428
+ return null;
429
+ }
430
+ }), innerAutocomplete);
431
+ }
432
+ return /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Index, {
433
+ EXPERIMENTAL_isolated: true
434
+ }, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Configure, searchParameters), indicesConfig.map(function(index) {
435
+ return /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Index, {
436
+ key: index.indexName,
437
+ indexName: index.indexName
438
+ }, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Configure, index.searchParameters));
439
+ }), innerAutocomplete);
325
440
  }
326
441
  function InnerAutocomplete(_0) {
327
442
  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, [
@@ -51,7 +51,8 @@ var _DisplayResultsTool = require("./chat/tools/DisplayResultsTool");
51
51
  var _SearchIndexTool = require("./chat/tools/SearchIndexTool");
52
52
  var ChatUiComponent = (0, _instantsearchuicomponents.createChatComponent)({
53
53
  createElement: _react.createElement,
54
- Fragment: _react.Fragment
54
+ Fragment: _react.Fragment,
55
+ memo: _react.memo
55
56
  });
56
57
  function createDefaultTools(itemComponent, getSearchPageURL) {
57
58
  var _obj;
@@ -139,6 +140,23 @@ function ChatInner(_0, _1) {
139
140
  }, [
140
141
  open
141
142
  ]);
143
+ // Keep the conversation pinned to the bottom while streaming. The stick-to-
144
+ // bottom ResizeObserver only reacts to content *height* changes, but tool
145
+ // results such as a horizontally-growing carousel stream in without changing
146
+ // height — so we also re-pin on every message/status update. Passing
147
+ // `preserveScrollPosition` reuses the existing "only if already at the
148
+ // bottom" gate, so this never fights a user who has scrolled up to read.
149
+ (0, _react.useEffect)(function() {
150
+ if (status === 'streaming' || status === 'submitted') {
151
+ scrollToBottom({
152
+ preserveScrollPosition: true
153
+ });
154
+ }
155
+ }, [
156
+ messages,
157
+ status,
158
+ scrollToBottom
159
+ ]);
142
160
  return /*#__PURE__*/ _react.default.createElement(ChatUiComponent, {
143
161
  title: title,
144
162
  open: open,
@@ -21,36 +21,74 @@ type AutocompleteTranslations = {
21
21
  detachedSearchButtonTitle: string;
22
22
  detachedClearButtonTitle: string;
23
23
  };
24
- export type AutocompleteProps<TItem extends BaseHit> = ComponentProps<'div'> & {
25
- indices?: Array<IndexConfig<TItem>>;
26
- showQuerySuggestions?: Partial<Pick<IndexConfig<{
24
+ export type FeedConfig<TItem extends BaseHit> = {
25
+ feedID: string;
26
+ headerComponent?: AutocompleteIndexProps<TItem>['HeaderComponent'];
27
+ itemComponent: AutocompleteIndexProps<TItem>['ItemComponent'];
28
+ noResultsComponent?: AutocompleteIndexProps<TItem>['NoResultsComponent'];
29
+ getURL?: AutocompleteIndexConfig<TItem>['getURL'];
30
+ getQuery?: AutocompleteIndexConfig<TItem>['getQuery'];
31
+ classNames?: Partial<AutocompleteIndexClassNames>;
32
+ };
33
+ type IndicesShowQuerySuggestionsConfig = Partial<Pick<IndexConfig<{
34
+ query: string;
35
+ }>, 'indexName' | 'getURL' | 'headerComponent' | 'itemComponent' | 'classNames' | 'searchParameters'>>;
36
+ type FeedsShowQuerySuggestionsConfig = {
37
+ feedID: string;
38
+ getURL?: IndexConfig<{
27
39
  query: string;
28
- }>, 'indexName' | 'getURL' | 'headerComponent' | 'itemComponent' | 'classNames' | 'searchParameters'>>;
29
- showPromptSuggestions?: Partial<Pick<IndexConfig<{
40
+ }>['getURL'];
41
+ headerComponent?: IndexConfig<{
42
+ query: string;
43
+ }>['headerComponent'];
44
+ itemComponent?: IndexConfig<{
45
+ query: string;
46
+ }>['itemComponent'];
47
+ classNames?: Partial<AutocompleteIndexClassNames>;
48
+ };
49
+ type IndicesShowPromptSuggestionsConfig = Partial<Pick<IndexConfig<{
50
+ query: string;
51
+ label?: string;
52
+ }>, 'indexName' | 'getURL' | 'headerComponent' | 'itemComponent' | 'classNames' | 'searchParameters'>>;
53
+ type FeedsShowPromptSuggestionsConfig = {
54
+ feedID: string;
55
+ getURL?: IndexConfig<{
56
+ query: string;
57
+ label?: string;
58
+ }>['getURL'];
59
+ headerComponent?: IndexConfig<{
30
60
  query: string;
31
61
  label?: string;
32
- }>, 'indexName' | 'getURL' | 'headerComponent' | 'itemComponent' | 'classNames' | 'searchParameters'>>;
33
- showRecent?: boolean | {
34
- /**
35
- * Storage key to use in the local storage.
36
- */
37
- storageKey?: string;
38
- /**
39
- * Component to use for the header, before the list of items.
40
- */
41
- headerComponent?: AutocompleteIndexProps<{
42
- query: string;
43
- }>['HeaderComponent'];
44
- /**
45
- * Component to use for each recent search item.
46
- */
47
- itemComponent?: AutocompleteIndexProps<{
48
- query: string;
49
- }>['ItemComponent'] & {
50
- onRemoveRecentSearch: () => void;
51
- };
52
- classNames?: Partial<AutocompleteIndexClassNames>;
62
+ }>['headerComponent'];
63
+ itemComponent?: IndexConfig<{
64
+ query: string;
65
+ label?: string;
66
+ }>['itemComponent'];
67
+ classNames?: Partial<AutocompleteIndexClassNames>;
68
+ };
69
+ type AutocompleteShowRecentConfig = {
70
+ /**
71
+ * Storage key to use in the local storage.
72
+ */
73
+ storageKey?: string;
74
+ /**
75
+ * Component to use for the header, before the list of items.
76
+ */
77
+ headerComponent?: AutocompleteIndexProps<{
78
+ query: string;
79
+ }>['HeaderComponent'];
80
+ /**
81
+ * Component to use for each recent search item.
82
+ */
83
+ itemComponent?: AutocompleteIndexProps<{
84
+ query: string;
85
+ }>['ItemComponent'] & {
86
+ onRemoveRecentSearch: () => void;
53
87
  };
88
+ classNames?: Partial<AutocompleteIndexClassNames>;
89
+ };
90
+ type AutocompleteCommonProps<TItem extends BaseHit> = ComponentProps<'div'> & {
91
+ showRecent?: boolean | AutocompleteShowRecentConfig;
54
92
  getSearchPageURL?: (nextUiState: IndexUiState) => string;
55
93
  onSelect?: AutocompleteIndexConfig<TItem>['onSelect'];
56
94
  transformItems?: (indices: TransformItemsIndicesConfig[]) => TransformItemsIndicesConfig[];
@@ -84,5 +122,18 @@ export type AutocompleteProps<TItem extends BaseHit> = ComponentProps<'div'> & {
84
122
  */
85
123
  aiMode?: boolean;
86
124
  };
87
- export declare function EXPERIMENTAL_Autocomplete<TItem extends BaseHit = BaseHit>({ indices, showQuerySuggestions, showPromptSuggestions, showRecent, searchParameters: userSearchParameters, detachedMediaQuery, translations: userTranslations, aiMode, ...props }: AutocompleteProps<TItem>): React.JSX.Element;
125
+ export type AutocompleteIndicesProps<TItem extends BaseHit> = AutocompleteCommonProps<TItem> & {
126
+ indices?: Array<IndexConfig<TItem>>;
127
+ feeds?: never;
128
+ showQuerySuggestions?: IndicesShowQuerySuggestionsConfig;
129
+ showPromptSuggestions?: IndicesShowPromptSuggestionsConfig;
130
+ };
131
+ export type AutocompleteFeedsProps<TItem extends BaseHit> = AutocompleteCommonProps<TItem> & {
132
+ feeds: Array<FeedConfig<TItem>>;
133
+ indices?: never;
134
+ showQuerySuggestions?: FeedsShowQuerySuggestionsConfig;
135
+ showPromptSuggestions?: FeedsShowPromptSuggestionsConfig;
136
+ };
137
+ export type AutocompleteProps<TItem extends BaseHit> = AutocompleteIndicesProps<TItem> | AutocompleteFeedsProps<TItem>;
138
+ export declare function EXPERIMENTAL_Autocomplete<TItem extends BaseHit = BaseHit>(props: AutocompleteProps<TItem>): React.JSX.Element;
88
139
  export {};