react-instantsearch 7.26.1 → 7.28.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 +262 -120
- 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 +13 -4
- package/dist/es/widgets/Autocomplete.js +167 -32
- package/dist/es/widgets/Chat.js +17 -4
- package/dist/umd/ReactInstantSearch.js +1222 -1012
- 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, autoFocus = _0.autoFocus, _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,18 @@ 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",
|
|
327
|
+
"autoFocus",
|
|
283
328
|
"detachedMediaQuery",
|
|
284
329
|
"translations",
|
|
285
330
|
"classNames"
|
|
286
331
|
]);
|
|
332
|
+
var _ref;
|
|
333
|
+
var _showPromptSuggestions_searchParameters;
|
|
287
334
|
var _useAutocomplete = useAutocomplete({
|
|
288
335
|
transformItems: transformItems
|
|
289
336
|
}), indices = _useAutocomplete.indices, refineAutocomplete = _useAutocomplete.refine, currentRefinement = _useAutocomplete.currentRefinement;
|
|
@@ -294,10 +341,66 @@ function InnerAutocomplete(_0) {
|
|
|
294
341
|
query: currentRefinement,
|
|
295
342
|
indices: indices,
|
|
296
343
|
indicesConfig: indicesConfig,
|
|
297
|
-
suggestionsIndexName:
|
|
344
|
+
suggestionsIndexName: showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName
|
|
298
345
|
}), storage = _useStorage.storage, storageHits = _useStorage.storageHits, indicesForPropGetters = _useStorage.indicesForPropGetters, indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters;
|
|
346
|
+
var promptSuggestionsIndexName = showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName;
|
|
347
|
+
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;
|
|
348
|
+
var indicesForPanel = useMemo(function() {
|
|
349
|
+
return indices.map(function(index) {
|
|
350
|
+
var dedupedHits = index.indexName === (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName) && showRecent ? index.hits.filter(function(suggestionHit) {
|
|
351
|
+
return !storageHits.find(function(storageHit) {
|
|
352
|
+
return storageHit.query === suggestionHit.query;
|
|
353
|
+
});
|
|
354
|
+
}) : index.hits;
|
|
355
|
+
if (index.indexName !== promptSuggestionsIndexName) {
|
|
356
|
+
return _$4(_$1({}, index), {
|
|
357
|
+
hits: dedupedHits
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
return _$4(_$1({}, index), {
|
|
361
|
+
hits: getPromptSuggestionHits({
|
|
362
|
+
hits: dedupedHits,
|
|
363
|
+
limit: promptSuggestionsLimit
|
|
364
|
+
})
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
}, [
|
|
368
|
+
indices,
|
|
369
|
+
promptSuggestionsIndexName,
|
|
370
|
+
promptSuggestionsLimit,
|
|
371
|
+
showRecent,
|
|
372
|
+
showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName,
|
|
373
|
+
storageHits
|
|
374
|
+
]);
|
|
375
|
+
var indicesForPropGettersWithPromptSuggestions = useMemo(function() {
|
|
376
|
+
return indicesForPropGetters.map(function(index) {
|
|
377
|
+
if (index.indexName !== promptSuggestionsIndexName) {
|
|
378
|
+
return index;
|
|
379
|
+
}
|
|
380
|
+
return _$4(_$1({}, index), {
|
|
381
|
+
hits: getPromptSuggestionHits({
|
|
382
|
+
hits: index.hits,
|
|
383
|
+
limit: promptSuggestionsLimit
|
|
384
|
+
})
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
}, [
|
|
388
|
+
indicesForPropGetters,
|
|
389
|
+
promptSuggestionsIndexName,
|
|
390
|
+
promptSuggestionsLimit
|
|
391
|
+
]);
|
|
392
|
+
useRef(false);
|
|
393
|
+
var allIndicesEmpty = indicesForPanel.every(function(param) {
|
|
394
|
+
var hits = param.hits;
|
|
395
|
+
return hits.length === 0;
|
|
396
|
+
});
|
|
397
|
+
var recentEmpty = !storageHits || storageHits.length === 0;
|
|
398
|
+
var hasNoResultsTemplate = indicesConfig.some(function(c) {
|
|
399
|
+
return c.noResultsComponent !== undefined;
|
|
400
|
+
});
|
|
401
|
+
var shouldHideEmptyPanel = allIndicesEmpty && recentEmpty && !hasNoResultsTemplate && !PanelComponent;
|
|
299
402
|
var _usePropGetters = usePropGetters({
|
|
300
|
-
indices:
|
|
403
|
+
indices: indicesForPropGettersWithPromptSuggestions,
|
|
301
404
|
indicesConfig: indicesConfigForPropGetters,
|
|
302
405
|
onRefine: function onRefine(query) {
|
|
303
406
|
refineAutocomplete(query);
|
|
@@ -308,7 +411,19 @@ function InnerAutocomplete(_0) {
|
|
|
308
411
|
refineAutocomplete(query);
|
|
309
412
|
},
|
|
310
413
|
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function(param) {
|
|
311
|
-
var query = param.query, setQuery = param.setQuery, url = param.url;
|
|
414
|
+
var item = param.item, query = param.query, setQuery = param.setQuery, url = param.url;
|
|
415
|
+
if (isPromptSuggestion(item)) {
|
|
416
|
+
var chatRenderStateWithFocus = chatRenderState;
|
|
417
|
+
if (chatRenderStateWithFocus) {
|
|
418
|
+
var _chatRenderStateWithFocus_setOpen, _chatRenderStateWithFocus_focusInput, _chatRenderStateWithFocus_sendMessage;
|
|
419
|
+
(_chatRenderStateWithFocus_setOpen = chatRenderStateWithFocus.setOpen) === null || _chatRenderStateWithFocus_setOpen === void 0 ? void 0 : _chatRenderStateWithFocus_setOpen.call(chatRenderStateWithFocus, true);
|
|
420
|
+
(_chatRenderStateWithFocus_focusInput = chatRenderStateWithFocus.focusInput) === null || _chatRenderStateWithFocus_focusInput === void 0 ? void 0 : _chatRenderStateWithFocus_focusInput.call(chatRenderStateWithFocus);
|
|
421
|
+
(_chatRenderStateWithFocus_sendMessage = chatRenderStateWithFocus.sendMessage) === null || _chatRenderStateWithFocus_sendMessage === void 0 ? void 0 : _chatRenderStateWithFocus_sendMessage.call(chatRenderStateWithFocus, {
|
|
422
|
+
text: item.prompt
|
|
423
|
+
});
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
312
427
|
if (url) {
|
|
313
428
|
window.location.href = url;
|
|
314
429
|
return;
|
|
@@ -328,7 +443,9 @@ function InnerAutocomplete(_0) {
|
|
|
328
443
|
}
|
|
329
444
|
},
|
|
330
445
|
placeholder: placeholder,
|
|
331
|
-
isDetached: isDetached
|
|
446
|
+
isDetached: isDetached,
|
|
447
|
+
shouldHidePanel: shouldHideEmptyPanel,
|
|
448
|
+
autoFocus: autoFocus
|
|
332
449
|
}), getInputProps = _usePropGetters.getInputProps, getItemProps = _usePropGetters.getItemProps, getPanelProps = _usePropGetters.getPanelProps, getRootProps = _usePropGetters.getRootProps, isOpen = _usePropGetters.isOpen, setIsOpen = _usePropGetters.setIsOpen, focusInput = _usePropGetters.focusInput;
|
|
333
450
|
// Open panel and focus input when modal opens
|
|
334
451
|
useEffect(function() {
|
|
@@ -381,14 +498,14 @@ function InnerAutocomplete(_0) {
|
|
|
381
498
|
key: "recentSearches"
|
|
382
499
|
});
|
|
383
500
|
}
|
|
384
|
-
|
|
501
|
+
indicesForPanel.forEach(function(param) {
|
|
385
502
|
var indexId = param.indexId, indexName = param.indexName, hits = param.hits;
|
|
386
|
-
var elementId = indexName
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
503
|
+
var elementId = indexName;
|
|
504
|
+
if (indexName === (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName)) {
|
|
505
|
+
elementId = 'suggestions';
|
|
506
|
+
} else if (indexName === (showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName)) {
|
|
507
|
+
elementId = 'promptSuggestions';
|
|
508
|
+
}
|
|
392
509
|
var currentIndexConfig = indicesConfig.find(function(config) {
|
|
393
510
|
return config.indexName === indexName;
|
|
394
511
|
});
|
|
@@ -401,7 +518,8 @@ function InnerAutocomplete(_0) {
|
|
|
401
518
|
HeaderComponent: currentIndexConfig.headerComponent,
|
|
402
519
|
// @ts-expect-error - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
403
520
|
ItemComponent: currentIndexConfig.itemComponent,
|
|
404
|
-
|
|
521
|
+
NoResultsComponent: currentIndexConfig.noResultsComponent,
|
|
522
|
+
items: hits.map(function(item) {
|
|
405
523
|
return _$4(_$1({}, item), {
|
|
406
524
|
__indexName: indexId
|
|
407
525
|
});
|
|
@@ -425,15 +543,19 @@ function InnerAutocomplete(_0) {
|
|
|
425
543
|
});
|
|
426
544
|
var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, getPanelProps(), PanelComponent ? /*#__PURE__*/ React.createElement(PanelComponent, {
|
|
427
545
|
elements: elements,
|
|
428
|
-
indices:
|
|
546
|
+
indices: indicesForPanel
|
|
429
547
|
}) : Object.keys(elements).map(function(elementId) {
|
|
430
548
|
return elements[elementId];
|
|
431
549
|
}));
|
|
432
550
|
var detachedContainerClassNames = isModalDetached ? _$4(_$1({}, classNames), {
|
|
433
551
|
detachedContainer: cx('ais-AutocompleteDetachedContainer--modal', classNames === null || classNames === void 0 ? void 0 : classNames.detachedContainer)
|
|
434
552
|
}) : classNames;
|
|
553
|
+
var _getRootProps = getRootProps(), rootRef = _getRootProps.ref, rootProps = _(_getRootProps, [
|
|
554
|
+
"ref"
|
|
555
|
+
]);
|
|
435
556
|
if (isDetached) {
|
|
436
|
-
return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$1({}, props,
|
|
557
|
+
return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$1({}, props, rootProps), {
|
|
558
|
+
rootRef: rootRef,
|
|
437
559
|
classNames: classNames
|
|
438
560
|
}), /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
|
|
439
561
|
query: currentRefinement || indexUiState.query || '',
|
|
@@ -466,7 +588,8 @@ function InnerAutocomplete(_0) {
|
|
|
466
588
|
}, searchBoxContent), panelContent)));
|
|
467
589
|
}
|
|
468
590
|
// Normal (non-detached) rendering
|
|
469
|
-
return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$1({}, props,
|
|
591
|
+
return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$1({}, props, rootProps), {
|
|
592
|
+
rootRef: rootRef,
|
|
470
593
|
classNames: classNames
|
|
471
594
|
}), searchBoxContent, panelContent);
|
|
472
595
|
}
|
|
@@ -482,5 +605,17 @@ function ConditionalReverseHighlight(param) {
|
|
|
482
605
|
hit: item
|
|
483
606
|
});
|
|
484
607
|
}
|
|
608
|
+
function ConditionalHighlight(param) {
|
|
609
|
+
var item = param.item, _param_attribute = param.attribute, attribute = _param_attribute === void 0 ? 'query' : _param_attribute;
|
|
610
|
+
var _item__highlightResult;
|
|
611
|
+
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
|
|
612
|
+
item._highlightResult[attribute].matchLevel === 'none') {
|
|
613
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, item[attribute]);
|
|
614
|
+
}
|
|
615
|
+
return /*#__PURE__*/ React.createElement(Highlight, {
|
|
616
|
+
attribute: attribute,
|
|
617
|
+
hit: item
|
|
618
|
+
});
|
|
619
|
+
}
|
|
485
620
|
|
|
486
621
|
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,
|