react-instantsearch 7.35.0 → 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.
- package/dist/cjs/widgets/Autocomplete.js +192 -77
- package/dist/cjs/widgets/Chat.js +19 -1
- package/dist/cjs/widgets/chat/tools/DisplayResultsTool.js +2 -1
- package/dist/cjs/widgets/chat/tools/SearchIndexTool.js +1 -1
- package/dist/es/widgets/Autocomplete.d.ts +78 -27
- package/dist/es/widgets/Autocomplete.js +210 -95
- package/dist/es/widgets/Chat.js +20 -2
- package/dist/es/widgets/chat/tools/DisplayResultsTool.js +3 -2
- package/dist/es/widgets/chat/tools/SearchIndexTool.js +2 -2
- package/dist/umd/ReactInstantSearch.js +396 -103
- package/dist/umd/ReactInstantSearch.min.js +3 -3
- package/package.json +5 -5
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { _ as _$1 } from '@swc/helpers/esm/_object_spread.js';
|
|
2
|
-
import { _ as _$
|
|
2
|
+
import { _ as _$3 } from '@swc/helpers/esm/_object_spread_props.js';
|
|
3
3
|
import { _ } from '@swc/helpers/esm/_object_without_properties.js';
|
|
4
4
|
import { _ as _$5 } from '@swc/helpers/esm/_sliced_to_array.js';
|
|
5
5
|
import { _ as _$2 } from '@swc/helpers/esm/_to_consumable_array.js';
|
|
6
|
-
import { _ as _$
|
|
6
|
+
import { _ as _$4 } from '@swc/helpers/esm/_type_of.js';
|
|
7
7
|
import { createAutocompleteComponent, createAutocompletePanelComponent, createAutocompleteIndexComponent, createAutocompleteSuggestionComponent, createAutocompletePromptSuggestionComponent, createAutocompleteRecentSearchComponent, createAutocompleteDetachedContainerComponent, createAutocompleteDetachedOverlayComponent, createAutocompleteDetachedFormContainerComponent, createAutocompleteDetachedSearchButtonComponent, createAutocompletePropGetters, createAutocompleteStorage, cx, getPromptSuggestionHits, isPromptSuggestion } from 'instantsearch-ui-components';
|
|
8
8
|
import { openChat, isChatBusy } from 'instantsearch.js/es/lib/chat/index.js';
|
|
9
9
|
import 'instantsearch.js/es/lib/utils/index.js';
|
|
10
10
|
import React, { createElement, Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
-
import { useInstantSearch, useSearchBox, Index, Configure, useAutocomplete } from 'react-instantsearch-core';
|
|
11
|
+
import { useInstantSearch, useInstantSearchContext, useSearchBox, Index, Configure, Feeds, useAutocomplete } from 'react-instantsearch-core';
|
|
12
12
|
import { AutocompleteSearch } from '../components/AutocompleteSearch.js';
|
|
13
13
|
import { Highlight } from './Highlight.js';
|
|
14
14
|
import { ReverseHighlight } from './ReverseHighlight.js';
|
|
@@ -54,6 +54,13 @@ var AutocompleteDetachedSearchButton = createAutocompleteDetachedSearchButtonCom
|
|
|
54
54
|
Fragment: Fragment
|
|
55
55
|
});
|
|
56
56
|
var id = 0;
|
|
57
|
+
var useAutocompleteInstanceId = React.useId ? function() {
|
|
58
|
+
return React.useId().replace(/:/g, '');
|
|
59
|
+
} : function() {
|
|
60
|
+
return React.useState(function() {
|
|
61
|
+
return "a".concat(id++);
|
|
62
|
+
})[0];
|
|
63
|
+
};
|
|
57
64
|
var usePropGetters = createAutocompletePropGetters({
|
|
58
65
|
useEffect: useEffect,
|
|
59
66
|
useId: React.useId || function() {
|
|
@@ -189,99 +196,190 @@ function getMediaQueryList(mediaQuery) {
|
|
|
189
196
|
setIsModalOpen: setIsModalOpen
|
|
190
197
|
};
|
|
191
198
|
}
|
|
192
|
-
function EXPERIMENTAL_Autocomplete(
|
|
193
|
-
var
|
|
194
|
-
|
|
199
|
+
function EXPERIMENTAL_Autocomplete(props) {
|
|
200
|
+
var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
|
|
201
|
+
var indices = 'indices' in props ? props.indices : undefined;
|
|
202
|
+
var feeds = 'feeds' in props ? props.feeds : undefined;
|
|
203
|
+
var isFeedsMode = feeds !== undefined;
|
|
204
|
+
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 = _(props, [
|
|
195
205
|
"showQuerySuggestions",
|
|
196
206
|
"showPromptSuggestions",
|
|
197
207
|
"showRecent",
|
|
198
208
|
"searchParameters",
|
|
199
209
|
"detachedMediaQuery",
|
|
200
210
|
"translations",
|
|
201
|
-
"
|
|
211
|
+
"transformItems"
|
|
202
212
|
]);
|
|
203
|
-
var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
|
|
204
213
|
var translations = _$1({}, DEFAULT_TRANSLATIONS, userTranslations);
|
|
205
214
|
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
|
|
215
|
+
var compositionID = useInstantSearchContext().compositionID;
|
|
206
216
|
var refine = useSearchBox({}, _$1({
|
|
207
217
|
$$type: 'ais.autocomplete',
|
|
208
218
|
$$widgetType: 'ais.autocomplete'
|
|
209
|
-
}, aiMode ? {
|
|
219
|
+
}, props.aiMode ? {
|
|
210
220
|
opensChat: true
|
|
211
221
|
} : {})).refine;
|
|
222
|
+
// In feeds-mode, indexId disambiguates multiple Autocomplete instances
|
|
223
|
+
// sharing the same compositionID. Mirrors the fallback at line 111 for React <18.
|
|
224
|
+
var instanceKey = useAutocompleteInstanceId();
|
|
225
|
+
if (isFeedsMode && indices !== undefined) {
|
|
226
|
+
throw new Error('EXPERIMENTAL_Autocomplete: `feeds` and `indices` are mutually exclusive.');
|
|
227
|
+
}
|
|
228
|
+
if (isFeedsMode && !compositionID) {
|
|
229
|
+
throw new Error('EXPERIMENTAL_Autocomplete in feeds-mode requires a composition-based <InstantSearch> (compositionID must be set).');
|
|
230
|
+
}
|
|
212
231
|
var isSearchStalled = status === 'stalled';
|
|
213
232
|
var searchParameters = _$1({
|
|
214
233
|
hitsPerPage: 5
|
|
215
234
|
}, userSearchParameters);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
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)
|
|
237
|
-
},
|
|
238
|
-
searchParameters: _$1({
|
|
235
|
+
// In feeds-mode `indexName` carries the feedID so downstream matching
|
|
236
|
+
// (section building, dedupe in createAutocompleteStorage) treats feeds
|
|
237
|
+
// like indices without any changes to InnerAutocomplete.
|
|
238
|
+
var querySuggestionsKey = isFeedsMode ? showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.feedID : showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName;
|
|
239
|
+
var promptSuggestionsKey = isFeedsMode ? showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.feedID : showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName;
|
|
240
|
+
var indicesConfig = useMemo(function() {
|
|
241
|
+
var config = isFeedsMode ? feeds.map(function(feed) {
|
|
242
|
+
return {
|
|
243
|
+
indexName: feed.feedID,
|
|
244
|
+
headerComponent: feed.headerComponent,
|
|
245
|
+
itemComponent: feed.itemComponent,
|
|
246
|
+
noResultsComponent: feed.noResultsComponent,
|
|
247
|
+
getURL: feed.getURL,
|
|
248
|
+
getQuery: feed.getQuery,
|
|
249
|
+
classNames: feed.classNames
|
|
250
|
+
};
|
|
251
|
+
}) : _$2(indices !== null && indices !== void 0 ? indices : []);
|
|
252
|
+
if (querySuggestionsKey) {
|
|
253
|
+
var _showQuerySuggestions_classNames, _showQuerySuggestions_classNames1, _showQuerySuggestions_classNames2, _showQuerySuggestions_classNames3;
|
|
254
|
+
var querySuggestionsSearchParameters = isFeedsMode ? undefined : _$1({
|
|
239
255
|
hitsPerPage: 3
|
|
240
|
-
}, showQuerySuggestions.searchParameters)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
item: item
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
256
|
+
}, showQuerySuggestions.searchParameters);
|
|
257
|
+
config.unshift({
|
|
258
|
+
indexName: querySuggestionsKey,
|
|
259
|
+
headerComponent: showQuerySuggestions.headerComponent,
|
|
260
|
+
itemComponent: showQuerySuggestions.itemComponent || function(param) {
|
|
261
|
+
var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
|
|
262
|
+
return /*#__PURE__*/ React.createElement(AutocompleteSuggestion, {
|
|
263
|
+
item: item,
|
|
264
|
+
onSelect: onSelect,
|
|
265
|
+
onApply: onApply
|
|
266
|
+
}, /*#__PURE__*/ React.createElement(ConditionalReverseHighlight, {
|
|
267
|
+
item: item
|
|
268
|
+
}));
|
|
269
|
+
},
|
|
270
|
+
classNames: {
|
|
271
|
+
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),
|
|
272
|
+
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),
|
|
273
|
+
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),
|
|
274
|
+
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)
|
|
275
|
+
},
|
|
276
|
+
searchParameters: querySuggestionsSearchParameters,
|
|
277
|
+
getQuery: function getQuery(item) {
|
|
278
|
+
return item.query;
|
|
279
|
+
},
|
|
280
|
+
getURL: showQuerySuggestions.getURL
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
if (promptSuggestionsKey) {
|
|
284
|
+
var _showPromptSuggestions_classNames, _showPromptSuggestions_classNames1, _showPromptSuggestions_classNames2, _showPromptSuggestions_classNames3;
|
|
285
|
+
var promptSuggestionsSearchParameters = isFeedsMode ? undefined : _$1({
|
|
269
286
|
hitsPerPage: 3
|
|
270
|
-
}, showPromptSuggestions.searchParameters)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
287
|
+
}, showPromptSuggestions.searchParameters);
|
|
288
|
+
config.push({
|
|
289
|
+
indexName: promptSuggestionsKey,
|
|
290
|
+
headerComponent: showPromptSuggestions.headerComponent,
|
|
291
|
+
itemComponent: showPromptSuggestions.itemComponent || function(param) {
|
|
292
|
+
var item = param.item, onSelect = param.onSelect;
|
|
293
|
+
return /*#__PURE__*/ React.createElement(AutocompletePromptSuggestion, {
|
|
294
|
+
item: item,
|
|
295
|
+
onSelect: onSelect
|
|
296
|
+
}, /*#__PURE__*/ React.createElement(ConditionalHighlight, {
|
|
297
|
+
item: item,
|
|
298
|
+
attribute: "prompt"
|
|
299
|
+
}));
|
|
300
|
+
},
|
|
301
|
+
classNames: {
|
|
302
|
+
root: cx('ais-AutocompletePromptSuggestions', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames === void 0 ? void 0 : _showPromptSuggestions_classNames.root),
|
|
303
|
+
list: cx('ais-AutocompletePromptSuggestionsList', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames1 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames1 === void 0 ? void 0 : _showPromptSuggestions_classNames1.list),
|
|
304
|
+
header: cx('ais-AutocompletePromptSuggestionsHeader', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames2 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames2 === void 0 ? void 0 : _showPromptSuggestions_classNames2.header),
|
|
305
|
+
item: cx('ais-AutocompletePromptSuggestionsItem', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames3 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames3 === void 0 ? void 0 : _showPromptSuggestions_classNames3.item)
|
|
306
|
+
},
|
|
307
|
+
searchParameters: promptSuggestionsSearchParameters,
|
|
308
|
+
getQuery: function getQuery(item) {
|
|
309
|
+
return item.prompt;
|
|
310
|
+
},
|
|
311
|
+
getURL: showPromptSuggestions.getURL
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return config;
|
|
315
|
+
}, [
|
|
316
|
+
feeds,
|
|
317
|
+
indices,
|
|
318
|
+
isFeedsMode,
|
|
319
|
+
promptSuggestionsKey,
|
|
320
|
+
querySuggestionsKey,
|
|
321
|
+
showPromptSuggestions,
|
|
322
|
+
showQuerySuggestions
|
|
323
|
+
]);
|
|
324
|
+
// Normalize `show*` for InnerAutocomplete: always surface `indexName`
|
|
325
|
+
// (in feeds-mode it carries the feedID). Keeps downstream dedupe in
|
|
326
|
+
// createAutocompleteStorage (suggestionsIndexName === index.indexName) working.
|
|
327
|
+
var normalizedShowQuerySuggestions = useMemo(function() {
|
|
328
|
+
if (!showQuerySuggestions) {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
if (isFeedsMode) {
|
|
332
|
+
return _$3(_$1({}, showQuerySuggestions), {
|
|
333
|
+
indexName: querySuggestionsKey
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
return showQuerySuggestions;
|
|
337
|
+
}, [
|
|
338
|
+
isFeedsMode,
|
|
339
|
+
querySuggestionsKey,
|
|
340
|
+
showQuerySuggestions
|
|
341
|
+
]);
|
|
342
|
+
var normalizedShowPromptSuggestions = useMemo(function() {
|
|
343
|
+
if (!showPromptSuggestions) {
|
|
344
|
+
return undefined;
|
|
345
|
+
}
|
|
346
|
+
if (isFeedsMode) {
|
|
347
|
+
return _$3(_$1({}, showPromptSuggestions), {
|
|
348
|
+
indexName: promptSuggestionsKey
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
return showPromptSuggestions;
|
|
352
|
+
}, [
|
|
353
|
+
isFeedsMode,
|
|
354
|
+
promptSuggestionsKey,
|
|
355
|
+
showPromptSuggestions
|
|
356
|
+
]);
|
|
357
|
+
// In feeds-mode, remap `indexName := indexId` so downstream storage (which
|
|
358
|
+
// matches on indexName) sees feedIDs instead of the composition index name
|
|
359
|
+
// that connectAutocomplete sets from the helper results.
|
|
360
|
+
// Must be memoized: useConnector's useStableValue runs dequal on each render
|
|
361
|
+
// and treats a new function identity as a change, re-registering the widget.
|
|
362
|
+
var effectiveTransformItems = useMemo(function() {
|
|
363
|
+
return isFeedsMode ? function(items) {
|
|
364
|
+
var remapped = items.map(function(item) {
|
|
365
|
+
return _$3(_$1({}, item), {
|
|
366
|
+
indexName: item.indexId
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
return transformItems ? transformItems(remapped) : remapped;
|
|
370
|
+
} : transformItems;
|
|
371
|
+
}, [
|
|
372
|
+
isFeedsMode,
|
|
373
|
+
transformItems
|
|
374
|
+
]);
|
|
277
375
|
var recentSearchConfig = showRecent ? {
|
|
278
|
-
headerComponent: (typeof showRecent === "undefined" ? "undefined" : _$
|
|
279
|
-
itemComponent: (typeof showRecent === "undefined" ? "undefined" : _$
|
|
376
|
+
headerComponent: (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? showRecent.headerComponent : undefined,
|
|
377
|
+
itemComponent: (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
|
|
280
378
|
classNames: {
|
|
281
|
-
root: cx('ais-AutocompleteRecentSearches', (typeof showRecent === "undefined" ? "undefined" : _$
|
|
282
|
-
list: cx('ais-AutocompleteRecentSearchesList', (typeof showRecent === "undefined" ? "undefined" : _$
|
|
283
|
-
header: cx('ais-AutocompleteRecentSearchesHeader', (typeof showRecent === "undefined" ? "undefined" : _$
|
|
284
|
-
item: cx('ais-AutocompleteRecentSearchesItem', (typeof showRecent === "undefined" ? "undefined" : _$
|
|
379
|
+
root: cx('ais-AutocompleteRecentSearches', (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? (_showRecent_classNames = showRecent.classNames) === null || _showRecent_classNames === void 0 ? void 0 : _showRecent_classNames.root : undefined),
|
|
380
|
+
list: cx('ais-AutocompleteRecentSearchesList', (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? (_showRecent_classNames1 = showRecent.classNames) === null || _showRecent_classNames1 === void 0 ? void 0 : _showRecent_classNames1.list : undefined),
|
|
381
|
+
header: cx('ais-AutocompleteRecentSearchesHeader', (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? (_showRecent_classNames2 = showRecent.classNames) === null || _showRecent_classNames2 === void 0 ? void 0 : _showRecent_classNames2.header : undefined),
|
|
382
|
+
item: cx('ais-AutocompleteRecentSearchesItem', (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? (_showRecent_classNames3 = showRecent.classNames) === null || _showRecent_classNames3 === void 0 ? void 0 : _showRecent_classNames3.item : undefined)
|
|
285
383
|
}
|
|
286
384
|
} : undefined;
|
|
287
385
|
var isSearchPage = useMemo(function() {
|
|
@@ -289,15 +387,11 @@ function EXPERIMENTAL_Autocomplete(_0) {
|
|
|
289
387
|
}, [
|
|
290
388
|
indexRenderState
|
|
291
389
|
]);
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
indexName: index.indexName
|
|
298
|
-
}, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
|
|
299
|
-
}), /*#__PURE__*/ React.createElement(InnerAutocomplete, _$4(_$1({}, props), {
|
|
300
|
-
aiMode: aiMode,
|
|
390
|
+
restProps.indices; restProps.feeds; var forwardedProps = _(restProps, [
|
|
391
|
+
"indices",
|
|
392
|
+
"feeds"
|
|
393
|
+
]);
|
|
394
|
+
var innerAutocomplete = /*#__PURE__*/ React.createElement(InnerAutocomplete, _$3(_$1({}, forwardedProps), {
|
|
301
395
|
indicesConfig: indicesConfig,
|
|
302
396
|
refineSearchBox: refine,
|
|
303
397
|
isSearchStalled: isSearchStalled,
|
|
@@ -305,12 +399,33 @@ function EXPERIMENTAL_Autocomplete(_0) {
|
|
|
305
399
|
isSearchPage: isSearchPage,
|
|
306
400
|
showRecent: showRecent,
|
|
307
401
|
recentSearchConfig: recentSearchConfig,
|
|
308
|
-
showQuerySuggestions:
|
|
402
|
+
showQuerySuggestions: normalizedShowQuerySuggestions,
|
|
309
403
|
detachedMediaQuery: detachedMediaQuery,
|
|
310
404
|
translations: translations,
|
|
311
|
-
showPromptSuggestions:
|
|
405
|
+
showPromptSuggestions: normalizedShowPromptSuggestions,
|
|
406
|
+
transformItems: effectiveTransformItems,
|
|
312
407
|
chatRenderState: indexRenderState.chat
|
|
313
|
-
}))
|
|
408
|
+
}));
|
|
409
|
+
if (isFeedsMode) {
|
|
410
|
+
return /*#__PURE__*/ React.createElement(Index, {
|
|
411
|
+
EXPERIMENTAL_isolated: true,
|
|
412
|
+
indexName: compositionID,
|
|
413
|
+
indexId: "ais-autocomplete-".concat(instanceKey)
|
|
414
|
+
}, /*#__PURE__*/ React.createElement(Configure, searchParameters), /*#__PURE__*/ React.createElement(Feeds, {
|
|
415
|
+
isolated: false,
|
|
416
|
+
renderFeed: function renderFeed() {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
}), innerAutocomplete);
|
|
420
|
+
}
|
|
421
|
+
return /*#__PURE__*/ React.createElement(Index, {
|
|
422
|
+
EXPERIMENTAL_isolated: true
|
|
423
|
+
}, /*#__PURE__*/ React.createElement(Configure, searchParameters), indicesConfig.map(function(index) {
|
|
424
|
+
return /*#__PURE__*/ React.createElement(Index, {
|
|
425
|
+
key: index.indexName,
|
|
426
|
+
indexName: index.indexName
|
|
427
|
+
}, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
|
|
428
|
+
}), innerAutocomplete);
|
|
314
429
|
}
|
|
315
430
|
function InnerAutocomplete(_0) {
|
|
316
431
|
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 = _(_0, [
|
|
@@ -363,11 +478,11 @@ function InnerAutocomplete(_0) {
|
|
|
363
478
|
});
|
|
364
479
|
}) : index.hits;
|
|
365
480
|
if (index.indexName !== promptSuggestionsIndexName) {
|
|
366
|
-
return _$
|
|
481
|
+
return _$3(_$1({}, index), {
|
|
367
482
|
hits: dedupedHits
|
|
368
483
|
});
|
|
369
484
|
}
|
|
370
|
-
return _$
|
|
485
|
+
return _$3(_$1({}, index), {
|
|
371
486
|
hits: getPromptSuggestionHits({
|
|
372
487
|
hits: dedupedHits,
|
|
373
488
|
limit: promptSuggestionsLimit
|
|
@@ -387,7 +502,7 @@ function InnerAutocomplete(_0) {
|
|
|
387
502
|
if (index.indexName !== promptSuggestionsIndexName) {
|
|
388
503
|
return index;
|
|
389
504
|
}
|
|
390
|
-
return _$
|
|
505
|
+
return _$3(_$1({}, index), {
|
|
391
506
|
hits: getPromptSuggestionHits({
|
|
392
507
|
hits: index.hits,
|
|
393
508
|
limit: promptSuggestionsLimit
|
|
@@ -438,7 +553,7 @@ function InnerAutocomplete(_0) {
|
|
|
438
553
|
return;
|
|
439
554
|
}
|
|
440
555
|
if (!isSearchPage && typeof getSearchPageURL !== 'undefined') {
|
|
441
|
-
window.location.href = getSearchPageURL(_$
|
|
556
|
+
window.location.href = getSearchPageURL(_$3(_$1({}, indexUiState), {
|
|
442
557
|
query: query
|
|
443
558
|
}));
|
|
444
559
|
return;
|
|
@@ -529,7 +644,7 @@ function InnerAutocomplete(_0) {
|
|
|
529
644
|
ItemComponent: currentIndexConfig.itemComponent,
|
|
530
645
|
NoResultsComponent: currentIndexConfig.noResultsComponent,
|
|
531
646
|
items: hits.map(function(item) {
|
|
532
|
-
return _$
|
|
647
|
+
return _$3(_$1({}, item), {
|
|
533
648
|
__indexName: indexId
|
|
534
649
|
});
|
|
535
650
|
}),
|
|
@@ -576,7 +691,7 @@ function InnerAutocomplete(_0) {
|
|
|
576
691
|
aiModeButtonDisabled: aiMode ? isChatBusy(chatRenderState) : undefined,
|
|
577
692
|
classNames: classNames
|
|
578
693
|
});
|
|
579
|
-
var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, _$
|
|
694
|
+
var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, _$3(_$1({}, getPanelProps()), {
|
|
580
695
|
classNames: {
|
|
581
696
|
root: classNames === null || classNames === void 0 ? void 0 : classNames.panel,
|
|
582
697
|
open: classNames === null || classNames === void 0 ? void 0 : classNames.panelOpen,
|
|
@@ -588,14 +703,14 @@ function InnerAutocomplete(_0) {
|
|
|
588
703
|
}) : Object.keys(elements).map(function(elementId) {
|
|
589
704
|
return elements[elementId];
|
|
590
705
|
}));
|
|
591
|
-
var detachedContainerClassNames = isModalDetached ? _$
|
|
706
|
+
var detachedContainerClassNames = isModalDetached ? _$3(_$1({}, classNames), {
|
|
592
707
|
detachedContainer: cx('ais-AutocompleteDetachedContainer--modal', classNames === null || classNames === void 0 ? void 0 : classNames.detachedContainer)
|
|
593
708
|
}) : classNames;
|
|
594
709
|
var _getRootProps = getRootProps(), rootRef = _getRootProps.ref, rootProps = _(_getRootProps, [
|
|
595
710
|
"ref"
|
|
596
711
|
]);
|
|
597
712
|
if (isDetached) {
|
|
598
|
-
return /*#__PURE__*/ React.createElement(Autocomplete, _$
|
|
713
|
+
return /*#__PURE__*/ React.createElement(Autocomplete, _$3(_$1({}, props, rootProps), {
|
|
599
714
|
rootRef: rootRef,
|
|
600
715
|
classNames: classNames
|
|
601
716
|
}), /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
|
|
@@ -621,7 +736,7 @@ function InnerAutocomplete(_0) {
|
|
|
621
736
|
}, searchBoxContent), panelContent)));
|
|
622
737
|
}
|
|
623
738
|
// Normal (non-detached) rendering
|
|
624
|
-
return /*#__PURE__*/ React.createElement(Autocomplete, _$
|
|
739
|
+
return /*#__PURE__*/ React.createElement(Autocomplete, _$3(_$1({}, props, rootProps), {
|
|
625
740
|
rootRef: rootRef,
|
|
626
741
|
classNames: classNames
|
|
627
742
|
}), searchBoxContent, panelContent);
|
package/dist/es/widgets/Chat.js
CHANGED
|
@@ -7,7 +7,7 @@ import { _ as _$1 } from '@swc/helpers/esm/_to_array.js';
|
|
|
7
7
|
import { createChatComponent } from 'instantsearch-ui-components';
|
|
8
8
|
import { SearchIndexToolType, RecommendToolType, DisplayResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
9
9
|
export { DisplayResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
10
|
-
import React, { createElement, Fragment, useState, useRef, useMemo, useImperativeHandle, useEffect } from 'react';
|
|
10
|
+
import React, { createElement, Fragment, memo, useState, useRef, useMemo, useImperativeHandle, useEffect } from 'react';
|
|
11
11
|
import { useInstantSearch, useChat } from 'react-instantsearch-core';
|
|
12
12
|
import { useStickToBottom } from '../lib/useStickToBottom.js';
|
|
13
13
|
import { createDisplayResultsTool } from './chat/tools/DisplayResultsTool.js';
|
|
@@ -15,7 +15,8 @@ import { createCarouselTool } from './chat/tools/SearchIndexTool.js';
|
|
|
15
15
|
|
|
16
16
|
var ChatUiComponent = createChatComponent({
|
|
17
17
|
createElement: createElement,
|
|
18
|
-
Fragment: Fragment
|
|
18
|
+
Fragment: Fragment,
|
|
19
|
+
memo: memo
|
|
19
20
|
});
|
|
20
21
|
function createDefaultTools(itemComponent, getSearchPageURL) {
|
|
21
22
|
var _obj;
|
|
@@ -103,6 +104,23 @@ function ChatInner(_0, _1) {
|
|
|
103
104
|
}, [
|
|
104
105
|
open
|
|
105
106
|
]);
|
|
107
|
+
// Keep the conversation pinned to the bottom while streaming. The stick-to-
|
|
108
|
+
// bottom ResizeObserver only reacts to content *height* changes, but tool
|
|
109
|
+
// results such as a horizontally-growing carousel stream in without changing
|
|
110
|
+
// height — so we also re-pin on every message/status update. Passing
|
|
111
|
+
// `preserveScrollPosition` reuses the existing "only if already at the
|
|
112
|
+
// bottom" gate, so this never fights a user who has scrolled up to read.
|
|
113
|
+
useEffect(function() {
|
|
114
|
+
if (status === 'streaming' || status === 'submitted') {
|
|
115
|
+
scrollToBottom({
|
|
116
|
+
preserveScrollPosition: true
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}, [
|
|
120
|
+
messages,
|
|
121
|
+
status,
|
|
122
|
+
scrollToBottom
|
|
123
|
+
]);
|
|
106
124
|
return /*#__PURE__*/ React.createElement(ChatUiComponent, {
|
|
107
125
|
title: title,
|
|
108
126
|
open: open,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createDisplayResultsToolComponent, createButtonComponent, ChevronLeftIcon, ChevronRightIcon } from 'instantsearch-ui-components';
|
|
2
|
-
import React, { createElement, Fragment } from 'react';
|
|
2
|
+
import React, { createElement, Fragment, useMemo } from 'react';
|
|
3
3
|
import { Carousel } from '../../../components/Carousel.js';
|
|
4
4
|
|
|
5
5
|
function createDisplayResultsTool(itemComponent) {
|
|
6
6
|
var DisplayResultsUIComponent = createDisplayResultsToolComponent({
|
|
7
7
|
createElement: createElement,
|
|
8
|
-
Fragment: Fragment
|
|
8
|
+
Fragment: Fragment,
|
|
9
|
+
useMemo: useMemo
|
|
9
10
|
});
|
|
10
11
|
var Button = createButtonComponent({
|
|
11
12
|
createElement: createElement
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ } from '@swc/helpers/esm/_object_spread.js';
|
|
2
|
-
import { createButtonComponent, ArrowRightIcon, ChevronLeftIcon, ChevronRightIcon } from 'instantsearch-ui-components';
|
|
2
|
+
import { createButtonComponent, getFacetFiltersFromToolInput, ArrowRightIcon, ChevronLeftIcon, ChevronRightIcon } from 'instantsearch-ui-components';
|
|
3
3
|
import { addAbsolutePosition, addQueryID } from 'instantsearch.js/es/lib/utils/index.js';
|
|
4
4
|
import React, { createElement } from 'react';
|
|
5
5
|
import { Carousel } from '../../../components/Carousel.js';
|
|
@@ -59,7 +59,7 @@ function createCarouselTool(showViewAll, itemComponent, getSearchPageURL) {
|
|
|
59
59
|
if (!input || !applyFilters) return;
|
|
60
60
|
var params = applyFilters({
|
|
61
61
|
query: input.query,
|
|
62
|
-
facetFilters: input
|
|
62
|
+
facetFilters: getFacetFiltersFromToolInput(input)
|
|
63
63
|
});
|
|
64
64
|
if (getSearchPageURL && new URL(getSearchPageURL(params)).pathname !== window.location.pathname) {
|
|
65
65
|
window.location.href = getSearchPageURL(params);
|