react-instantsearch 7.26.1 → 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.
- package/dist/cjs/components/AutocompleteSearch.js +18 -11
- package/dist/cjs/components/Carousel.js +24 -17
- package/dist/cjs/components/index.js +5 -5
- package/dist/cjs/index.js +8 -88
- package/dist/cjs/lib/useStickToBottom.js +17 -11
- package/dist/cjs/types/PartialKeys.js +3 -0
- package/dist/cjs/types/Translatable.js +3 -0
- package/dist/cjs/types/index.js +6 -0
- package/dist/cjs/ui/Breadcrumb.js +31 -24
- package/dist/cjs/ui/ClearRefinements.js +19 -12
- package/dist/cjs/ui/CurrentRefinements.js +32 -26
- package/dist/cjs/ui/HierarchicalMenu.js +35 -28
- package/dist/cjs/ui/Highlight.js +20 -13
- package/dist/cjs/ui/HitsPerPage.js +21 -14
- package/dist/cjs/ui/InfiniteHits.js +38 -31
- package/dist/cjs/ui/InternalHighlight.js +14 -8
- package/dist/cjs/ui/Menu.js +32 -25
- package/dist/cjs/ui/Pagination.js +39 -32
- package/dist/cjs/ui/PoweredBy.js +23 -16
- package/dist/cjs/ui/RangeInput.js +34 -27
- package/dist/cjs/ui/RefinementList.js +40 -33
- package/dist/cjs/ui/ReverseHighlight.js +20 -13
- package/dist/cjs/ui/SearchBox.js +43 -36
- package/dist/cjs/ui/ShowMoreButton.js +13 -6
- package/dist/cjs/ui/Snippet.js +20 -13
- package/dist/cjs/ui/SortBy.js +21 -14
- package/dist/cjs/ui/Stats.js +18 -11
- package/dist/cjs/ui/ToggleRefinement.js +23 -16
- package/dist/cjs/ui/lib/capitalize.js +9 -2
- package/dist/cjs/ui/lib/index.js +6 -7
- package/dist/cjs/ui/lib/isModifierClick.js +9 -2
- package/dist/cjs/widgets/Autocomplete.js +243 -119
- package/dist/cjs/widgets/Breadcrumb.js +17 -10
- package/dist/cjs/widgets/Chat.js +69 -47
- package/dist/cjs/widgets/ClearRefinements.js +17 -10
- package/dist/cjs/widgets/CurrentRefinements.js +17 -10
- package/dist/cjs/widgets/FilterSuggestions.js +20 -13
- package/dist/cjs/widgets/FrequentlyBoughtTogether.js +23 -16
- package/dist/cjs/widgets/HierarchicalMenu.js +18 -11
- package/dist/cjs/widgets/Highlight.js +19 -12
- package/dist/cjs/widgets/Hits.js +24 -17
- package/dist/cjs/widgets/HitsPerPage.js +17 -10
- package/dist/cjs/widgets/InfiniteHits.js +17 -10
- package/dist/cjs/widgets/LookingSimilar.js +23 -16
- package/dist/cjs/widgets/Menu.js +18 -11
- package/dist/cjs/widgets/Pagination.js +18 -11
- package/dist/cjs/widgets/PoweredBy.js +16 -9
- package/dist/cjs/widgets/RangeInput.js +17 -10
- package/dist/cjs/widgets/RefinementList.js +23 -16
- package/dist/cjs/widgets/RelatedProducts.js +23 -16
- package/dist/cjs/widgets/ReverseHighlight.js +19 -12
- package/dist/cjs/widgets/SearchBox.js +20 -13
- package/dist/cjs/widgets/Snippet.js +19 -12
- package/dist/cjs/widgets/SortBy.js +17 -10
- package/dist/cjs/widgets/Stats.js +17 -10
- package/dist/cjs/widgets/ToggleRefinement.js +17 -10
- package/dist/cjs/widgets/TrendingItems.js +23 -16
- package/dist/cjs/widgets/chat/tools/SearchIndexTool.js +32 -25
- package/dist/cjs/widgets/index.js +29 -76
- package/dist/cjs/widgets/index.umd.js +58 -59
- package/dist/es/widgets/Autocomplete.d.ts +8 -4
- package/dist/es/widgets/Autocomplete.js +146 -29
- package/dist/es/widgets/Chat.js +17 -4
- package/dist/umd/ReactInstantSearch.js +1190 -1003
- package/dist/umd/ReactInstantSearch.min.js +3 -3
- 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';
|
|
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';
|
|
8
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
|
|
@@ -183,9 +189,10 @@ function getMediaQueryList(mediaQuery) {
|
|
|
183
189
|
};
|
|
184
190
|
}
|
|
185
191
|
function EXPERIMENTAL_Autocomplete(_0) {
|
|
186
|
-
var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices,
|
|
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, [
|
|
187
193
|
"indices",
|
|
188
|
-
"
|
|
194
|
+
"showQuerySuggestions",
|
|
195
|
+
"showPromptSuggestions",
|
|
189
196
|
"showRecent",
|
|
190
197
|
"searchParameters",
|
|
191
198
|
"detachedMediaQuery",
|
|
@@ -203,12 +210,12 @@ function EXPERIMENTAL_Autocomplete(_0) {
|
|
|
203
210
|
hitsPerPage: 5
|
|
204
211
|
}, userSearchParameters);
|
|
205
212
|
var indicesConfig = _$2(indices);
|
|
206
|
-
if (
|
|
207
|
-
var
|
|
213
|
+
if (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName) {
|
|
214
|
+
var _showQuerySuggestions_classNames, _showQuerySuggestions_classNames1, _showQuerySuggestions_classNames2, _showQuerySuggestions_classNames3;
|
|
208
215
|
indicesConfig.unshift({
|
|
209
|
-
indexName:
|
|
210
|
-
headerComponent:
|
|
211
|
-
itemComponent:
|
|
216
|
+
indexName: showQuerySuggestions.indexName,
|
|
217
|
+
headerComponent: showQuerySuggestions.headerComponent,
|
|
218
|
+
itemComponent: showQuerySuggestions.itemComponent || function(param) {
|
|
212
219
|
var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
|
|
213
220
|
return /*#__PURE__*/ React.createElement(AutocompleteSuggestion, {
|
|
214
221
|
item: item,
|
|
@@ -219,15 +226,48 @@ function EXPERIMENTAL_Autocomplete(_0) {
|
|
|
219
226
|
}));
|
|
220
227
|
},
|
|
221
228
|
classNames: {
|
|
222
|
-
root: cx('ais-AutocompleteSuggestions',
|
|
223
|
-
list: cx('ais-AutocompleteSuggestionsList',
|
|
224
|
-
header: cx('ais-AutocompleteSuggestionsHeader',
|
|
225
|
-
item: cx('ais-AutocompleteSuggestionsItem',
|
|
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)
|
|
226
233
|
},
|
|
234
|
+
searchParameters: _$1({
|
|
235
|
+
hitsPerPage: 3
|
|
236
|
+
}, showQuerySuggestions.searchParameters),
|
|
227
237
|
getQuery: function getQuery(item) {
|
|
228
238
|
return item.query;
|
|
229
239
|
},
|
|
230
|
-
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
|
|
231
271
|
});
|
|
232
272
|
}
|
|
233
273
|
var recentSearchConfig = showRecent ? {
|
|
@@ -260,13 +300,15 @@ function EXPERIMENTAL_Autocomplete(_0) {
|
|
|
260
300
|
isSearchPage: isSearchPage,
|
|
261
301
|
showRecent: showRecent,
|
|
262
302
|
recentSearchConfig: recentSearchConfig,
|
|
263
|
-
|
|
303
|
+
showQuerySuggestions: showQuerySuggestions,
|
|
264
304
|
detachedMediaQuery: detachedMediaQuery,
|
|
265
|
-
translations: translations
|
|
305
|
+
translations: translations,
|
|
306
|
+
showPromptSuggestions: showPromptSuggestions,
|
|
307
|
+
chatRenderState: indexRenderState.chat
|
|
266
308
|
}))));
|
|
267
309
|
}
|
|
268
310
|
function InnerAutocomplete(_0) {
|
|
269
|
-
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,
|
|
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, [
|
|
270
312
|
"indicesConfig",
|
|
271
313
|
"refineSearchBox",
|
|
272
314
|
"isSearchStalled",
|
|
@@ -277,13 +319,17 @@ function InnerAutocomplete(_0) {
|
|
|
277
319
|
"panelComponent",
|
|
278
320
|
"showRecent",
|
|
279
321
|
"recentSearchConfig",
|
|
280
|
-
"
|
|
322
|
+
"showQuerySuggestions",
|
|
323
|
+
"showPromptSuggestions",
|
|
324
|
+
"chatRenderState",
|
|
281
325
|
"transformItems",
|
|
282
326
|
"placeholder",
|
|
283
327
|
"detachedMediaQuery",
|
|
284
328
|
"translations",
|
|
285
329
|
"classNames"
|
|
286
330
|
]);
|
|
331
|
+
var _ref;
|
|
332
|
+
var _showPromptSuggestions_searchParameters;
|
|
287
333
|
var _useAutocomplete = useAutocomplete({
|
|
288
334
|
transformItems: transformItems
|
|
289
335
|
}), indices = _useAutocomplete.indices, refineAutocomplete = _useAutocomplete.refine, currentRefinement = _useAutocomplete.currentRefinement;
|
|
@@ -294,10 +340,57 @@ function InnerAutocomplete(_0) {
|
|
|
294
340
|
query: currentRefinement,
|
|
295
341
|
indices: indices,
|
|
296
342
|
indicesConfig: indicesConfig,
|
|
297
|
-
suggestionsIndexName:
|
|
343
|
+
suggestionsIndexName: showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName
|
|
298
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);
|
|
299
392
|
var _usePropGetters = usePropGetters({
|
|
300
|
-
indices:
|
|
393
|
+
indices: indicesForPropGettersWithPromptSuggestions,
|
|
301
394
|
indicesConfig: indicesConfigForPropGetters,
|
|
302
395
|
onRefine: function onRefine(query) {
|
|
303
396
|
refineAutocomplete(query);
|
|
@@ -308,7 +401,19 @@ function InnerAutocomplete(_0) {
|
|
|
308
401
|
refineAutocomplete(query);
|
|
309
402
|
},
|
|
310
403
|
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function(param) {
|
|
311
|
-
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
|
+
}
|
|
312
417
|
if (url) {
|
|
313
418
|
window.location.href = url;
|
|
314
419
|
return;
|
|
@@ -381,14 +486,14 @@ function InnerAutocomplete(_0) {
|
|
|
381
486
|
key: "recentSearches"
|
|
382
487
|
});
|
|
383
488
|
}
|
|
384
|
-
|
|
489
|
+
indicesForPanel.forEach(function(param) {
|
|
385
490
|
var indexId = param.indexId, indexName = param.indexName, hits = param.hits;
|
|
386
|
-
var elementId = indexName
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
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
|
+
}
|
|
392
497
|
var currentIndexConfig = indicesConfig.find(function(config) {
|
|
393
498
|
return config.indexName === indexName;
|
|
394
499
|
});
|
|
@@ -401,7 +506,7 @@ function InnerAutocomplete(_0) {
|
|
|
401
506
|
HeaderComponent: currentIndexConfig.headerComponent,
|
|
402
507
|
// @ts-expect-error - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
403
508
|
ItemComponent: currentIndexConfig.itemComponent,
|
|
404
|
-
items:
|
|
509
|
+
items: hits.map(function(item) {
|
|
405
510
|
return _$4(_$1({}, item), {
|
|
406
511
|
__indexName: indexId
|
|
407
512
|
});
|
|
@@ -425,7 +530,7 @@ function InnerAutocomplete(_0) {
|
|
|
425
530
|
});
|
|
426
531
|
var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, getPanelProps(), PanelComponent ? /*#__PURE__*/ React.createElement(PanelComponent, {
|
|
427
532
|
elements: elements,
|
|
428
|
-
indices:
|
|
533
|
+
indices: indicesForPanel
|
|
429
534
|
}) : Object.keys(elements).map(function(elementId) {
|
|
430
535
|
return elements[elementId];
|
|
431
536
|
}));
|
|
@@ -482,5 +587,17 @@ function ConditionalReverseHighlight(param) {
|
|
|
482
587
|
hit: item
|
|
483
588
|
});
|
|
484
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
|
+
}
|
|
485
602
|
|
|
486
603
|
export { EXPERIMENTAL_Autocomplete };
|
package/dist/es/widgets/Chat.js
CHANGED
|
@@ -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
|
|
56
|
-
var promptRef =
|
|
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 =
|
|
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,
|